Beispiel #1
0
 public static function textToScript($option, $optionIndex, $text, $gameId, $dialogId, $rootCharacterId, $rootCharacterTitle, $rootCharacterMediaId, $parentScriptId, &$characters, $maps)
 {
     //testing scripts
     //$text = "<dialog banana=\"testing\" butNot=\"12\" America='555'><npc mediaId = \"59\">\nHere is the first thing I will say</npc><npc mediaId = \"60\">Second Thing!!!</npc></dialog>";
     //$text = "<d  but >dialog </dialog>"
     $newIds = new stdClass();
     $newIds->firstOptionId = 0;
     $newIds->firstScriptId = 0;
     $newIds->lastScriptId = $parentScriptId;
     $newIds->exitToType = 0;
     $newIds->exitToId = 0;
     //The case where no parsing is necessary
     if (!preg_match("@<\\s*dialog(ue)?\\s*(\\w*\\s*=\\s*[\"'][^\"']*[\"']\\s*)*>(.*?)<\\s*/\\s*dialog(ue)?\\s*>@is", $text, $matches)) {
         //phew. Nothing complicated.
         $tmpScriptId = migration_dbconnection::queryInsert("INSERT INTO dialog_scripts (game_id, dialog_id, dialog_character_id, text, created) VALUES ('{$gameId}','{$dialogId}','{$rootCharacterId}','" . addslashes($text) . "',CURRENT_TIMESTAMP)", "v2");
         if ($option) {
             $newIds->firstOptionId = migration_dbconnection::queryInsert("INSERT INTO dialog_options (game_id, dialog_id, parent_dialog_script_id, link_id, prompt, sort_index, created) VALUES ('{$gameId}','{$dialogId}','{$newIds->lastScriptId}','{$tmpScriptId}','" . addslashes($option) . "','{$optionIndex}',CURRENT_TIMESTAMP)", "v2");
         }
         $newIds->firstScriptId = $tmpScriptId;
         $newIds->lastScriptId = $tmpScriptId;
         return $newIds;
     }
     //if it gets here, we actually need to parse stuff..
     $dialogContents = $matches[3];
     //$dialogContents will be the string between the dialog tags; save this before parsing dialog attribs
     //parse dialog tag
     preg_match("@<\\s*([^\\s>]*)([^>]*)@is", $text, $matches);
     $attribs = $matches[2];
     //$attribs will be the string of attributes on tag (example: "mediaId='123' title='billy'")
     while (preg_match("@^\\s*([^\\s=]*)\\s*=\\s*[\"']([^\"']*)[\"']\\s*(.*)@is", $attribs, $matches)) {
         //In the example:  mediaId="123" name="billy"
         $attrib_name = $matches[1];
         //mediaId
         $attrib_value = $matches[2];
         //123
         $attribs = $matches[3];
         //name="billy"
         if (preg_match("@exitToTab@i", $attrib_name)) {
             $newIds->exitToType = "EXIT_TO_TAB";
         }
         $newIds->exitToId = $attrib_value;
         if (preg_match("@exitToScannerWithPrompt@i", $attrib_name)) {
             $newIds->exitToType = "EXIT_TO_TAB";
         }
         $newIds->exitToId = $attrib_value;
         if (preg_match("@exitToPlaque@i", $attrib_name)) {
             $newIds->exitToType = "EXIT_TO_PLAQUE";
         }
         $newIds->exitToId = $attrib_value;
         if (preg_match("@exitToWebPage@i", $attrib_name)) {
             $newIds->exitToType = "EXIT_TO_WEB_PAGE";
         }
         $newIds->exitToId = $attrib_value;
         if (preg_match("@exitToCharacter@i", $attrib_name)) {
             $newIds->exitToType = "EXIT_TO_DIALOG";
         }
         $newIds->exitToId = $attrib_value;
         if (preg_match("@exitToItem@i", $attrib_name)) {
             $newIds->exitToType = "EXIT_TO_ITEM";
         }
         $newIds->exitToId = $attrib_value;
     }
     //parse contents of dialog tag
     while (!preg_match("@^\\s*\$@s", $dialogContents)) {
         preg_match("@<\\s*([^\\s>]*)([^>]*)@is", $dialogContents, $matches);
         $tag = $matches[1];
         //$tag will be the tag type (example: "npc")
         $attribs = $matches[2];
         //$attribs will be the string of attributes on tag (example: "mediaId='123' title='billy'")
         preg_match("@<\\s*" . $tag . "[^>]*>(.*?)<\\s*\\/\\s*" . $tag . "\\s*>(.*)@is", $dialogContents, $matches);
         $tag_contents = $matches[1];
         //$tag_contents will be the string between npc tags (example: "Hi!")
         $dialogContents = $matches[2];
         //$dialog_contents will be the rest of the dialog contents that still need parsing
         $characterId = 0;
         if (preg_match("@npc@i", $tag)) {
             $characterId = $rootCharacterId;
             //assume clean npc tag, use default character
             $title = "";
             $mediaId = 0;
             while (preg_match("@^\\s*([^\\s=]*)\\s*=\\s*[\"']([^\"']*)[\"']\\s*(.*)@is", $attribs, $matches)) {
                 //In the example:  mediaId="123" name="billy"
                 $attrib_name = $matches[1];
                 //mediaId
                 $attrib_value = $matches[2];
                 //123
                 $attribs = $matches[3];
                 //name="billy"
                 if (preg_match("@title@i", $attrib_name)) {
                     $title = $attrib_value;
                 }
                 if (preg_match("@mediaId@i", $attrib_name)) {
                     $mediaId = $attrib_value;
                 }
                 //etc... (check for other attribs here)
             }
             if ($title != "" || $mediaId != 0) {
                 if ($title == "") {
                     $title = $rootCharacterTitle;
                 }
                 if ($mediaId == 0) {
                     $mediaId = $rootCharacterMediaId;
                 } else {
                     $mediaId = $maps->media[$mediaId];
                 }
                 $characterId = migration::characterIdForGameNameMedia($gameId, $title, $mediaId, $characters);
             }
         } else {
             if (preg_match("@pc@i", $tag)) {
                 $characterId = 0;
                 //assume clean pc tag, use player character.
                 $title = "";
                 $mediaId = 0;
                 while (preg_match("@^\\s*([^\\s=]*)\\s*=\\s*[\"']([^\"']*)[\"']\\s*(.*)@is", $attribs, $matches)) {
                     //In the example:  mediaId="123" name="billy"
                     $attrib_name = $matches[1];
                     //mediaId
                     $attrib_value = $matches[2];
                     //123
                     $attribs = $matches[3];
                     //name="billy"
                     if (preg_match("@title@i", $attrib_name)) {
                         $title = $attrib_value;
                     }
                     if (preg_match("@mediaId@i", $attrib_name)) {
                         $mediaId = $attrib_value;
                     }
                     //etc... (check for other attribs here)
                 }
                 if ($title != "" || $mediaId != 0) {
                     if ($title == "") {
                         $title = $rootCharacterTitle;
                     }
                     if ($mediaId == 0) {
                         $mediaId = $rootCharacterMediaId;
                     } else {
                         $mediaId = $maps->media[$mediaId];
                     }
                     $characterId = migration::characterIdForGameNameMedia($gameId, $title, $mediaId, $characters);
                 }
                 //handle non-npc tag attributes
             }
         }
         $tmpScriptId = migration_dbconnection::queryInsert("INSERT INTO dialog_scripts (game_id, dialog_id,  dialog_character_id, text, created) VALUES ('{$gameId}','{$dialogId}','{$characterId}','" . addslashes($tag_contents) . "',CURRENT_TIMESTAMP)", "v2");
         if ($option) {
             $newestOptionId = migration_dbconnection::queryInsert("INSERT INTO dialog_options (game_id, dialog_id, parent_dialog_script_id, link_id, prompt, sort_index, created) VALUES ('{$gameId}','{$dialogId}','{$newIds->lastScriptId}','{$tmpScriptId}','" . addslashes($option) . "','{$optionIndex}',CURRENT_TIMESTAMP)", "v2");
         }
         if (!$newIds->firstOptionId) {
             $newIds->firstOptionId = $newestOptionId;
         }
         if (!$newIds->firstScriptId) {
             $newIds->firstScriptId = $tmpScriptId;
         }
         $newIds->lastScriptId = $tmpScriptId;
         $option = "Continue";
         //set option for all but first script to 'continue'
         $optionIndex = 0;
         //set option index 0 for all but first script
     }
     return $newIds;
 }