95 lines
2.0 KiB
PHP
95 lines
2.0 KiB
PHP
|
#!/usr/bin/php
|
||
|
<?php
|
||
|
|
||
|
//$files = array_merge(
|
||
|
// scandir('./src/r3', SCANDIR_SORT_DESCENDING),
|
||
|
// scandir('./test', SCANDIR_SORT_DESCENDING)
|
||
|
//);
|
||
|
|
||
|
$files = scandir('./src/r3', SCANDIR_SORT_DESCENDING);
|
||
|
|
||
|
$events = [];
|
||
|
|
||
|
foreach ($files as $file) {
|
||
|
|
||
|
$file = './src/r3/' . $file;
|
||
|
// echo $file . "\n";
|
||
|
// continue;
|
||
|
|
||
|
if (
|
||
|
preg_match('/\.js$/', $file) &&
|
||
|
!preg_match('/r3\-event/', $file)
|
||
|
) {
|
||
|
|
||
|
echo "processing file " . $file . "\n";
|
||
|
|
||
|
$fn = fopen($file, "r");
|
||
|
|
||
|
while (!feof($fn)) {
|
||
|
|
||
|
$line = fgets($fn);
|
||
|
|
||
|
|
||
|
if (
|
||
|
preg_match('/Event\./', $line) &&
|
||
|
!preg_match('/Emit|Subscribe|.call|GetEventName|Async|prototype/', $line)
|
||
|
) {
|
||
|
$matches = [];
|
||
|
preg_match_all('/(Event\..*?)(\s+|,|;|$|\))/', $line, $matches);
|
||
|
|
||
|
if ($matches[1] && $matches[1][0]) {
|
||
|
|
||
|
$event = $matches[1][0];
|
||
|
|
||
|
if (in_array($event, $events)) {
|
||
|
// Do nothing
|
||
|
} else {
|
||
|
array_push($events, $event);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
fclose($fn);
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
array_push($events, 'Event.START');
|
||
|
array_push($events, 'Event.PAUSE');
|
||
|
array_push($events, 'Event.RESTART');
|
||
|
|
||
|
sort($events);
|
||
|
|
||
|
$i = 1;
|
||
|
|
||
|
$eventList = '';
|
||
|
|
||
|
$eventFunction = "Event.GetEventName = function(eventId) {\n\n\tswitch(eventId) {\n";
|
||
|
|
||
|
foreach ($events as $event) {
|
||
|
$eventList .= $event . " = " . "0x" . dechex($i) . ";\n";
|
||
|
|
||
|
$eventFunction .= "\t\tcase 0x" . dechex($i). " : return '" . strtolower(str_replace('Event.', '', $event)) . "';\n";
|
||
|
|
||
|
$i++;
|
||
|
}
|
||
|
|
||
|
$eventList .= "Event.MAX_EVENTS = " . "0x" . dechex($i) . ";\n\n";
|
||
|
|
||
|
$eventFunction .= "\t\tdefault :\n\t\t\tthrow new Error('Event type not defined : ' + eventId);\n";
|
||
|
$eventFunction .= "\t}\n\n";
|
||
|
$eventFunction .= "};\n";
|
||
|
|
||
|
echo $eventList;
|
||
|
echo $eventFunction;
|
||
|
|
||
|
file_put_contents('./src/r3/events-generated', $eventList . $eventFunction);
|
||
|
|
||
|
?>
|