/** * @param $key * @param $data */ function __construct($key, $data) { // Make sure scene data is defined like we need to $processor = new Processor(); $configuration = new SceneConfiguration(); $this->data = $processor->processConfiguration($configuration, $data); // Set initial values $this->key = $key; $this->title = $this->data['title']; $this->description = $this->data['description']; // Add objects to the scene $this->objects = new ArrayCollection(); foreach ($this->data['objects'] as $objectKey => $objectConfig) { // @TODO: This should have been normalized by the semantic configuration! $objectConfig['name'] = $objectKey; $object = ObjectFactory::create($objectConfig); $object->setScene($this); $this->objects->add($object); } // Set exits $this->exits = new ArrayCollection(); foreach ($this->data['exit'] as $dir => $scene) { $this->exits->set($dir, $scene); } }
/** * @param IO $io * @param Config $config * @param ArrayCollection $scenes */ function __construct(IO $io, Config $config, ArrayCollection $scenes) { $this->io = $io; $this->config = $config; $this->scenes = $scenes; $this->state = new State(); // Set initial values, like entry scene $this->state->setScene($this->getScene($this->config['entry_scene'])); // Create inventory with default objects as states in the config $this->state->setInventory(new Inventory()); foreach ($this->config['inventory'] as $objectConfig) { $object = ObjectFactory::create($objectConfig); $object->setScene(null); $this->state->getInventory()->add($object); } // Add some generic actions $this->actions = new ArrayCollection(); $this->actions->add(new Action\Help()); $this->actions->add(new Action\Inventory()); $this->actions->add(new Action\Look()); $this->actions->add(new Action\Go()); // Create a simple parser $this->parser = new Parser($this); }