Widget:FateConversion

From Granblue Fantasy Wiki
Jump to navigation Jump to search
Danchou name <input type="text" id="profile_name" value="" /> (Your name, e.g. Gran)
Scenario Type
     <input type="radio" id="fate" name="scenario_type" value="fate" checked>
     <label for="fate">Fate Episode</label>
<input type="radio" id="main_quest" name="scenario_type" value="main_quest"> <label for="main_quest">Main Quest</label>
Character ID <input type="text" id="char_id" value="" /> (Fate Characters ID, e.g. 3040054000)
Character Name <input type="text" id="char_name" value="" /> (Fate Character Name, e.g. Katalina)
Fate Type
     <select id="fate_type">
       <option value=""></option>
       <option value="intro">Intro</option>
       <option value="skill">Skill</option>
       <option value="lvlcap">Lvl Cap +1</option>
       <option value="maxlvl">5★ Max Lvl</option>
       <option value="cross">Cross-Fate</option>
       <option value="enc">Eternals Encounter Fate</option>
       <option value="rematch">Eternals Rematch Fate</option>
     </select>
Fate URI <input type="text" id="fate_uri" size="70" value="" /> (URI of the scene.)
Options <input type="checkbox" id="fate_array_next" value="1" checked /><label for="fate_array_next">Fix array next values</label>
Fate JSON <textarea id="fate_content" rows="10" cols="80"></textarea>
<input type="button" id="fate_convert" value="Convert fate" onclick="WidgetConvertFate();" />
Expected page name
Output <textarea id="fate_converted" rows="10" cols="80"></textarea>

<script type="application/javascript"> function WidgetConvertFate() {

 var profile_name = $('#profile_name').val().trim();
 if (!profile_name) {
   alert('Profile name required.\nIt is needed to replace your MCs name with a generic one.');
   return False;
 }
 var scenario_type = $('input[name="scenario_type"]:checked').val();
 var char_id = $('#char_id').val().trim();
 
 var is_prologue = false;
 var has_next_scene = false;
 
 // fates etc
 var re = /quest\/scenario_archive\/([0-9]+)\/[^?]+/g;
 var path = re.exec($('#fate_uri').val().trim());
 if (path) {
   // for fates we expect a character ID
   if (!char_id) {
     alert('Character ID required.\nFind it on the character page.\n\nShould look like:\n3030157000');
     return False;
   }
 }
 // event
 if (!path) {
   re = /quest\/scenario\/([A-Za-z0-9_]+)\/[^?]+/g;
   path = re.exec($('#fate_uri').val().trim());
 }
 // arcarum characters
 if (!path) {
   re = /arcarum\/summon_scenario\/([A-Za-z0-9_]+)[^?]+/g;
   path = re.exec($('#fate_uri').val().trim());
 } 
 // eternals transcendence
 if (!path) {
   re = /npc\/evolution\/scenario_by_transcendence\/([A-Za-z0-9_]+)[^?]+/g;
   path = re.exec($('#fate_uri').val().trim());
 }
 // main story prologue
 if (!path) {
   re = /quest\/scenario\/(scene_tutorial[0-9]+)/g;
   path = re.exec($('#fate_uri').val().trim());
   if (path) { is_prologue = true; }
 }
 if (!path) {
   alert('Fate URI required!\nShould look like:\n http://game.granbluefantasy.jp/quest/quest/scenario_archive/200801/scene_fate_chr080_ep1?_=1231231232131&t=1231231231233&uid=98765432\n http://game.granbluefantasy.jp/rest/arcarum/summon_scenario/scene_chr489_ep1_s10?_=1231231232131&t=1231231231233&uid=98765432\n http://game.granbluefantasy.jp/quest/scenario/scene_evt140430_cp1_q1_s10/null?_=1231231232131&t=1231231231233&uid=98765432\n https://game.granbluefantasy.jp/quest/scenario/scene_tutorial00?_=1672540771370&t=1672540789580&uid=11106267');
   return False;
 }
 console
 var scenario_id = path[1];
 path = path[0];
 
 var scenario_req = jQuery.parseJSON($('#fate_content').val().trim());
 var scenario = scenario_req.scene_list;
 
 var scenario_text = scenario[0].synopsis;
 var scenario_name = is_prologue ? 'Opening: Setting Off on an Adventure' : scenario[0].chapter_name; // prologue scenario scripts don't include this value so there's no way to automatically grab it, let's hope it never changes
 var scenario_wiki_basename = $('#char_name').val();
 scenario_text = scenario_text.split(profile_name).join('(Captain)');
 if ($('#fate_array_next').val() == '1') {
   for (let i = 0; i < scenario.length; i++) {
     let scene = scenario[i];
     if ((scene.next != ) && (scene.next != undefined)) {
       let next_scene = scenario[scene.next];
       if (next_scene != undefined)
         scenario[i].next = next_scene.id + ;
     }
     if ((scene.sel_next1 != ) && (scene.sel_next1 != undefined)) {
       let next_scene = scenario[scene.sel_next1];
       if (next_scene != undefined)
         scenario[i].sel_next1 = next_scene.id + ;
     }
     if ((scene.sel_next2 != ) && (scene.sel_next2 != undefined)) {
       let next_scene = scenario[scene.sel_next2];
       if (next_scene != undefined)
         scenario[i].sel_next2 = next_scene.id + ;
     }
     if ((scene.sel_next3 != ) && (scene.sel_next3 != undefined)) {
       let next_scene = scenario[scene.sel_next3];
       if (next_scene != undefined)
         scenario[i].sel_next3 = next_scene.id + ;
     }
     if ((scene.sel_next4 != ) && (scene.sel_next4 != undefined)) {
       let next_scene = scenario[scene.sel_next4];
       if (next_scene != undefined)
         scenario[i].sel_next4 = next_scene.id + ;
     }
     if ((scene.sel_next5 != ) && (scene.sel_next5 != undefined)) {
       let next_scene = scenario[scene.sel_next5];
       if (next_scene != undefined)
         scenario[i].sel_next5 = next_scene.id + ;
     }
   }
 } 
 
 var forcedKeys = ['id', 'scene_id', 'character1_name', 'character2_name', 'character3_name', 'step_flag']
 var output = '{{Scenario\n' +
              '|id=' + scenario_id + '\n' +
              '|path=' + path + '\n' +
              '|type=' + scenario_type + '\n' +
              '|category=' + $(fate_type).val() + '\n' +
              '|character_id=' + char_id + '\n' +
              '|name=' + scenario_name + '\n' +
              '|synopsis=' + scenario_text + '\n' +
              ;
 
 if(scenario_type === 'main_quest') {
   scenario_wiki_basename = 'Main Quest';
   var episode;
   var chapter;
   var chapter_name;
   var act;
   
   if (is_prologue) {
     // scenario_id will look like scene_tutorial0#, with the number going from 0-3
     chapter = 'op';
     chapter_name = scenario_name.split(/:(.*)/)[1].trim();
     episode = scenario_id.slice(-1) - -1;
     act = 1;
     scenario_name = scenario_name + ' - Episode ' + episode;
   }
   else {
     // chapter is the first number in the id (scene_cp#_q#_s#0), episode is the second, third is the scene (with a 0 after it)
     re = /scene_cp([0-9]+)_q([0-9]+)_s([0-9])0/g;
     episode = re.exec(scenario_id);
     chapter = Number(episode[1]);
     episode = episode[2];
     // act is a function of the chapter (1-63 = 1, 64-110 = 2, 111+ = 3, but this function needs to be updated when act 4 starts, and also the scenario template has an entry for act 3-1, but journal doesn't split it up that way
     if(chapter <= 63) { act = 1; }
     else if (chapter <= 110) { act = 2; }
     else { act = 3; }
     // chapter_name should be the scenario_name without the number: in front
     chapter_name = scenario_name.split(/:(.*)/)[1].trim();
     
     scenario_name = 'Chapter ' + scenario_name + ' - Episode ' + episode;
   }
   
   output += '|act=' + act + '\n' +
             '|chapter=' + chapter + '\n' +
             '|chapter_name=' + chapter_name + '\n' +
             '|episode=' + episode + '\n' +
             ;
 }
 for (var scenario_index in scenario) {
   var scene = scenario[scenario_index];
   output += '|{{ScenarioStep\n';
   for (var key in scene) {
     if (scene.hasOwnProperty(key)) 
       var value = scene[key];
       key = key.replace('charcter', 'character')
       //value = value.replace(profile_name, '(Captain)');
       value = value.split(profile_name).join('(Captain)');
       if ((value != ) || (forcedKeys.indexOf(key) > -1)) {
         output += '|' + key + '=' + value + '\n';
       }
       
       // Some fate episodes, such as Colossus and Summer Monika's intro fates, don't load the entire scene in a single response even though they show Scene: 1/1 at the top.
       // Check if this is the case (if the next_scene_file key has a value) and alert the user so they know to grab the rest
       if ((value != ) && (key === 'next_scene_file')) {
         has_next_scene = true;

}

   }
   output += '}}';
 }
 output += '}}';
 
 $('#fate_converted').val(output);  
 var wiki_path = scenario_wiki_basename + ' - ' + scenario_name
 $('#fate_url').html('<a href="https://gbf.wiki/Scenario:'+wiki_path+'">'+wiki_path+'</a>');
 if(has_next_scene) {
   alert('This scene may contain additional text that was not included in the initial JSON response. Jump to the final line in-game and click to progress in order to load the next script chunk.');
 }

} </script>