sort of 'saving' + restore fails

master
Theunis J. Botha 2021-06-19 16:41:42 +02:00
parent c4707a9f0d
commit 09b5000aca
8 changed files with 404 additions and 196 deletions

31
.r3_history Normal file
View File

@ -0,0 +1,31 @@
r3 create VectorApplierAgain extends Event
r3 create AnotherClass extends R3Object
r3 create OneMore extends R3Object
r3 create AgainMore extends R3Object
r3 create AgainMoreAgain extends R3Object
r3 update-templates
r3 update-templates
r3 create AnotherClass extends R3Object
r3 create VectorApplierAgain extends Event
r3 update-templates
r3 update-templates
r3 update-options
r3 create AnotherClass extends R3Object
r3 create AnotherClass extends R3Object
r3 create VectorApplierAgain extends Event
r3 create VectorApplierAgain extends Event
r3 update-templates
r3 create AnotherClass extends R3Object
r3 create AnotherClass extends R3Object
r3 create VectorApplierAgain extends Event
r3 create VectorApplierAgain extends Event
r3 update-templates
r3 update-templates
r3 update-templates
r3 update-templates
r3 update-templates
r3 create AnotherClass extends R3Object
r3 create AnotherClass extends R3Object
r3 create VectorApplierAgain extends Event
r3 create VectorApplierAgain extends Event
r3 update-templates

View File

@ -4,6 +4,8 @@ const Utils = require('r3-utils');
/**
OPTIONS_START
x=0
y=1
@ -11,17 +13,19 @@ const Utils = require('r3-utils');
register=true
OPTIONS_END
INSTANCE_OPTIONS_MAPPING_START
x=side.x
y=side.y
z=side.z
INSTANCE_OPTIONS_MAPPING_END
LINKED_OBJECTS_START
LINKED_OBJECTS_END
EXCLUDED_FROM_INSTANCE_OPTIONS_START
register
EXCLUDED_FROM_INSTANCE_OPTIONS_END
**/
@ -57,11 +61,13 @@ class AnotherClass extends R3Object {
}
//OPTIONS_INIT_END
//CUSTOM_OPTIONS_INIT_START
//CUSTOM_OPTIONS_INIT_END
Object.assign(this, options);
//CUSTOM_BEFORE_INIT_START
//CUSTOM_BEFORE_INIT_END
@ -80,9 +86,10 @@ class AnotherClass extends R3Object {
this.graphics.createInstance(
{
//CREATE_INSTANCE_OPTIONS_START
'side.x': this.x,
'side.y': this.y,
'side.z': this.z
'x': this.x,
'y': this.y,
'z': this.z,
'register': this.register
//CREATE_INSTANCE_OPTIONS_END
},
this
@ -90,6 +97,7 @@ class AnotherClass extends R3Object {
}
//CREATE_INSTANCE_BEFORE_END
//CUSTOM_CREATE_INSTANCE_START
//CUSTOM_CREATE_INSTANCE_END
@ -109,19 +117,24 @@ class AnotherClass extends R3Object {
//UPDATE_INSTANCE_OPTIONS_START
if (property === 'x') {
this.instance.side.x = this.x;
this.instance.x = this.x;
return;
}
if (property === 'y') {
this.instance.side.y = this.y;
this.instance.y = this.y;
return;
}
if (property === 'z') {
this.instance.side.z = this.z;
this.instance.z = this.z;
return;
}
if (property === 'register') {
this.instance.register = this.register;
return;
}
//UPDATE_INSTANCE_OPTIONS_END
//CUSTOM_UPDATE_INSTANCE_START
//CUSTOM_UPDATE_INSTANCE_END
@ -141,19 +154,24 @@ class AnotherClass extends R3Object {
//UPDATE_FROM_INSTANCE_OPTIONS_START
if (property === 'x') {
this.x = this.instance.side.x;
this.x = this.instance.x;
return;
}
if (property === 'y') {
this.y = this.instance.side.y;
this.y = this.instance.y;
return;
}
if (property === 'z') {
this.z = this.instance.side.z;
this.z = this.instance.z;
return;
}
if (property === 'register') {
this.register = this.instance.register;
return;
}
//UPDATE_FROM_INSTANCE_OPTIONS_END
//CUSTOM_UPDATE_FROM_INSTANCE_START
//CUSTOM_UPDATE_FROM_INSTANCE_END
@ -171,6 +189,7 @@ class AnotherClass extends R3Object {
this.emit(Event.DISPOSE_OBJECT, this);
//DISPOSE_BEFORE_END
//CUSTOM_DISPOSE_START
//CUSTOM_DISPOSE_END
@ -189,6 +208,7 @@ class AnotherClass extends R3Object {
this.emit(Event.DISPOSE_INSTANCE, this);
//DISPOSE_INSTANCE_BEFORE_END
//CUSTOM_DISPOSE_INSTANCE_START
//CUSTOM_DISPOSE_INSTANCE_END
@ -199,6 +219,7 @@ class AnotherClass extends R3Object {
}
//DISPOSE_INSTANCE_TEMPLATE_END
//CUSTOM_IMPLEMENTATION_START
//CUSTOM_IMPLEMENTATION_END

View File

@ -1,77 +1,172 @@
const R3Object = require('r3-r3-object.js');
const Event = require('r3-event.js');
const Event = require('r3-event');
const Utils = require('r3-utils');
/**
OPTIONS_START
x=0
y=0
z=0
OPTIONS_END
INSTANCE_MAPPING_START
INSTANCE_MAPPING_END
INSTANCE_OPTIONS_MAPPING_START
INSTANCE_OPTIONS_MAPPING_END
LINKED_OBJECTS_START
LINKED_OBJECTS_END
EXCLUDED_FROM_INSTANCE_OPTIONS_START
EXCLUDED_FROM_INSTANCE_OPTIONS_END
**/
class VectorApplierAgain extends R3Object {
class VectorApplierAgain extends Event {
//CONSTRUCTOR_EXTENDS_TEMPLATE_START
constructor(options) {
if (Utils.UndefinedOrNull(options)) {
options = {};
}
options.id = Utils.RandomId(10);
options.name = 'VectorApplierAgain (' + options.id + ')';
super(options);
this.emit(Event.OBJECT_CREATED);
this.emit(Event.OBJECT_CREATED, this);
//OPTIONS_INIT_START
if (Utils.UndefinedOrNull(options.x)) {
options.x = 0;
}
if (Utils.UndefinedOrNull(options.y)) {
options.y = 0;
}
if (Utils.UndefinedOrNull(options.z)) {
options.z = 0;
}
//OPTIONS_INIT_END
this.emit(Event.OBJECT_INITIALIZED);
}
//CUSTOM_OPTIONS_INIT_START
//CUSTOM_OPTIONS_INIT_END
Object.assign(this, options);
//CUSTOM_BEFORE_INIT_START
//CUSTOM_BEFORE_INIT_END
this.emit(Event.OBJECT_INITIALIZED, this);
}
//CONSTRUCTOR_EXTENDS_TEMPLATE_END
//CREATE_INSTANCE_TEMPLATE_START
createInstance() {
//CREATE_INSTANCE_BEFORE_START
this.emit(Event.CREATE_INSTANCE);
super.createInstance();
this.emit(Event.CREATE_INSTANCE, this);
if (this.runtime === 'graphics') {
this.graphics.createInstance(
{
//CREATE_INSTANCE_OPTIONS_START
//CREATE_INSTANCE_OPTIONS_END
},
this
)
}
//CREATE_INSTANCE_BEFORE_END
//CUSTOM_CREATE_INSTANCE_START
//CUSTOM_CREATE_INSTANCE_END
//CREATE_INSTANCE_AFTER_START
this.createInstance();
this.emit(Event.INSTANCE_CREATED);
this.emit(Event.INSTANCE_CREATED, this);
//CREATE_INSTANCE_AFTER_END
}
//CREATE_INSTANCE_TEMPLATE_END
updateInstance() {
//UPDATE_INSTANCE_TEMPLATE_START
updateInstance(property) {
//UPDATE_INSTANCE_BEFORE_START
//UPDATE_INSTANCE_BEFORE_END
this.emit(Event.UPDATE_INSTANCE_BEFORE, this);
//UPDATE_INSTANCE_BEFORE_END
//UPDATE_INSTANCE_OPTIONS_START
//UPDATE_INSTANCE_OPTIONS_END
//CUSTOM_UPDATE_INSTANCE_START
//CUSTOM_UPDATE_INSTANCE_END
//UPDATE_INSTANCE_AFTER_START
//UPDATE_INSTANCE_AFTER_END
this.emit(Event.UPDATE_INSTANCE_AFTER, this);
//UPDATE_INSTANCE_AFTER_END
}
//UPDATE_INSTANCE_TEMPLATE_END
updateFromInstance() {
//UPDATE_FROM_INSTANCE_TEMPLATE_START
updateFromInstance(property) {
//UPDATE_FROM_INSTANCE_BEFORE_START
//UPDATE_FROM_INSTANCE_BEFORE_END
this.emit(Event.UPDATE_FROM_INSTANCE_BEFORE, this);
//UPDATE_FROM_INSTANCE_BEFORE_END
//UPDATE_FROM_INSTANCE_OPTIONS_START
//UPDATE_FROM_INSTANCE_OPTIONS_END
//CUSTOM_UPDATE_FROM_INSTANCE_START
//CUSTOM_UPDATE_FROM_INSTANCE_END
//UPDATE_FROM_INSTANCE_AFTER_START
//UPDATE_FROM_INSTANCE_AFTER_END
this.emit(Event.UPDATE_FROM_INSTANCE_AFTER, this);
//UPDATE_FROM_INSTANCE_AFTER_END
}
//UPDATE_FROM_INSTANCE_TEMPLATE_END
//DISPOSE_TEMPLATE_START
dispose() {
//DISPOSE_BEFORE_START
this.emit(Event.DISPOSE_OBJECT, this);
//DISPOSE_BEFORE_END
//CUSTOM_DISPOSE_START
//CUSTOM_DISPOSE_END
//DISPOSE_AFTER_START
this.emit(Event.OBJECT_DISPOSED, this);
//DISPOSE_AFTER_END
}
//DISPOSE_TEMPLATE_END
//DISPOSE_INSTANCE_TEMPLATE_START
disposeInstance() {
//DISPOSE_INSTANCE_BEFORE_START
super.disposeInstance();
this.emit(Event.DISPOSE_INSTANCE, this);
//DISPOSE_INSTANCE_BEFORE_END
//CUSTOM_DISPOSE_INSTANCE_START
//CUSTOM_DISPOSE_INSTANCE_END
//DISPOSE_INSTANCE_AFTER_START
this.emit(Event.INSTANCE_DISPOSED, this);
//DISPOSE_INSTANCE_AFTER_END
}
//DISPOSE_INSTANCE_TEMPLATE_END
//CUSTOM_IMPLEMENTATION_START
//CUSTOM_IMPLEMENTATION_END
}

2
dist/r3-node/r3.js vendored
View File

@ -7,7 +7,7 @@ class R3 {
}
static version() {
return 'Sat Jun 19 2021 11:37:50 GMT+0000 (Coordinated Universal Time)';
return 'Sat Jun 19 2021 14:40:43 GMT+0000 (Coordinated Universal Time)';
}
}

2
dist/r3.js vendored
View File

@ -1772,7 +1772,7 @@ var R3 = /*#__PURE__*/function () {
_createClass(R3, null, [{
key: "version",
value: function version() {
return 'Sat Jun 19 2021 11:37:50 GMT+0000 (Coordinated Universal Time)';
return 'Sat Jun 19 2021 14:40:43 GMT+0000 (Coordinated Universal Time)';
}
}]);

View File

@ -4,6 +4,8 @@ const Utils = require('r3-utils');
/**
OPTIONS_START
x=0
y=1
@ -11,17 +13,19 @@ const Utils = require('r3-utils');
register=true
OPTIONS_END
INSTANCE_OPTIONS_MAPPING_START
x=side.x
y=side.y
z=side.z
INSTANCE_OPTIONS_MAPPING_END
LINKED_OBJECTS_START
LINKED_OBJECTS_END
EXCLUDED_FROM_INSTANCE_OPTIONS_START
register
EXCLUDED_FROM_INSTANCE_OPTIONS_END
**/
@ -57,11 +61,13 @@ class AnotherClass extends R3Object {
}
//OPTIONS_INIT_END
//CUSTOM_OPTIONS_INIT_START
//CUSTOM_OPTIONS_INIT_END
Object.assign(this, options);
//CUSTOM_BEFORE_INIT_START
//CUSTOM_BEFORE_INIT_END
@ -80,9 +86,10 @@ class AnotherClass extends R3Object {
this.graphics.createInstance(
{
//CREATE_INSTANCE_OPTIONS_START
'side.x': this.x,
'side.y': this.y,
'side.z': this.z
'x': this.x,
'y': this.y,
'z': this.z,
'register': this.register
//CREATE_INSTANCE_OPTIONS_END
},
this
@ -90,6 +97,7 @@ class AnotherClass extends R3Object {
}
//CREATE_INSTANCE_BEFORE_END
//CUSTOM_CREATE_INSTANCE_START
//CUSTOM_CREATE_INSTANCE_END
@ -109,19 +117,24 @@ class AnotherClass extends R3Object {
//UPDATE_INSTANCE_OPTIONS_START
if (property === 'x') {
this.instance.side.x = this.x;
this.instance.x = this.x;
return;
}
if (property === 'y') {
this.instance.side.y = this.y;
this.instance.y = this.y;
return;
}
if (property === 'z') {
this.instance.side.z = this.z;
this.instance.z = this.z;
return;
}
if (property === 'register') {
this.instance.register = this.register;
return;
}
//UPDATE_INSTANCE_OPTIONS_END
//CUSTOM_UPDATE_INSTANCE_START
//CUSTOM_UPDATE_INSTANCE_END
@ -141,19 +154,24 @@ class AnotherClass extends R3Object {
//UPDATE_FROM_INSTANCE_OPTIONS_START
if (property === 'x') {
this.x = this.instance.side.x;
this.x = this.instance.x;
return;
}
if (property === 'y') {
this.y = this.instance.side.y;
this.y = this.instance.y;
return;
}
if (property === 'z') {
this.z = this.instance.side.z;
this.z = this.instance.z;
return;
}
if (property === 'register') {
this.register = this.instance.register;
return;
}
//UPDATE_FROM_INSTANCE_OPTIONS_END
//CUSTOM_UPDATE_FROM_INSTANCE_START
//CUSTOM_UPDATE_FROM_INSTANCE_END
@ -171,6 +189,7 @@ class AnotherClass extends R3Object {
this.emit(Event.DISPOSE_OBJECT, this);
//DISPOSE_BEFORE_END
//CUSTOM_DISPOSE_START
//CUSTOM_DISPOSE_END
@ -189,6 +208,7 @@ class AnotherClass extends R3Object {
this.emit(Event.DISPOSE_INSTANCE, this);
//DISPOSE_INSTANCE_BEFORE_END
//CUSTOM_DISPOSE_INSTANCE_START
//CUSTOM_DISPOSE_INSTANCE_END
@ -199,6 +219,7 @@ class AnotherClass extends R3Object {
}
//DISPOSE_INSTANCE_TEMPLATE_END
//CUSTOM_IMPLEMENTATION_START
//CUSTOM_IMPLEMENTATION_END

View File

@ -1,77 +1,172 @@
const R3Object = require('r3-r3-object.js');
const Event = require('r3-event.js');
const Event = require('r3-event');
const Utils = require('r3-utils');
/**
OPTIONS_START
x=0
y=0
z=0
OPTIONS_END
INSTANCE_MAPPING_START
INSTANCE_MAPPING_END
INSTANCE_OPTIONS_MAPPING_START
INSTANCE_OPTIONS_MAPPING_END
LINKED_OBJECTS_START
LINKED_OBJECTS_END
EXCLUDED_FROM_INSTANCE_OPTIONS_START
EXCLUDED_FROM_INSTANCE_OPTIONS_END
**/
class VectorApplierAgain extends R3Object {
class VectorApplierAgain extends Event {
//CONSTRUCTOR_EXTENDS_TEMPLATE_START
constructor(options) {
if (Utils.UndefinedOrNull(options)) {
options = {};
}
options.id = Utils.RandomId(10);
options.name = 'VectorApplierAgain (' + options.id + ')';
super(options);
this.emit(Event.OBJECT_CREATED);
this.emit(Event.OBJECT_CREATED, this);
//OPTIONS_INIT_START
if (Utils.UndefinedOrNull(options.x)) {
options.x = 0;
}
if (Utils.UndefinedOrNull(options.y)) {
options.y = 0;
}
if (Utils.UndefinedOrNull(options.z)) {
options.z = 0;
}
//OPTIONS_INIT_END
this.emit(Event.OBJECT_INITIALIZED);
}
//CUSTOM_OPTIONS_INIT_START
//CUSTOM_OPTIONS_INIT_END
Object.assign(this, options);
//CUSTOM_BEFORE_INIT_START
//CUSTOM_BEFORE_INIT_END
this.emit(Event.OBJECT_INITIALIZED, this);
}
//CONSTRUCTOR_EXTENDS_TEMPLATE_END
//CREATE_INSTANCE_TEMPLATE_START
createInstance() {
//CREATE_INSTANCE_BEFORE_START
this.emit(Event.CREATE_INSTANCE);
super.createInstance();
this.emit(Event.CREATE_INSTANCE, this);
if (this.runtime === 'graphics') {
this.graphics.createInstance(
{
//CREATE_INSTANCE_OPTIONS_START
//CREATE_INSTANCE_OPTIONS_END
},
this
)
}
//CREATE_INSTANCE_BEFORE_END
//CUSTOM_CREATE_INSTANCE_START
//CUSTOM_CREATE_INSTANCE_END
//CREATE_INSTANCE_AFTER_START
this.createInstance();
this.emit(Event.INSTANCE_CREATED);
this.emit(Event.INSTANCE_CREATED, this);
//CREATE_INSTANCE_AFTER_END
}
//CREATE_INSTANCE_TEMPLATE_END
updateInstance() {
//UPDATE_INSTANCE_TEMPLATE_START
updateInstance(property) {
//UPDATE_INSTANCE_BEFORE_START
//UPDATE_INSTANCE_BEFORE_END
this.emit(Event.UPDATE_INSTANCE_BEFORE, this);
//UPDATE_INSTANCE_BEFORE_END
//UPDATE_INSTANCE_OPTIONS_START
//UPDATE_INSTANCE_OPTIONS_END
//CUSTOM_UPDATE_INSTANCE_START
//CUSTOM_UPDATE_INSTANCE_END
//UPDATE_INSTANCE_AFTER_START
//UPDATE_INSTANCE_AFTER_END
this.emit(Event.UPDATE_INSTANCE_AFTER, this);
//UPDATE_INSTANCE_AFTER_END
}
//UPDATE_INSTANCE_TEMPLATE_END
updateFromInstance() {
//UPDATE_FROM_INSTANCE_TEMPLATE_START
updateFromInstance(property) {
//UPDATE_FROM_INSTANCE_BEFORE_START
//UPDATE_FROM_INSTANCE_BEFORE_END
this.emit(Event.UPDATE_FROM_INSTANCE_BEFORE, this);
//UPDATE_FROM_INSTANCE_BEFORE_END
//UPDATE_FROM_INSTANCE_OPTIONS_START
//UPDATE_FROM_INSTANCE_OPTIONS_END
//CUSTOM_UPDATE_FROM_INSTANCE_START
//CUSTOM_UPDATE_FROM_INSTANCE_END
//UPDATE_FROM_INSTANCE_AFTER_START
//UPDATE_FROM_INSTANCE_AFTER_END
this.emit(Event.UPDATE_FROM_INSTANCE_AFTER, this);
//UPDATE_FROM_INSTANCE_AFTER_END
}
//UPDATE_FROM_INSTANCE_TEMPLATE_END
//DISPOSE_TEMPLATE_START
dispose() {
//DISPOSE_BEFORE_START
this.emit(Event.DISPOSE_OBJECT, this);
//DISPOSE_BEFORE_END
//CUSTOM_DISPOSE_START
//CUSTOM_DISPOSE_END
//DISPOSE_AFTER_START
this.emit(Event.OBJECT_DISPOSED, this);
//DISPOSE_AFTER_END
}
//DISPOSE_TEMPLATE_END
//DISPOSE_INSTANCE_TEMPLATE_START
disposeInstance() {
//DISPOSE_INSTANCE_BEFORE_START
super.disposeInstance();
this.emit(Event.DISPOSE_INSTANCE, this);
//DISPOSE_INSTANCE_BEFORE_END
//CUSTOM_DISPOSE_INSTANCE_START
//CUSTOM_DISPOSE_INSTANCE_END
//DISPOSE_INSTANCE_AFTER_START
this.emit(Event.INSTANCE_DISPOSED, this);
//DISPOSE_INSTANCE_AFTER_END
}
//DISPOSE_INSTANCE_TEMPLATE_END
//CUSTOM_IMPLEMENTATION_START
//CUSTOM_IMPLEMENTATION_END
}

View File

@ -10,7 +10,23 @@ else {
echo "argc and argv disabled\n";
}
if ($argv[1] == 'all') {
$save = [
'options' => '/^\s*\bOPTIONS_START\b.*\bOPTIONS_END\b/sm',
'instance_mappings' => '/^\s*\bINSTANCE_OPTIONS_MAPPING_START\b.*\bINSTANCE_OPTIONS_MAPPING_END\b/sm',
'linked_objects' => '/^\s*\bLINKED_OBJECTS_START\b.*\bLINKED_OBJECTS_END\b/sm',
'excluded_options' => '/^\s*\bEXCLUDED_FROM_INSTANCE_OPTIONS_START\b.*\bEXCLUDED_FROM_INSTANCE_OPTIONS_END\b/sm',
'custom_options' => '/^\s*\/\/\bCUSTOM_OPTIONS_INIT_START\b.*\/\/\bCUSTOM_OPTIONS_INIT_END\b/sm',
'custom_before_init' => '/^\s*\/\/\bCUSTOM_BEFORE_INIT_START\b.*\/\/\bCUSTOM_BEFORE_INIT_END\b/sm',
'custom_create_instance' => '/^\s*\/\/\bCUSTOM_CREATE_INSTANCE_START\b.*\/\/\bCUSTOM_CREATE_INSTANCE_END\b/sm',
'custom_update_instance' => '/^\s*\/\/\bCUSTOM_UPDATE_INSTANCE_START\b.*\/\/\bCUSTOM_UPDATE_INSTANCE_END\b/sm',
'custom_update_from_instance' => '/^\s*\/\/\bCUSTOM_UPDATE_FROM_INSTANCE_START\b.*\/\/\bCUSTOM_UPDATE_FROM_INSTANCE_END\b/sm',
'custom_dispose' => '/^\s*\/\/\bCUSTOM_DISPOSE_START\b.*\/\/\bCUSTOM_DISPOSE_END\b/sm',
'custom_dispose_instance' => '/^\s*\/\/\bCUSTOM_DISPOSE_INSTANCE_START\b.*\/\/\bCUSTOM_DISPOSE_INSTANCE_END\b/sm',
'custom_implementation' => '/^\s*\/\/\bCUSTOM_IMPLEMENTATION_START\b.*\/\/\bCUSTOM_IMPLEMENTATION_END\b/sm'
];
if ($argv[2] == 'all') {
$files = scandir('src/r3', SCANDIR_SORT_DESCENDING);
$newFiles = [];
@ -24,133 +40,62 @@ if ($argv[1] == 'all') {
$files = $newFiles;
} else {
$files = [$argv[1]];
$files = [$argv[2]];
}
function getContents($contents, $regex) {
$matches = [];
preg_match($regex, $contents, $matches);
if (sizeof($matches) > 0) {
return $matches[0];
} else {
return null;
}
}
foreach ($files as $file) {
echo $file . "\n";
if ($argv[1] == 'save') {
echo "processing file " . $file . "\n";
echo "saving file " . $file . "\n";
$fn = fopen($file, "r");
$contents = file_get_contents($file);
$startCapture = false;
$saved = [];
$saveLine = true;
foreach ($save as $key => $regex) {
$options = [];
$lines = [];
while (!feof($fn)) {
$line = fgets($fn);
if (
preg_match('/OPTIONS_END/', $line)
) {
$startCapture = false;
}
if (
preg_match('/OPTIONS_INIT_END/', $line)
) {
$saveLine = true;
}
if ($saveLine) {
array_push($lines, $line);
}
if (
preg_match('/OPTIONS_INIT_START/', $line)
) {
$saveLine = false;
}
if ($startCapture) {
$line = trim($line);
$key_value = preg_split('/=/', $line);
if ($key_value === false) {
continue;
$value = getContents($contents, $regex);
if ($value) {
array_push($saved, "\n");
array_push($saved, $value);
array_push($saved, "\n");
}
$options[$key_value[0]] = $key_value[1];
}
file_put_contents($file . '.saved', $saved);
echo "saved file " . $file . ".saved\n";
} else if ($argv[1] == 'restore') {
echo "restoring file " . $file . "\n";
$saved = file_get_contents($file . '.saved');
$new = file_get_contents($file);
foreach ($save as $key => $regex) {
$value = getContents($saved, $regex);
echo "restoring " . $key . " in " . $file;
if ($value && preg_match($regex, $new)) {
$new = preg_replace($regex, $value, $new);
}
}
if (
preg_match('/OPTIONS_START/', $line)
) {
$startCapture = true;
}
file_put_contents($file, $new);
}
fclose($fn);
file_put_contents($file, $lines);
$template = file_get_contents('src/templates/options_init.template');
$newOptions = '';
foreach ($options as $key => $value) {
$updated = str_replace('KEY', $key, $template);
$updated = str_replace('VALUE', $value, $updated);
$newOptions .= $updated;
}
$contents = file_get_contents($file);
$contents = preg_replace(
'/\/\/OPTIONS_INIT_START.*?\/\/OPTIONS_INIT_END/s',
"//OPTIONS_INIT_START\n" . $newOptions . "\t\t//OPTIONS_INIT_END",
$contents
);
file_put_contents($file, $contents);
print_r($newOptions);
}
exit(0);
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);
?>