Skip to content

Commit

Permalink
Issue #27: Render bushes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sketchy502 committed Mar 4, 2018
1 parent 278ee69 commit c0c8ed7
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 86 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@ render_test.py
test

logs/
*.log*
*.log*

dev/

tests/reference_images
tests/reference_saves
49 changes: 31 additions & 18 deletions sdv/farmInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'Combat'
]


# Check adj. tiles for all tiles on map to determine orientation. Uses bit mask to select correct tile from spritesheet
def checkSurrounding(tiles):
floor_map = [[None for a in range(80)] for b in range(65)]
Expand Down Expand Up @@ -41,7 +42,8 @@ def checkSurrounding(tiles):
current_tile = None
try:
if floor_map[y + dy][x + dx] is not None:
if tile.name == 'Flooring' or (tile.name == 'Fence' and not tile.growth):
if tile.name == 'Flooring' or (
tile.name == 'Fence' and not tile.growth):
if floor_map[y + dy][x + dx].type == tile.type:
a += b
else:
Expand Down Expand Up @@ -71,11 +73,10 @@ def getFarmInfo(saveFile):

root = saveFile.getRoot()


# Farm Objects

s = []
farm_location = get_location(root,'Farm')
farm_location = get_location(root, 'Farm')
for item in farm_location.find('objects').iter("item"):
f = False
obj = item.find('value').find('Object')
Expand Down Expand Up @@ -129,7 +130,7 @@ def getFarmInfo(saveFile):
s = None
loc = None
f = False
name = item.find('value').find('TerrainFeature').get(ns+'type')
name = item.find('value').find('TerrainFeature').get(ns + 'type')
if name == 'Tree':
t = int(item.find('value').find('TerrainFeature').find('treeType').text)
s = int(item.find('value').find('TerrainFeature').find('growthStage').text)
Expand Down Expand Up @@ -164,11 +165,12 @@ def getFarmInfo(saveFile):
crop_dead = False
if crop.find('dead').text == 'true':
crop_dead = True
crops.append(sprite('HoeDirtCrop', crop_x, crop_y, 1, 1, crop_dead, crop_location, crop_phase, crop_flip, o))
crops.append(sprite('HoeDirtCrop', crop_x, crop_y, 1, 1, crop_dead, crop_location,
crop_phase, crop_flip, o))
if name == "FruitTree":
t = int(item.find('value').find('TerrainFeature').find('treeType').text)
s = int(item.find('value').find('TerrainFeature').find('growthStage').text)
if item.find('value').find('TerrainFeature').find('flipped').text == 'true': f= True
if item.find('value').find('TerrainFeature').find('flipped').text == 'true': f = True
if name == "Grass":
t = int(item.find('value').find('TerrainFeature').find('grassType').text)
s = int(item.find('value').find('TerrainFeature').find('numberOfWeeds').text)
Expand All @@ -192,11 +194,28 @@ def getFarmInfo(saveFile):
except:
pass

# Large Terrain Features

large_terrain_features = []
for ltf in farm_location.find('largeTerrainFeatures'):
name = ltf.get(ns + 'type')
flipped = ltf.find('flipped').text == 'true'
size = int(ltf.find('size').text)
x = int(ltf.find('tilePosition').find('X').text)
y = int(ltf.find('tilePosition').find('Y').text)
tile_sheet_offset = int(ltf.find('tileSheetOffset').text)

large_terrain_features.append(
sprite(name, x, y, 1, 1, tile_sheet_offset, None, size, flipped, None)
)

farm['largeTerrainFeatures'] = large_terrain_features

# Resource Clumps
s = []

for item in farm_location.find('resourceClumps').iter('ResourceClump'):
name = item.get(ns+'type')
name = item.get(ns + 'type')
if name is None:
name = 'ResourceClump'
t = int(item.find('parentSheetIndex').text)
Expand Down Expand Up @@ -230,7 +249,7 @@ def getFarmInfo(saveFile):

hasGreenhouse = False
try:
community_center = get_location(root,'CommunityCenter')
community_center = get_location(root, 'CommunityCenter')
cats = community_center.find('areasComplete').findall('boolean')
if cats[0].text == 'true':
hasGreenhouse = True
Expand Down Expand Up @@ -264,7 +283,7 @@ def colourBox(x, y, colour, pixels, scale=8):
for i in range(scale):
for j in range(scale):
try:
pixels[x*scale + i, y*scale + j] = colour
pixels[x * scale + i, y * scale + j] = colour
except IndexError:
pass
return pixels
Expand Down Expand Up @@ -337,21 +356,15 @@ def generateImage(data):
elif tile.type == 600:
for i in range(tile[3]):
for j in range(tile[3]):
colourBox(tile.x+i, tile.y + j, (75, 75, 75), pixels)
colourBox(tile.x + i, tile.y + j, (75, 75, 75), pixels)
return image


def regenerateFarmInfo(json_from_db):
sprite = namedtuple('Sprite', ['name', 'x', 'y', 'w', 'h', 'index', 'type', 'growth', 'flipped', 'orientation'])
sprite = namedtuple('Sprite', ['name', 'x', 'y', 'w', 'h', 'index', 'type', 'growth', 'flipped',
'orientation'])

for key in json_from_db['data'].keys():
for i, item in enumerate(json_from_db['data'][key]):
json_from_db['data'][key][i] = sprite(*item)
return json_from_db


def main():
generateImage(getFarmInfo('./saves/Crono_116230451')).save('farm.png')

if __name__ == '__main__':
main()
161 changes: 94 additions & 67 deletions sdv/imagegeneration/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,120 +17,147 @@ def open_nicely(filename):
im.load()
return im


def load_overlays(season, base):
overlays = dict()

for layer in overlay_layers:
overlays[layer] = list()
overlay_path = os.path.join(asset_dir, 'base', base, season, layer)
for i in range(65):
overlays[layer].append(open_nicely(os.path.join(overlay_path, '{}-{}.png'.format(layer, i))))
overlays[layer].append(
open_nicely(os.path.join(overlay_path, '{}-{}.png'.format(layer, i))))
return overlays


def loadFarmAssets(season='spring', base='Default'):
assets = {
'base' : {
'base': {
base: {season: Image.open(os.path.join(asset_dir, 'base', base, season, 'Back.png'))}
},
'overlays' : {
base : {season: load_overlays(season, base)}
'overlays': {
base: {season: load_overlays(season, base)}
},
'objects' : Image.open(os.path.join(asset_dir, 'farm', 'tileSheets', 'springobjects.png')),
'objects': Image.open(os.path.join(asset_dir, 'farm', 'tileSheets', 'springobjects.png')),
'craftables': Image.open(os.path.join(asset_dir, 'farm', 'tileSheets', 'Craftables.png')),
'flooring' : Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'flooring.png')),
'hoe dirt' : {
'flooring': Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'flooring.png')),
'hoe dirt': {
'normal': Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'hoeDirt.png')),
'winter': Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'hoeDirtsnow.png'))
'winter': Image.open(
os.path.join(asset_dir, 'farm', 'terrainFeatures', 'hoeDirtsnow.png'))
},
'crops' : Image.open(os.path.join(asset_dir, 'farm', 'tileSheets', 'crops.png')),
'fences' : {
'wood' : Image.open(os.path.join(asset_dir, 'farm', 'looseSprites', 'Fence1.png')),
'stone' : Image.open(os.path.join(asset_dir, 'farm', 'looseSprites', 'Fence2.png')),
'iron' : Image.open(os.path.join(asset_dir, 'farm', 'looseSprites', 'Fence3.png')),
'crops': Image.open(os.path.join(asset_dir, 'farm', 'tileSheets', 'crops.png')),
'fences': {
'wood': Image.open(os.path.join(asset_dir, 'farm', 'looseSprites', 'Fence1.png')),
'stone': Image.open(os.path.join(asset_dir, 'farm', 'looseSprites', 'Fence2.png')),
'iron': Image.open(os.path.join(asset_dir, 'farm', 'looseSprites', 'Fence3.png')),
'hardwood': Image.open(os.path.join(asset_dir, 'farm', 'looseSprites', 'Fence5.png'))
},
'trees' : {
'oak' : {
'spring': Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree1_spring.png')),
'summer': Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree1_summer.png')),
'fall' : Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree1_fall.png')),
'winter': Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree1_winter.png'))
'bushes': Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'bushes.png')),
'trees': {
'oak': {
'spring': Image.open(
os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree1_spring.png')),
'summer': Image.open(
os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree1_summer.png')),
'fall': Image.open(
os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree1_fall.png')),
'winter': Image.open(
os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree1_winter.png'))
},
'maple' : {
'spring': Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree2_spring.png')),
'summer': Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree2_summer.png')),
'fall' : Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree2_fall.png')),
'winter': Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree2_winter.png'))
'maple': {
'spring': Image.open(
os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree2_spring.png')),
'summer': Image.open(
os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree2_summer.png')),
'fall': Image.open(
os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree2_fall.png')),
'winter': Image.open(
os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree2_winter.png'))
},
'pine' : {
'spring': Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree3_spring.png')),
'summer': Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree3_spring.png')),
'fall' : Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree3_fall.png')),
'winter': Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree3_winter.png'))
'pine': {
'spring': Image.open(
os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree3_spring.png')),
'summer': Image.open(
os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree3_spring.png')),
'fall': Image.open(
os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree3_fall.png')),
'winter': Image.open(
os.path.join(asset_dir, 'farm', 'terrainFeatures', 'tree3_winter.png'))
},
'mushroom': Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'mushroom_tree.png')),
'fruit' : Image.open(os.path.join(asset_dir, 'farm', 'tileSheets', 'fruitTrees.png'))
'mushroom': Image.open(
os.path.join(asset_dir, 'farm', 'terrainFeatures', 'mushroom_tree.png')),
'fruit': Image.open(os.path.join(asset_dir, 'farm', 'tileSheets', 'fruitTrees.png'))
},
'grass' : Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'grass.png')),
'buildings' : {
'barn' : Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Barn.png')),
'big barn' : Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Big Barn.png')),
'deluxe barn' : Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Deluxe Barn.png')),
'coop' : Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Coop.png')),
'big coop' : Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Big Coop.png')),
'deluxe coop' : Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Deluxe Coop.png')),
'greenhouse' : Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'houses.png'))
'grass': Image.open(os.path.join(asset_dir, 'farm', 'terrainFeatures', 'grass.png')),
'buildings': {
'barn': Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Barn.png')),
'big barn': Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Big Barn.png')),
'deluxe barn': Image.open(
os.path.join(asset_dir, 'farm', 'buildings', 'Deluxe Barn.png')),
'coop': Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Coop.png')),
'big coop': Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Big Coop.png')),
'deluxe coop': Image.open(
os.path.join(asset_dir, 'farm', 'buildings', 'Deluxe Coop.png')),
'greenhouse': Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'houses.png'))
.crop((160, 0, 160 + 112, 144 * 3)),
'house' : Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'houses.png'))
'house': Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'houses.png'))
.crop((0, 0, 160, 144 * 3)),
'silo' : Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Silo.png')),
'slime hutch' : Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Slime Hutch.png')),
'stable' : Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Stable.png')),
'well' : Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Well.png')),
'earth obelisk': Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Earth Obelisk.png')),
'gold clock' : Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Gold Clock.png')),
'junimo hut' : {
'spring': Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Junimo Hut.png')).crop(
'silo': Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Silo.png')),
'slime hutch': Image.open(
os.path.join(asset_dir, 'farm', 'buildings', 'Slime Hutch.png')),
'stable': Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Stable.png')),
'well': Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Well.png')),
'earth obelisk': Image.open(
os.path.join(asset_dir, 'farm', 'buildings', 'Earth Obelisk.png')),
'gold clock': Image.open(
os.path.join(asset_dir, 'farm', 'buildings', 'Gold Clock.png')),
'junimo hut': {
'spring': Image.open(
os.path.join(asset_dir, 'farm', 'buildings', 'Junimo Hut.png')).crop(
(0, 0, 48, 64)),
'summer': Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Junimo Hut.png')).crop(
'summer': Image.open(
os.path.join(asset_dir, 'farm', 'buildings', 'Junimo Hut.png')).crop(
(48, 0, 48 * 2, 64)),
'fall' : Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Junimo Hut.png')).crop(
'fall': Image.open(
os.path.join(asset_dir, 'farm', 'buildings', 'Junimo Hut.png')).crop(
(48 * 2, 0, 48 * 3, 64)),
'winter': Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Junimo Hut.png')).crop(
'winter': Image.open(
os.path.join(asset_dir, 'farm', 'buildings', 'Junimo Hut.png')).crop(
(48 * 3, 0, 48 * 4, 64))
},
'mill' : Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Mill.png')),
'shed' : Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Shed.png')),
'water obelisk': Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Water Obelisk.png'))
'mill': Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Mill.png')),
'shed': Image.open(os.path.join(asset_dir, 'farm', 'buildings', 'Shed.png')),
'water obelisk': Image.open(
os.path.join(asset_dir, 'farm', 'buildings', 'Water Obelisk.png'))
},
'binLid' : Image.open(os.path.join(asset_dir, 'farm', 'looseSprites', 'binLid.png'))
'binLid': Image.open(os.path.join(asset_dir, 'farm', 'looseSprites', 'binLid.png'))
}
return assets


def loadAvatarAssets():
assets = {
'base' : {
'male' : Image.open(os.path.join(asset_dir, 'player', 'male', 'male_base.png')),
'base': {
'male': Image.open(os.path.join(asset_dir, 'player', 'male', 'male_base.png')),
'female': Image.open(os.path.join(asset_dir, 'player', 'female', 'female_base.png'))
},
'boots' : {
'male' : Image.open(os.path.join(asset_dir, 'player', 'male', 'male_boots.png')),
'boots': {
'male': Image.open(os.path.join(asset_dir, 'player', 'male', 'male_boots.png')),
'female': Image.open(os.path.join(asset_dir, 'player', 'female', 'female_boots.png'))
},
'legs' : {
'male' : Image.open(os.path.join(asset_dir, 'player', 'male', 'male_legs.png')),
'legs': {
'male': Image.open(os.path.join(asset_dir, 'player', 'male', 'male_legs.png')),
'female': Image.open(os.path.join(asset_dir, 'player', 'female', 'female_legs.png'))
},
'arms' : {
'male' : Image.open(os.path.join(asset_dir, 'player', 'male', 'male_arms.png')),
'arms': {
'male': Image.open(os.path.join(asset_dir, 'player', 'male', 'male_arms.png')),
'female': Image.open(os.path.join(asset_dir, 'player', 'female', 'female_arms.png'))
},
'hair' : Image.open(os.path.join(asset_dir, 'player', 'misc', 'hairstyles.png')),
'hair': Image.open(os.path.join(asset_dir, 'player', 'misc', 'hairstyles.png')),
'accessories': Image.open(os.path.join(asset_dir, 'player', 'misc', 'accessories.png')),
'shirts' : Image.open(os.path.join(asset_dir, 'player', 'misc', 'shirts.png')),
'shirts': Image.open(os.path.join(asset_dir, 'player', 'misc', 'shirts.png')),
'skin colors': Image.open(os.path.join(asset_dir, 'player', 'misc', 'skinColors.png'))
}

return assets
return assets
Loading

0 comments on commit c0c8ed7

Please sign in to comment.