本文整理汇总了Python中horizons.world.World.save_map方法的典型用法代码示例。如果您正苦于以下问题:Python World.save_map方法的具体用法?Python World.save_map怎么用?Python World.save_map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizons.world.World
的用法示例。
在下文中一共展示了World.save_map方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Session
# 需要导入模块: from horizons.world import World [as 别名]
# 或者: from horizons.world.World import save_map [as 别名]
#.........这里部分代码省略.........
self.speed_set(self.paused_ticks_per_second)
# check if resource icons should be displayed (possible changes in settings)
self.create_production_finished_icon_manager()
def speed_toggle_pause(self, suggestion=False):
if self.speed_is_paused():
self.speed_unpause(suggestion)
else:
self.speed_pause(suggestion)
def speed_is_paused(self):
return (self.timer.ticks_per_second == 0)
def is_game_loaded(self):
"""Checks if the current game is a new one, or a loaded one.
@return: True if game is loaded, else False
"""
return (self.savecounter > 0)
def remove_selected(self):
self.log.debug('Removing %s', self.selected_instances)
for instance in [inst for inst in self.selected_instances]:
if instance.is_building:
if instance.tearable and instance.owner is self.world.player:
self.log.debug('Attempting to remove building %s', inst)
Tear(instance).execute(self)
self.selected_instances.discard(instance)
else:
self.log.debug('Unable to remove building %s', inst)
elif instance.is_unit:
if instance.owner is self.world.player:
self.log.debug('Attempting to remove unit %s', inst)
RemoveUnit(instance).execute(self)
self.selected_instances.discard(instance)
else:
self.log.debug('Unable to remove unit %s', inst)
else:
self.log.error('Unable to remove unknown object %s', instance)
def save_map(self, prefix):
maps_folder = os.path.join(PATHS.USER_DIR, 'maps')
if not os.path.exists(maps_folder):
os.makedirs(maps_folder)
self.world.save_map(maps_folder, prefix)
def _do_save(self, savegame):
"""Actual save code.
@param savegame: absolute path"""
assert os.path.isabs(savegame)
self.log.debug("Session: Saving to %s", savegame)
try:
if os.path.exists(savegame):
os.unlink(savegame)
self.savecounter += 1
db = DbReader(savegame)
except IOError as e: # usually invalid filename
headline = _("Failed to create savegame file")
descr = _("There has been an error while creating your savegame file.")
advice = _("This usually means that the savegame name contains unsupported special characters.")
self.gui.show_error_popup(headline, descr, advice, unicode(e))
return self.save() # retry with new savegamename entered by the user
# this must not happen with quicksave/autosave
except OSError as e:
if e.errno == errno.EACCES:
self.gui.show_error_popup(_("Access is denied"),
_("The savegame file could be read-only or locked by another process."))
return self.save()
raise
try:
read_savegame_template(db)
db("BEGIN")
self.world.save(db)
#self.manager.save(db)
self.view.save(db)
self.ingame_gui.save(db)
self.scenario_eventhandler.save(db)
LastActivePlayerSettlementManager().save(db)
for instance in self.selected_instances:
db("INSERT INTO selected(`group`, id) VALUES(NULL, ?)", instance.worldid)
for group in xrange(len(self.selection_groups)):
for instance in self.selection_groups[group]:
db("INSERT INTO selected(`group`, id) VALUES(?, ?)", group, instance.worldid)
rng_state = json.dumps( self.random.getstate() )
SavegameManager.write_metadata(db, self.savecounter, rng_state)
# make sure everything gets written now
db("COMMIT")
db.close()
return True
except:
print "Save Exception"
traceback.print_exc()
db.close() # close db before delete
os.unlink(savegame) # remove invalid savegamefile
return False
示例2: Session
# 需要导入模块: from horizons.world import World [as 别名]
# 或者: from horizons.world.World import save_map [as 别名]
#.........这里部分代码省略.........
tps = self.timer.ticks_per_second
if tps == 0: # pause
text = u'0x'
up_icon.set_inactive()
down_icon.set_inactive()
else:
if tps != GAME_SPEED.TICKS_PER_SECOND:
text = unicode("%1gx" % (tps * 1.0/GAME_SPEED.TICKS_PER_SECOND))
#%1g: displays 0.5x, but 2x instead of 2.0x
index = GAME_SPEED.TICK_RATES.index(tps)
if index + 1 >= len(GAME_SPEED.TICK_RATES):
up_icon.set_inactive()
else:
up_icon.set_active()
if index > 0:
down_icon.set_active()
else:
down_icon.set_inactive()
self.ingame_gui.display_game_speed(text)
def speed_up(self):
if self.speed_is_paused():
AmbientSoundComponent.play_special('error')
return
if self.timer.ticks_per_second in GAME_SPEED.TICK_RATES:
i = GAME_SPEED.TICK_RATES.index(self.timer.ticks_per_second)
if i + 1 < len(GAME_SPEED.TICK_RATES):
self.speed_set(GAME_SPEED.TICK_RATES[i + 1])
else:
self.speed_set(GAME_SPEED.TICK_RATES[0])
def speed_down(self):
if self.speed_is_paused():
AmbientSoundComponent.play_special('error')
return
if self.timer.ticks_per_second in GAME_SPEED.TICK_RATES:
i = GAME_SPEED.TICK_RATES.index(self.timer.ticks_per_second)
if i > 0:
self.speed_set(GAME_SPEED.TICK_RATES[i - 1])
else:
self.speed_set(GAME_SPEED.TICK_RATES[0])
_pause_stack = 0 # this saves the level of pausing
# e.g. if two dialogs are displayed, that pause the game,
# unpause needs to be called twice to unpause the game. cf. #876
def speed_pause(self, suggestion=False):
self.log.debug("Session: Pausing")
self._pause_stack += 1
if not self.speed_is_paused():
self.paused_ticks_per_second = self.timer.ticks_per_second
self.speed_set(0, suggestion)
def speed_unpause(self, suggestion=False):
self.log.debug("Session: Unpausing")
if self.speed_is_paused():
self._pause_stack -= 1
if self._pause_stack == 0:
self.speed_set(self.paused_ticks_per_second)
def speed_toggle_pause(self, suggestion=False):
if self.speed_is_paused():
self.speed_unpause(suggestion)
else:
self.speed_pause(suggestion)
def speed_is_paused(self):
return (self.timer.ticks_per_second == 0)
def is_game_loaded(self):
"""Checks if the current game is a new one, or a loaded one.
@return: True if game is loaded, else False
"""
return (self.savecounter > 0)
def remove_selected(self):
self.log.debug('Removing %s', self.selected_instances)
for instance in [inst for inst in self.selected_instances]:
if instance.is_building:
if instance.tearable and instance.owner is self.world.player:
self.log.debug('Attempting to remove building %s', inst)
Tear(instance).execute(self)
self.selected_instances.discard(instance)
else:
self.log.debug('Unable to remove building %s', inst)
elif instance.is_unit:
if instance.owner is self.world.player:
self.log.debug('Attempting to remove unit %s', inst)
RemoveUnit(instance).execute(self)
self.selected_instances.discard(instance)
else:
self.log.debug('Unable to remove unit %s', inst)
else:
self.log.error('Unable to remove unknown object %s', instance)
def save_map(self, prefix):
maps_folder = os.path.join(PATHS.USER_DIR, 'maps')
if not os.path.exists(maps_folder):
os.makedirs(maps_folder)
self.world.save_map(maps_folder, prefix)