Skip to content

Commit

Permalink
Update save and load functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Shoes01 committed Apr 21, 2019
1 parent ef57040 commit a01ab70
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions _helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,23 @@ def load_game(world):
world._next_entity_id = data_file['next_entity_id']
world._components = data_file['components']
world._entities = data_file['entities']
world.messages = data_file['log']
world.state_stack = data_file['state']
world.ticker = data_file['ticker']
world.map = data_file['map']

def loot_algorithm(chance, monster, item, floor):
net_rarity = (1 + (monster)*5 - (item - 3)*5 + (floor)*5)
if chance > (100 - net_rarity):
return True
return False

def save_game(next_entity_id, components, entities):
def save_game(world):
with shelve.open('savegame', 'n') as data_file:
data_file['next_entity_id'] = next_entity_id
data_file['components'] = components
data_file['entities'] = entities
data_file['next_entity_id'] = world._next_entity_id
data_file['components'] = world._components
data_file['entities'] = world._entities
data_file['log'] = world.messages
data_file['state'] = world.state_stack
data_file['ticker'] = world.ticker
data_file['map'] = world.map
2 changes: 1 addition & 1 deletion processors/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def process(self):

if _save_game:
self.world.messages.append({'game_saved': True})
save_game(self.world._next_entity_id, self.world._components, self.world._entities)
save_game(self.world)

if _scroll:
self.world.messages_offset += _scroll
Expand Down

0 comments on commit a01ab70

Please sign in to comment.