-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_config.php
executable file
·68 lines (61 loc) · 1.34 KB
/
load_config.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
<?php
$config_defaults = Array(
"high-scores" => false,
"controller" => "none",
"game-mode" => "lives",
"pre-html" => "",
"centered" => false,
"show-webad" => false,
"show-instructions" => true,
"show-control-buttons" => true,
"debug" => false,
"sound" => false,
"sound-dir" => "sounds/default",
);
$game_config = Array();
function game_config($id) {
global $game_config;
global $config_defaults;
foreach($config_defaults as $i=>$j) {
if($id == $i) {
if(isset($game_config[$id])){
return $game_config[$id];
} else {
return $j;
}
}
}
return false;
}
function load_config($file){
global $game_config;
if(file_exists($file)){
foreach(json_decode(file_get_contents($file), true) as $i=>$j){
$game_config[$i] = $j;
}
}
}
function to_js($value){
if($value === true) {
return "true";
}
if($value === false) {
return "false";
}
return "\"".$value."\"";
}
function write_js_config(){
global $config_defaults;
echo("function game_config(id) {");
foreach($config_defaults as $i=>$j){
echo("
if(id==\"".$i."\"){
return ".to_js(game_config($i))."
}");
}
echo("
return false;
}
");
}
?>