setGameData(""); $this->setMessages(array()); $this->setTime(0); } else { global $kdb; $typeData = $kdb->getTypeData($rid, self::$table); $this->setGameData(unserialize($typeData['data'])); $this->setRoboLandscape(unserialize($typeData['landscape'])); $this->setRoboBatteries(unserialize($typeData['batteries'])); $this->setMessages(unserialize($typeData['messages'])); $this->setTime($typeData['time']); } } protected function setGameData($d) { $this->exerciseData = $d; } public function getGameData() { return $this->exerciseData; } function setRoboLandscape($d) { if (!$d) $d = $this->makeGameArrays(); $this->roboLandscape = $d; } public function getRoboLandscape() { return $this->roboLandscape; } function setRoboBatteries($d) { if (!$d) $d = $this->makeGameArrays(); $this->roboBatteries = $d; } public function getRoboBatteries() { return $this->roboBatteries; } function makeGameArrays() { $ga = array(); for ($x=0;$x<60;$x++) { $gaa = array(); for ($y=0;$y<8;$y++) { $gaa []= 0; } $ga []= $gaa; } return $ga; } protected function setMessages($d) { $this->messages = $d; } public function getMessages() { return $this->messages; } protected function setTime($d) { $this->time = $d; } public function getTime() { return $this->time; } public function getActor() { return $this->actor; } public function getShowGameTime() { return true; } public function makeResourceFromXML($xml) { parent::makeResourceFromXML($xml); if ($this->getResourceID()!="new"){ global $kdb; $res = $kdb->query("INSERT INTO psyhvel_battery (resourceID, data) values (".$this->getResourceID().", '".$xml['data']."')"); if ($res) { $_SESSION['krihvel_notice'] = "\"".gettext("Battery")."\" ".gettext("has been imported successfully!"); } else { $_SESSION['krihvel_notice'] = gettext("Upload failed! Zip file was corrupted!"); } } return array('rid' => $this->getResourceID(), 'mode' => 'view'); } public function makeXML() { $xml = 'getGameData().']]>\n'; return $xml; } /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ public function actionSave() { $mode = "view"; if ($this->getResourceID() == "new"){ $mode = "compile"; } $this->updateData($_POST); $this->save(); $_SESSION['krihvel_notice'] = gettext("Saved"); return array('rid' => $this->getResourceID(), 'mode' => $mode); } /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ public function actionCopy() { global $kdb; $this->updateData($_POST); $rid = $this->getResourceID(); parent::copy(); if ($this->getResourceID() != $rid){ $res = $kdb->query("INSERT INTO psyhvel_battery (resourceID, data) values (".$this->getResourceID().", '".$this->getGameData()."')"); if ($res) { $_SESSION['krihvel_notice'] = gettext("You have new copy of")." \"".gettext("Battery")."\""; } else { $_SESSION['krihvel_notice'] = gettext("Making copy failed"); } } return array('rid' => $this->getResourceID(), 'mode' => 'view'); } protected function save() { global $kdb; $rid = $this->getResourceID(); parent::save(); if ($rid == "new" || $this->getResourceID() != $rid){ $kdb->query("INSERT INTO psyhvel_battery (resourceID, data) values (".$this->getResourceID().", '".$this->getGameData()."')"); } } /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ public function actionCompile() { $data = $this->getGameData(); if ( isset($_POST['fruit']) && isset($_POST['position_x']) && isset($_POST['position_y']) ) { $data []= array($_POST['fruit'], $_POST['position_x'], $_POST['position_y']); $this->kdb->query("UPDATE psyhvel_battery SET data='".serialize($data)."' WHERE resourceID=".$this->getResourceID()); $_SESSION['krihvel_notice'] = gettext("Lisatud"); } else { $_SESSION['krihvel_notice'] = gettext("Probleem on!"); } return array('rid' => $this->getResourceID(), 'mode' => "compile"); } /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ public function saveCompiledGame() { $res = $this->kdb->query("UPDATE psyhvel_battery SET data='".serialize($this->getGameData())."', landscape='".serialize($this->getRoboLandscape())."', batteries='".serialize($this->getRoboBatteries())."' WHERE resourceID=".$this->getResourceID()); if ($res) { return gettext("Saved"); } return gettext("Problem"); } } ?>