253 lines
9.2 KiB
PHP
253 lines
9.2 KiB
PHP
<?php
|
|
error_reporting(E_ALL ^ E_WARNING);
|
|
ini_set("memory_limit", "1G");
|
|
require_once("functions.php");
|
|
|
|
$str = readstdin();
|
|
$goldlist = json_decode($str, true);
|
|
|
|
// $goldlist is the entire sheet in an assoc array now.
|
|
|
|
// this will go $url => array(maps)
|
|
$arr_camps = array();
|
|
// player array
|
|
$arr_players = array();
|
|
|
|
// STANDARD LIST //
|
|
$lim = count($goldlist[4]['table-row']) - 3; // -3 to account for "total" and two weird extra rows google docs puts in?
|
|
echo "standard list\n";
|
|
foreach ($goldlist[4]['table-row'] as $rowcount => &$rowval) {
|
|
// skip first 2 rows and last row
|
|
if ($rowcount < 2 || $rowcount >= $lim) {
|
|
continue;
|
|
}
|
|
// map and chal always exist at each row
|
|
$obj_map = new Map();
|
|
$obj_chal = new Challenge();
|
|
|
|
// if first cell is campaign (has link), handle creation of a campaign and shift if it spans only 1 column
|
|
// this will align all of the columns to the map name
|
|
$cell = &$rowval['table-cell'][0];
|
|
if (gettype($cell['p']) === 'array') {
|
|
$obj_camp = new Campaign();
|
|
$obj_camp->url = $cell['p']['a']['+@xlink:href'];
|
|
$obj_camp->name = preg_replace('/ \(by .+\)/i', '', $cell['p']['a']['+content']);
|
|
$arr_camps[] = $obj_camp;
|
|
if ($cell['+@table:number-columns-spanned'] !== "2") {
|
|
array_shift($rowval['table-cell']); // normalize position in array
|
|
$cell = &$rowval['table-cell'][0];
|
|
} else {
|
|
$obj_map->name = $obj_camp->name;
|
|
}
|
|
}
|
|
$obj_map->name = $obj_map->name ?? $cell['p']; // fallback for no link stuff
|
|
$obj_camp->maps[] = $obj_map;
|
|
|
|
$obj_camp->name = preg_replace('/ \[Full Clear\]$/i', '', $obj_camp->name);
|
|
if (preg_match('/ \[Full Clear\]$/i', $obj_map->name)) {
|
|
$obj_map->name = preg_replace('/ \[Full Clear\]$/i', '', $obj_map->name);
|
|
$obj_chal->requires_fc = true;
|
|
}
|
|
array_shift($rowval['table-cell']);
|
|
|
|
// handle the entry numbers which tell us crucial information
|
|
// if this if statement fires, then it has an fc, but we first need to check
|
|
if ($rowval['table-cell'][0]['+@table:number-columns-spanned'] !== "2") {
|
|
if (search_hard_list($goldlist, $obj_camp->url, $obj_map->name) === false) {
|
|
$obj_chal->has_fc = true;
|
|
}
|
|
array_shift($rowval['table-cell']);
|
|
}
|
|
array_shift($rowval['table-cell']);
|
|
|
|
// we can do this here because $obj_chal is an object so it gets passed by reference I'm so good
|
|
$obj_map->challenges[] = $obj_chal;
|
|
|
|
// now to iterate over submissions to the map
|
|
foreach ($rowval['table-cell'] as $colcount => &$cellval) {
|
|
if (gettype($cellval['p']) !== 'array') {
|
|
if (gettype($cellval['p']) === 'string')
|
|
echo "LINK MISSING: " . $obj_camp->name . " - " . $obj_map->name . " - " . $cellval['p'] . "\n";
|
|
continue;
|
|
}
|
|
$obj_sub = new Submission();
|
|
$obj_sub->proof_url = $cellval['p']['a']['+@xlink:href'];
|
|
$tmp_playername = trim($cellval['p']['a']['+content']);
|
|
if (preg_match('/ \[FC\]$/', $tmp_playername)) {
|
|
// handles separate chals on same row
|
|
if ($obj_chal->has_fc === false) {
|
|
continue;
|
|
}
|
|
$tmp_playername = preg_replace('/ \[FC\]$/', '', $tmp_playername);
|
|
$obj_sub->is_fc = true;
|
|
}
|
|
|
|
// check if annotation exists and add it if so
|
|
if (isset($cellval['annotation'])) {
|
|
$obj_sub->verifier_note = "";
|
|
if (isset($cellval['annotation']['p']['+content'])) {
|
|
$obj_sub->verifier_note = $cellval['annotation']['p']['+content'];
|
|
} else { // concat arrays
|
|
foreach ($cellval['annotation']['p'] as &$ann) {
|
|
$obj_sub->verifier_note = $obj_sub->verifier_note . " " . $ann['+content'];
|
|
}
|
|
}
|
|
$obj_sub->verifier_note = trim($obj_sub->verifier_note);
|
|
}
|
|
|
|
// check if player exists already and set id accordingly
|
|
// N.B.: player id is offset one from array keys
|
|
if (($tmp_playerid = array_search($tmp_playername, $arr_players, true)) === false) {
|
|
$arr_players[] = $tmp_playername;
|
|
$obj_sub->player_id = count($arr_players);
|
|
} else {
|
|
$obj_sub->player_id = $tmp_playerid + 1;
|
|
}
|
|
|
|
$obj_chal->submissions[] = $obj_sub;
|
|
}
|
|
}
|
|
|
|
// HARD LIST
|
|
// can literally copy the camp/map/submission stuff, but num parsing will need help
|
|
$lim = count($goldlist[3]['table-row']) - 3;
|
|
echo "hard list\n";
|
|
foreach ($goldlist[3]['table-row'] as $rowcount => &$rowval) {
|
|
// skip first 2 rows and last row
|
|
if ($rowcount < 2 || $rowcount >= $lim) {
|
|
continue;
|
|
}
|
|
$obj_map = new Map();
|
|
$obj_chal = new Challenge();
|
|
$obj_chal_fc = new Challenge(); // this wasn't needed before but is needed now
|
|
$fc_chal_flag = false; // flag for determining if map has a separate fc challenge
|
|
$obj_chal_fc->requires_fc = true;
|
|
|
|
// if first cell is campaign (has link), handle creation of a campaign and shift if it spans only 1 column
|
|
// this will align all of the columns to the map name
|
|
$cell = &$rowval['table-cell'][0];
|
|
if (gettype($cell['p']) === 'array') {
|
|
// if the campaign already exists in array (since this is hard list), use existing object
|
|
// else go through the normal campaign creation process
|
|
if (($camp_ref = &find_obj_camp($arr_camps, $cell['p']['a']['+@xlink:href'])) !== null) {
|
|
$obj_camp = $camp_ref;
|
|
} else {
|
|
$obj_camp = new Campaign();
|
|
$obj_camp->url = $cell['p']['a']['+@xlink:href'];
|
|
$obj_camp->name = preg_replace('/ \(by .+\)/i', '', $cell['p']['a']['+content']);
|
|
$arr_camps[] = $obj_camp;
|
|
}
|
|
// shift check
|
|
if ($cell['+@table:number-columns-spanned'] !== "2") {
|
|
array_shift($rowval['table-cell']);
|
|
$cell = &$rowval['table-cell'][0];
|
|
} else {
|
|
$obj_map->name = $obj_camp->name;
|
|
}
|
|
}
|
|
$obj_map->name = $obj_map->name ?? $cell['p']; // fallback for no link stuff
|
|
|
|
$obj_camp->name = preg_replace('/ \[Full Clear\]$/i', '', $obj_camp->name);
|
|
if (preg_match('/ \[Full Clear\]$/i', $cell['p']['a']['+content'] ?? $cell['p'])) {
|
|
$obj_map->name = preg_replace('/ \[Full Clear\]$/i', '', $obj_map->name);
|
|
$obj_chal->requires_fc = true;
|
|
}
|
|
array_shift($rowval['table-cell']);
|
|
|
|
// handle the entry numbers which tell us crucial information
|
|
// if this if statement fires, then it has an fc, but we first need to check
|
|
if ($rowval['table-cell'][0]['+@table:number-columns-spanned'] !== "2") {
|
|
// $rowcount + 1 since arrays start at 0 but sheets start at 1
|
|
if (($obj_chal_fc->diff_id = search_top_list($goldlist, "'Hard Golden List'", $rowcount + 1, true)) === -1) {
|
|
if ($rowval['table-cell'][1]['p'] !== "0") {
|
|
$obj_chal->has_fc = true;
|
|
}
|
|
} else {
|
|
// again passed identifier
|
|
$fc_chal_flag = true;
|
|
$obj_map->challenges[] = $obj_chal_fc;
|
|
}
|
|
array_shift($rowval['table-cell']);
|
|
}
|
|
$obj_chal->diff_id = search_top_list($goldlist, "'Hard Golden List'", $rowcount + 1, false);
|
|
array_shift($rowval['table-cell']);
|
|
|
|
// if map exists in camp already, set the obj_map to that so we can update it
|
|
// otherwise, create new map!
|
|
if (($ind = map_exists_in($obj_camp->maps, $obj_map->name)) !== -1) {
|
|
$obj_map = $obj_camp->maps[$ind];
|
|
} else {
|
|
$obj_camp->maps[] = $obj_map;
|
|
}
|
|
|
|
$obj_map->challenges[] = $obj_chal;
|
|
|
|
foreach ($rowval['table-cell'] as $colcount => &$cellval) {
|
|
if (gettype($cellval['p']) !== 'array') {
|
|
if (gettype($cellval['p']) === 'string')
|
|
echo "LINK MISSING: " . $obj_camp->name . " - " . $obj_map->name . " - " . $cellval['p'] . "\n";
|
|
continue;
|
|
}
|
|
$obj_sub = new Submission();
|
|
$obj_sub->proof_url = $cellval['p']['a']['+@xlink:href'];
|
|
$tmp_playername = trim($cellval['p']['a']['+content']);
|
|
if (preg_match('/ \[FC\]$/', $tmp_playername)) {
|
|
if ($fc_chal_flag === true) {
|
|
$obj_chal_fc->submissions[] = $obj_sub;
|
|
} else {
|
|
$obj_sub->is_fc = true;
|
|
$obj_chal->submissions[] = $obj_sub;
|
|
}
|
|
$tmp_playername = preg_replace('/ \[FC\]$/', '', $tmp_playername);
|
|
} else {
|
|
$obj_chal->submissions[] = $obj_sub;
|
|
}
|
|
|
|
// check if annotation exists and add it if so
|
|
if (isset($cellval['annotation'])) {
|
|
$obj_sub->verifier_note = "";
|
|
if (isset($cellval['annotation']['p']['+content'])) {
|
|
$obj_sub->verifier_note = $cellval['annotation']['p']['+content'];
|
|
} else { // concat arrays
|
|
foreach ($cellval['annotation']['p'] as &$ann) {
|
|
$obj_sub->verifier_note = $obj_sub->verifier_note . " " . $ann['+content'];
|
|
}
|
|
}
|
|
$obj_sub->verifier_note = trim($obj_sub->verifier_note);
|
|
}
|
|
|
|
// check if player exists already and set id accordingly
|
|
// N.B.: player id is offset one from array keys
|
|
if (($tmp_playerid = array_search($tmp_playername, $arr_players, true)) === false) {
|
|
$arr_players[] = $tmp_playername;
|
|
$obj_sub->player_id = count($arr_players);
|
|
} else {
|
|
$obj_sub->player_id = $tmp_playerid + 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
// STRAWBERRY JAM
|
|
echo "strawberry jam\n";
|
|
complete_collab_parsing($goldlist, $arr_camps, $arr_players, 6, 'Strawberry Jam Collab', 'https://gamebanana.com/mods/424541');
|
|
|
|
// SPRING COLLAB
|
|
echo "spring collab\n";
|
|
complete_collab_parsing($goldlist, $arr_camps, $arr_players, 7, 'Spring Collab 2020', 'https://gamebanana.com/mods/150813');
|
|
|
|
// SSC2023
|
|
echo "ssc2023\n";
|
|
complete_collab_parsing($goldlist, $arr_camps, $arr_players, 9, 'Secret Santa Collab 2023', 'https://gamebanana.com/mods/452173');
|
|
|
|
// D SIDES PACK
|
|
echo "dsides\n";
|
|
$dside_camp = &find_obj_camp($arr_camps, 'https://gamebanana.com/mods/150759');
|
|
complete_collab_parsing($goldlist, $arr_camps, $arr_players, 10, 'D-Sides', 'na', $dside_camp);
|
|
|
|
file_put_contents('generated_players.json',
|
|
json_encode($arr_players, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)
|
|
);
|
|
|
|
file_put_contents('generated_camps.json',
|
|
json_encode($arr_camps, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)
|
|
);
|