forked from Aatu/FieryVoid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateStaticShipFile.php
69 lines (57 loc) · 1.84 KB
/
generateStaticShipFile.php
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
<?php
ob_start("ob_gzhandler");
include_once './source/public/global.php';
$ships = ShipLoader::getAllShips(null);
$data = [];
/* original - everything in one file
foreach ($ships as $faction) {
foreach ($faction as $ship) {
//print(gettype($ship));
if ($ship && $ship instanceof BaseShip) {
print("generating: ");
print($ship->faction);
print(" ");
print($ship->phpclass);
print("\n");
$data[$ship->faction][$ship->phpclass] = $ship;
}
}
}
file_put_contents('./source/public/static/ships.js', 'window.staticShips = ' . json_encode($data));
*/
// attempting to split into multiple smaller files (so intermediate caches don't notice)
foreach ($ships as $faction) {
foreach ($faction as $ship) {
//print(gettype($ship));
if ($ship && $ship instanceof BaseShip) {
print("generating: ");
print($ship->faction);
print(" ");
print($ship->phpclass);
print("\n");
$data[$ship->faction][$ship->phpclass] = $ship;
}
}
}
$fileBase = './source/public/static/ships';
$factionNo = 0;
foreach($data as $factionName=>$preparedFaction){
$factionNo++;
$fileName = $fileBase . $factionNo . '.js';
$varBase = "window.staticShips";
$varBase .= '["' . $factionName . '"]='; //like: window.staticShips["Abbai"]=
file_put_contents($fileName, $varBase . json_encode($preparedFaction) . ';');
}
//set up "file 0" with variable definition
$fileName = $fileBase . '0.js';
file_put_contents($fileName, 'window.staticShips = {};');
//add base file - with includes:
//<script src="static/ships.php"></script>
$fileName = $fileBase . '.php';
$includeText = '';
for ($i=0;$i<=$factionNo;$i++){
$includeText .= '<script src="static/ships' . $i . '.js"></script>';
}
file_put_contents($fileName, $includeText);
$includeText = '';
print("\n ships generated!\n\n");