本文整理汇总了Python中horizons.scenario.ScenarioEventHandler.start方法的典型用法代码示例。如果您正苦于以下问题:Python ScenarioEventHandler.start方法的具体用法?Python ScenarioEventHandler.start怎么用?Python ScenarioEventHandler.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizons.scenario.ScenarioEventHandler
的用法示例。
在下文中一共展示了ScenarioEventHandler.start方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Session
# 需要导入模块: from horizons.scenario import ScenarioEventHandler [as 别名]
# 或者: from horizons.scenario.ScenarioEventHandler import start [as 别名]
class Session(LivingObject):
"""The Session class represents the game's main ingame view and controls cameras and map loading.
It is alive as long as a game is running.
Many objects require a reference to this, which makes it a pseudo-global, from which we would
like to move away in the long term. This is where we hope the components come into play, which
you will encounter later.
This is the most important class if you are going to hack on Unknown Horizons; it provides most of
the important ingame variables.
Here's a small list of commonly used attributes:
* world - horizons.world instance of the currently running horizons. Stores players and islands,
which store settlements, which store buildings, which have productions and collectors.
Therefore, world deserves its name -- it contains the whole game state.
* scheduler - horizons.scheduler instance. Used to execute timed events. Master of time in UH.
* manager - horizons.manager instance. Used to execute commands (used to apply user interactions).
There is a singleplayer and a multiplayer version. Our mp system works by the mp-manager not
executing the commands directly, but sending them to all players, where they will be executed
at the same tick.
* view - horizons.view instance. Used to control the ingame camera.
* ingame_gui - horizons.gui.ingame_gui instance. Used to control the ingame gui framework.
(This is different from gui, which is the main menu and general session-independent gui)
* selected_instances - Set that holds the currently selected instances (building, units).
TUTORIAL:
For further digging you should now be checking out the load() function.
"""
timer = livingProperty()
manager = livingProperty()
view = livingProperty()
ingame_gui = livingProperty()
scenario_eventhandler = livingProperty()
log = logging.getLogger('session')
def __init__(self, db, rng_seed=None, ingame_gui_class=IngameGui):
super(Session, self).__init__()
assert isinstance(db, horizons.util.uhdbaccessor.UhDbAccessor)
self.log.debug("Initing session")
self.db = db # main db for game data (game.sql)
# this saves how often the current game has been saved
self.savecounter = 0
self.is_alive = True
self._clear_caches()
#game
self.random = self.create_rng(rng_seed)
assert isinstance(self.random, Random)
self.timer = self.create_timer()
Scheduler.create_instance(self.timer)
self.manager = self.create_manager()
self.view = View()
Entities.load(self.db)
self.scenario_eventhandler = ScenarioEventHandler(self) # dummy handler with no events
#GUI
self._ingame_gui_class = ingame_gui_class
self.selected_instances = set()
# List of sets that holds the player assigned unit groups.
self.selection_groups = [set()] * 10
self._old_autosave_interval = None
def start(self):
"""Actually starts the game."""
self.timer.activate()
self.scenario_eventhandler.start()
self.reset_autosave()
SettingChanged.subscribe(self._on_setting_changed)
def reset_autosave(self):
"""(Re-)Set up autosave. Called if autosave interval has been changed."""
# get_uh_setting returns floats like 4.0 and 42.0 since slider stepping is 1.0.
interval = int(horizons.globals.fife.get_uh_setting("AutosaveInterval"))
if interval != self._old_autosave_interval:
self._old_autosave_interval = interval
ExtScheduler().rem_call(self, self.autosave)
if interval != 0: #autosave
self.log.debug("Initing autosave every %s minutes", interval)
ExtScheduler().add_new_object(self.autosave, self, interval * 60, -1)
def _on_setting_changed(self, message):
if message.setting_name == 'AutosaveInterval':
self.reset_autosave()
def create_manager(self):
"""Returns instance of command manager (currently MPManager or SPManager)"""
raise NotImplementedError
def create_rng(self, seed=None):
"""Returns a RNG (random number generator). Must support the python random.Random interface"""
raise NotImplementedError
def create_timer(self):
"""Returns a Timer instance."""
raise NotImplementedError
@classmethod
#.........这里部分代码省略.........