forked from SWU-Petranaki/SWUOnline
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzzCardCodeGenerator.php
More file actions
168 lines (142 loc) · 5.91 KB
/
zzCardCodeGenerator.php
File metadata and controls
168 lines (142 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
include './zzImageConverter.php';
include './Libraries/Trie.php';
$hasMoreData = true;
$page = 1;
$titleTrie = [];
$subtitleTrie = [];
$costTrie = [];
$hpTrie = [];
$powerTrie = [];
$aspectsTrie = [];
$traitsTrie = [];
$arenasTrie = [];
$uuidLookupTrie = [];
$typeTrie = [];
$type2Trie = [];
$uniqueTrie = [];
$hasPlayTrie = [];
$setTrie = [];
while ($hasMoreData)
{
$jsonUrl = "https://admin.starwarsunlimited.com/api/cards?pagination[page]=" . $page;
$curl = curl_init();
$headers = array(
"Content-Type: application/json",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_URL, $jsonUrl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$cardData = curl_exec($curl);
curl_close($curl);
$response = json_decode($cardData);
$meta = $response->meta;
for ($i = 0; $i < count($response->data); ++$i)
{
$card = $response->data[$i];
$card = $card->attributes;
if($card->variantOf->data != null) continue;
$cardNumber = $card->cardNumber;
if($cardNumber < 10) $cardNumber = "00" . $cardNumber;
else if($cardNumber < 100) $cardNumber = "0" . $cardNumber;
$set = $card->expansion->data->attributes->code;
$cardID= $set . "_" . $cardNumber;
//$cardID = "SOR_" . $cardNumber;
AddToTries($cardID, $card->cardUid);
$definedType = $card->type->data->attributes->name;
$imageUrl = $card->artFront->data->attributes->formats->card->url;
//$imageUrl = "https://swudb.com/cards/" . $set . "/" . $cardNumber . ".png";
CheckImage($card->cardUid, $imageUrl, $definedType, set:$set);
if($card->artBack->data != null) {
$type2 = $card->type2->data == null ? "" : $card->type2->data->attributes->name;
if($type2 == "Leader Unit") $definedType = "Unit";
$imageUrl = $card->artBack->data->attributes->formats->card->url;
$arr = explode("_", $imageUrl);
$arr = explode(".", $arr[count($arr)-1]);
$uuid = $arr[0];
CheckImage($uuid, $imageUrl, $definedType, isBack:true, set:$set);
AddToTries($cardID, $uuid);
}
}
echo("Page: " . $meta->pagination->page . "/" . $meta->pagination->pageCount . "<BR>");
++$page;
$hasMoreData = $page <= $meta->pagination->pageCount;
}
/*
subtypes - array
*/
if (!is_dir("./GeneratedCode")) mkdir("./GeneratedCode", 777, true);
$generateFilename = "./GeneratedCode/GeneratedCardDictionaries.php";
$handler = fopen($generateFilename, "w");
fwrite($handler, "<?php\r\n");
GenerateFunction($titleTrie, $handler, "CardTitle", true, "");
GenerateFunction($subtitleTrie, $handler, "CardSubtitle", true, "");
GenerateFunction($costTrie, $handler, "CardCost", false, -1);
GenerateFunction($hpTrie, $handler, "CardHPDictionary", false, -1);
GenerateFunction($powerTrie, $handler, "CardPower", false, -1);
GenerateFunction($aspectsTrie, $handler, "CardAspects", true, "");
GenerateFunction($traitsTrie, $handler, "CardTraits", true, "");
GenerateFunction($arenasTrie, $handler, "CardArenas", true, "");
GenerateFunction($typeTrie, $handler, "DefinedCardType", true, "");
GenerateFunction($type2Trie, $handler, "DefinedCardType2", true, "");
GenerateFunction($uniqueTrie, $handler, "CardIsUnique", false, 0);
GenerateFunction($hasPlayTrie, $handler, "HasWhenPlayed", false, "false", 1);
GenerateFunction($setTrie, $handler, "CardSet", true, "");
GenerateFunction($uuidLookupTrie, $handler, "UUIDLookup", true, "");
fwrite($handler, "?>");
fclose($handler);
function GenerateFunction($cardArray, $handler, $functionName, $isString, $defaultValue, $dataType = 0)
{
fwrite($handler, "function " . $functionName . "(\$cardID) {\r\n");
TraverseTrie($cardArray, "", $handler, $isString, $defaultValue, $dataType);
fwrite($handler, "}\r\n\r\n");
}
function AddToTries($cardID, $uuid)
{
global $uuidLookupTrie, $titleTrie, $subtitleTrie, $costTrie, $hpTrie, $powerTrie, $typeTrie, $type2Trie, $uniqueTrie, $card;
global $aspectsTrie, $traitsTrie, $arenasTrie, $hasPlayTrie, $setTrie;
if($uuid != "8752877738" && $uuid != "2007868442") {
AddToTrie($uuidLookupTrie, $cardID, 0, $uuid);
}
AddToTrie($titleTrie, $uuid, 0, str_replace('"', "'", $card->title));
AddToTrie($subtitleTrie, $uuid, 0, str_replace('"', "'", $card->subtitle));
AddToTrie($costTrie, $uuid, 0, $card->cost);
AddToTrie($hpTrie, $uuid, 0, $card->hp);
AddToTrie($powerTrie, $uuid, 0, $card->power);
AddToTrie($typeTrie, $uuid, 0, $card->type->data->attributes->name);
AddToTrie($setTrie, $uuid, 0, $card->expansion->data->attributes->code);
if($card->type2->data != null) {
$type2 = $card->type2->data->attributes->name;
if($type2 == "Leader Unit") $type2 = "Unit";
AddToTrie($type2Trie, $uuid, 0, $type2);
}
AddToTrie($uniqueTrie, $uuid, 0, $card->unique == "true" ? 1 : 0);
if(str_contains($card->text, "When Played") || str_contains($card->text, "When played")) AddToTrie($hasPlayTrie, $uuid, 0, true);
$aspects = "";
for($j = 0; $j < count($card->aspects->data); ++$j)
{
if($aspects != "") $aspects .= ",";
$aspects .= $card->aspects->data[$j]->attributes->name;
}
for($j = 0; $j < count($card->aspectDuplicates->data); ++$j)
{
if($aspects != "") $aspects .= ",";
$aspects .= $card->aspectDuplicates->data[$j]->attributes->name;
}
AddToTrie($aspectsTrie, $uuid, 0, $aspects);
$traits = "";
for($j = 0; $j < count($card->traits->data); ++$j)
{
if($traits != "") $traits .= ",";
$traits .= $card->traits->data[$j]->attributes->name;
}
AddToTrie($traitsTrie, $uuid, 0, $traits);
$arenas = "";
for($j = 0; $j < count($card->arenas->data); ++$j)
{
if($arenas != "") $arenas .= ",";
$arenas .= $card->arenas->data[$j]->attributes->name;
}
AddToTrie($arenasTrie, $uuid, 0, $arenas);
}
?>