/** * konvertiert Code in ein LayerObjekt * @param $codeLine string * @return string */ function compileLine($codeLine) { $layerObject = false; // feststellen, ob Zeile ein Tag enthält // '<', '>' und sonstige Zeichen ausserhalb des Tags entfernen $lineRegex = '@.*<([a-z]+) .*>.*@i'; if (preg_match($lineRegex, $codeLine, $lineMatch)) { $tagName = $lineMatch[1]; $attributes = $this->readAttributesFromLine($codeLine); // Attribute überprüfen if ($this->hasAllAttributes(array_keys($attributes), $tagName)) { switch ($tagName) { case 'pfeil': $graphic = GAME_GRAPHICS_ABSOLUTE_PATH . 'pfeil_' . $attributes['richtung'] . '.png'; if (file_exists($graphic)) { $dimensions = getimagesize($graphic); $layerObject = new World_Map_LayerObject('pfeil_' . $attributes['richtung'], $attributes['left'], $attributes['top'], $dimensions[0], $dimensions[1], $attributes['hover'], buildSiteUrl('map', 'changemap', 'map=' . World_Map::getIdFromName($attributes['to']))); $this->drawOnImage($graphic, $attributes['left'], $attributes['top']); } break; case 'olink': $layerObject = new World_Map_LayerObject('olink', $attributes['left'], $attributes['top'], $attributes['width'], $attributes['height'], $attributes['hover'], buildSiteUrl('map', 'changemap', 'map=' . World_Map::getIdFromName($attributes['to']))); break; case 'umove': // $layerObject = new World_Map_LayerObject('umove', $attributes['left'], $attributes['top'], $attributes['width'], $attributes['height'], $attributes['hover'], '?site=attack&id=' . urlencode($attributes['move'])); // break; // $layerObject = new World_Map_LayerObject('umove', $attributes['left'], $attributes['top'], $attributes['width'], $attributes['height'], $attributes['hover'], '?site=attack&id=' . urlencode($attributes['move'])); // break; case 'hover': $layerObject = new World_Map_LayerObject('hover', $attributes['left'], $attributes['top'], $attributes['width'], $attributes['height'], $attributes['hover']); break; case 'plink': $layerObject = new World_Map_LayerObject('plink', $attributes['left'], $attributes['top'], $attributes['width'], $attributes['height'], '...', buildSiteUrl('fight', '', 'field=' . $attributes['field'])); break; case 'plinka': $layerObject = new World_Map_LayerObject('plinka', $attributes['left'], $attributes['top'], $attributes['width'], $attributes['height'], '...', buildSiteUrl('fight', '', 'field=' . $attributes['field'])); break; case 'pokebox': $layerObject = new World_Map_LayerObject('pokebox', $attributes['left'], $attributes['top'], $attributes['width'], $attributes['height'], $attributes['hover'], buildSiteUrl('storagePc')); break; case 'heal': $layerObject = new World_Map_LayerObject('heal', $attributes['left'], $attributes['top'], $attributes['width'], $attributes['height'], $attributes['hover'], buildSiteUrl('map', 'heal')); break; case 'shop': $layerObject = new World_Map_LayerObject('shop', $attributes['left'], $attributes['top'], $attributes['width'], $attributes['height'], $attributes['hover'], buildSiteUrl('shop', '', 'id=' . $attributes['shopid'])); break; case 'pokeshop': $layerObject = new World_Map_LayerObject('pokeshop', $attributes['left'], $attributes['top'], $attributes['width'], $attributes['height'], $attributes['hover'], buildSiteUrl('pokeshop', '', 'id=' . $attributes['shopid'])); break; case 'tkampf': $layerObject = new World_Map_LayerObject('tkampf', $attributes['left'], $attributes['top'], $attributes['width'], $attributes['height'], $attributes['hover'], buildSiteUrl('trainerFight')); break; case 'tausch': $layerObject = new World_Map_LayerObject('trade', $attributes['left'], $attributes['top'], $attributes['width'], $attributes['height'], $attributes['hover'], buildSiteUrl('trade')); break; case 'giveitem': $layerObject = new World_Map_LayerObject('giveitem', $attributes['left'], $attributes['top'], $attributes['width'], $attributes['height'], $attributes['hover'], buildSiteUrl('map', 'giveItem', 'id=' . $attributes['itemid']), $attributes['itemdid']); break; case 'img': $graphic = GAME_GRAPHICS_ABSOLUTE_PATH . $attributes['src']; if (file_exists($attributes['src'])) { $dimensions = getimagesize($attributes['src']); $layerObject = new World_Map_LayerObject('img', $attributes['left'], $attributes['top'], $dimensions[0], $dimensions[1], $attributes['hover']); $this->drawOnImage($attributes['src'], $attributes['left'], $attributes['top']); } break; case 'npc': $layerObject = new World_Map_LayerObject('npc', $attributes['left'], $attributes['top'], $attributes['width'], $attributes['height'], $attributes['hover'], buildSiteUrl('npc', 'id=' . $attributes['id'])); break; default: $layerObject = false; } if ($layerObject !== false) { // optionale Attribute verarbeiten $optionalAttributes = $this->_tags[$tagName]->getOptionalAttributes(); foreach ($optionalAttributes as $optAttr) { if (isset($attributes[$optAttr])) { $attributeValue = $attributes[$optAttr]; switch ($optAttr) { case 'condition_attack': $layerObject->addCondition('attack', $attributeValue); break; case 'condition_item': $layerObject->addCondition('item', $attributeValue); break; } } } } } } return $layerObject; }