fix imports + dist build

master
Theunis J. Botha 2021-09-18 11:06:19 +02:00
parent 165dba208f
commit 5a0029810e
11 changed files with 4883 additions and 4854 deletions

3
dist/index.html vendored
View File

@ -22,7 +22,8 @@
</script>
<script type="application/javascript">
window.addEventListener("load", function(){
let object = new R3.Canvas();
let canvas = new R3.Canvas();
let image = new R3.Image();
});
</script>
</body>

9490
dist/r3.js vendored

File diff suppressed because it is too large Load Diff

157
r3.php
View File

@ -1161,6 +1161,25 @@ function buildIndexBody($graph, $node, &$body, $nameSpace)
}
function buildImportsAndBody(&$imports, &$body, $node, $type, $nameSpace)
{
$originalNameSpace = $nameSpace;
foreach ($node->children as $child) {
$nameSpace = $originalNameSpace . '.' . $child->nameSpaceClassName;
$file = str_replace('src/r3/r3-' . strtolower($type), '.', $child->file);
array_push($imports, "const " . $child->name . ' = require(\'' . $file . "');");
array_push($body, "$nameSpace = " . $child->name . ';');
$child->nameSpace = $nameSpace;
buildImportsAndBody($imports, $body, $child, $type, $nameSpace);
}
}
function generateIndex($types)
{
/**
@ -1176,55 +1195,24 @@ function generateIndex($types)
$body = [];
$exports = [];
if ($type === 'Runtime') {
$nodes = $graph->walk();
$nodes = $graph->walk();
foreach ($nodes as $node) {
foreach ($nodes as $node) {
if (preg_match('/\bRuntime\b/', $node->name) && $node->isBaseClass) {
if (preg_match("/\b$type\b/", $node->name)) {
$file = str_replace('src/r3/r3-' . strtolower($type), '.', $node->file);
$file = str_replace('src/r3/r3-' . strtolower($type), '.', $node->file);
array_push($imports, "const " . $node->name . ' = require(\'' . $file . "');");
array_push($imports, "const " . $node->name . ' = require(\'' . $file . "');");
foreach ($node->children as $child) {
$file = str_replace('src/r3/r3-' . strtolower($type), '.', $child->file);
array_push($imports, "const " . $child->name . ' = require(\'' . $file . "');");
array_push($body, 'Runtime.' . str_replace('Runtime', '', $child->name) . ' = ' . $child->name . ';');
foreach ($child->children as $implementation) {
$file = str_replace('src/r3/r3-' . strtolower($type), '.', $implementation->file);
array_push($imports, "const " . $implementation->name . ' = require(\'' . $file . "');");
// array_push($body, 'Runtime.' . str_replace('Runtime', '', $implementation->name) . ' = ' . $implementation->name . ';');
array_push($body, 'Runtime.' . str_replace('Runtime', '', $child->name) . '.' . str_replace('Runtime', '', $implementation->name) . ' = ' . $implementation->name . ';');
}
}
}
}
array_push($exports, 'module.exports = Runtime;');
} else {
$node = $graph->search('name', $type);
$children = $graph->flatten($node);
$nodes = array_merge([$node], $children);
foreach ($nodes as $child) {
$file = str_replace('src/r3/r3-' . strtolower($type), '.', $child->file);
array_push($imports, "const " . $child->name . ' = require(\'' . $file . "');");
buildImportsAndBody($imports, $body, $node, $type, $type);
}
buildIndexBody($graph, $node, $body, $node->nameSpaceClassName);
array_push($exports, 'module.exports = ' . $node->name . ';');
}
array_push($exports, "module.exports = $type;");
$indexFile = 'src/r3/r3-'. strtolower($type) . '/index.js';
file_put_contents($indexFile, $template);
@ -1269,7 +1257,9 @@ function generateR3($nodes, $graph)
$children = $graph->flatten($component);
foreach ($children as $child) {
array_push($defines, 'R3.' . $child->nameSpaceClassName . ' = ' . $child->name);
if (sizeof($child->children) === 0) {
array_push($defines, 'R3.' . $child->nameSpaceClassName . ' = ' . $child->nameSpace);
}
}
$r3File = 'src/r3/r3-r3.js';
@ -1314,7 +1304,7 @@ function generateR3($nodes, $graph)
* Node $node
*/
if (preg_match('/\bSystem\w+\b/', $node->name)){
array_push($indexBody, $node->nameSpace . $node->nameSpaceClassName . ".Start();");
array_push($indexBody, 'R3.' . $node->nameSpace . ".Start();");
}
}
@ -1411,8 +1401,31 @@ function generateEvents()
}
function writeSource($node, $file)
{
foreach ($node->children as $child) {
$contents = file_get_contents($child->file);
fwrite($file, $contents);
writeSource($child, $file);
}
}
function buildDefines(&$defines, $node, $nameSpace)
{
$originalNameSpace = $nameSpace;
foreach ($node->children as $child) {
$nameSpace = $originalNameSpace . '.' . $child->nameSpaceClassName;
array_push($defines, $nameSpace. ' = ' . $child->nameSpaceClassName);
buildDefines($defines, $child, $nameSpace);
}
}
function generateR3Dist($nodes)
{
global $graph;
$r3jsFile = 'dist/r3.js';
$r3jsSource = 'src/r3/r3-r3.js';
$r3jsBaseTemplate = 'src/templates/r3_base.template';
@ -1434,25 +1447,15 @@ function generateR3Dist($nodes)
$generateTokens = getTokens(['GENERATED']);
$customTokens = getTokens(['CUSTOM']);
$savedGenerate = save($r3jsSource, $generateTokens)[1];
$savedCustom = save($r3jsSource, $customTokens)[1];
$r3 = $graph->search('name', 'R3');
foreach ($nodes as $node) {
$contents = file_get_contents($node->file);
fwrite($r3js, $contents);
}
writeSource($r3, $r3js);
foreach ($savedGenerate as $key => $store)
{
// $defines = [];
if ($key === 'GENERATED_IMPORTS') {
continue;
}
// buildDefines($defines, $r3, "R3");
foreach ($store as $line) {
fwrite($r3js, $line);
}
}
// fwrite($r3js, join("\n", $defines));
$indexFiles = [
'src/r3/r3-system/index.js',
@ -1480,6 +1483,20 @@ function generateR3Dist($nodes)
deleteSavedFile($indexFile . '.saved');
}
$savedGenerate = save($r3jsSource, $generateTokens)[1];
$savedCustom = save($r3jsSource, $customTokens)[1];
foreach ($savedGenerate as $key => $store)
{
if ($key === 'GENERATED_IMPORTS') {
continue;
}
foreach ($store as $line) {
fwrite($r3js, $line);
}
}
foreach ($savedCustom as $key => $store)
{
foreach ($store as $line) {
@ -1487,7 +1504,11 @@ function generateR3Dist($nodes)
}
}
$contents = file_get_contents('src/r3/index.js');
fwrite($r3js, $contents);
fclose($r3js);
@ -1537,13 +1558,6 @@ function generateR3Dist($nodes)
*/
$contents = preg_replace('/.*\b' . $customTokenKey . '(_START|_END)\b.*?\n/m', '', $contents );
}
//
// foreach ($templateTokens as $templateTokenKey => $templateTokenValue) {
// /**
// * Remove generate tokens
// */
// $contents = preg_replace('/.*\b' . $templateTokenKey . '(_START|_END)\b.*?\n/m', '', $contents );
// }
$contents = preg_replace('/\n^\/\*\*\s+\*\*\/\s*?$/sm', '', $contents);
@ -1692,18 +1706,11 @@ function generateOutOfClassImplementationDefines($graph, $types)
$i++;
}
updateSection($parent->file, 'GENERATED_OUT_OF_CLASS_IMPLEMENTATION' , $updateList);
}
if (preg_match('/\bRuntime\w+/', $node->name) && $node->parent->name === 'Runtime') {
$parent = $node;
$updateList = [];
foreach ($parent->children as $child) {
array_push($updateList, 'Runtime.' . strtoupper(from_camel_case(str_replace('Runtime','', $child->name))) . ' = 0x' . dechex($i) . ";\n");
$i++;
foreach ($child->children as $implementation) {
array_push($updateList, 'Runtime.' . strtoupper(from_camel_case(str_replace('Runtime', '', $implementation->name))) . ' = 0x' . dechex($i) . ";\n");
$i++;
}
}
updateSection($parent->file, 'GENERATED_OUT_OF_CLASS_IMPLEMENTATION' , $updateList);
@ -1722,7 +1729,7 @@ function generateOutOfClassImplementationDefines($graph, $types)
$children = $graph->flatten($parent);
foreach ($children as $child) {
array_push($updateList, $parent->name . '.' . strtoupper(from_camel_case($child->name)) . ' = 0x' . dechex($i) . ";\n");
array_push($updateList, $parent->name . '.' . strtoupper(from_camel_case(str_replace($parent->name, '', $child->name))) . ' = 0x' . dechex($i) . ";\n");
$i++;
}

View File

@ -4,13 +4,13 @@ const R3 = require('r3-r3.js');
//GENERATED_INDEX_BODY_START
console.log('r3.js - version ' + R3.version + ' compiled ' + R3.compileDate);
SystemDOM.Start();
SystemInput.Start();
SystemLinking.Start();
SystemRender.Start();
SystemRuntime.Start();
SystemSocket.Start();
SystemStorage.Start();
R3.System.DOM.Start();
R3.System.Input.Start();
R3.System.Linking.Start();
R3.System.Render.Start();
R3.System.Runtime.Start();
R3.System.Socket.Start();
R3.System.Storage.Start();
//GENERATED_INDEX_BODY_END
//GENERATED_EXPORTS_START

View File

@ -296,15 +296,15 @@ class Component extends R3Object {
//GENERATED_STATIC_OPTIONS_INIT_END
//GENERATED_OUT_OF_CLASS_IMPLEMENTATION_START
Component.COMPONENT_DOM = 0x0;
Component.COMPONENT_CANVAS = 0x1;
Component.COMPONENT_GRAPHICS = 0x2;
Component.COMPONENT_IMAGE = 0x3;
Component.COMPONENT_MATERIAL = 0x4;
Component.COMPONENT_MESH = 0x5;
Component.COMPONENT_TEXTURE = 0x6;
Component.COMPONENT_INPUT = 0x7;
Component.COMPONENT_TOUCH = 0x8;
Component.DOM = 0x0;
Component.CANVAS = 0x1;
Component.GRAPHICS = 0x2;
Component.IMAGE = 0x3;
Component.MATERIAL = 0x4;
Component.MESH = 0x5;
Component.TEXTURE = 0x6;
Component.INPUT = 0x7;
Component.TOUCH = 0x8;
Component.MAX_COMPONENT = 0x9;
//GENERATED_OUT_OF_CLASS_IMPLEMENTATION_END

View File

@ -202,7 +202,7 @@ class Entity extends R3Object {
//GENERATED_STATIC_OPTIONS_INIT_END
//GENERATED_OUT_OF_CLASS_IMPLEMENTATION_START
Entity.ENTITY_SLIDER = 0x0;
Entity.SLIDER = 0x0;
Entity.MAX_ENTITY = 0x1;
//GENERATED_OUT_OF_CLASS_IMPLEMENTATION_END

View File

@ -1,6 +1,6 @@
class R3 {
static version = '2.0.758';
static compileDate = '2021 Sep 18 - 08:48:43 am';
static compileDate = '2021 Sep 18 - 11:04:13 am';
}
//GENERATED_IMPORTS_START
@ -23,15 +23,12 @@ R3.Object = R3Object;
R3.Entity = Entity;
R3.Component = Component;
R3.Project = Project;
R3.DOM = ComponentDOM;
R3.Canvas = ComponentCanvas;
R3.Graphics = ComponentGraphics;
R3.Image = ComponentImage;
R3.Material = ComponentMaterial;
R3.Mesh = ComponentMesh;
R3.Texture = ComponentTexture;
R3.Input = ComponentInput;
R3.Touch = ComponentTouch;
R3.Canvas = Component.DOM.Canvas;
R3.Image = Component.Graphics.Image;
R3.Material = Component.Graphics.Material;
R3.Mesh = Component.Graphics.Mesh;
R3.Texture = Component.Graphics.Texture;
R3.Touch = Component.Input.Touch;
//GENERATED_DEFINES_END
//CUSTOM_CONVENIENT_DEFINES_START

View File

@ -74,7 +74,6 @@ class RuntimeCoder extends Runtime {
//GENERATED_STATIC_OPTIONS_INIT_END
//GENERATED_OUT_OF_CLASS_IMPLEMENTATION_START
Runtime.CODE_MIRROR = 0x8;
//GENERATED_OUT_OF_CLASS_IMPLEMENTATION_END
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START

View File

@ -93,6 +93,14 @@ Runtime.BASE_IMAGE = 0x4;
Runtime.BASE_PHYSICS = 0x5;
Runtime.BASE_SOCKET = 0x6;
Runtime.BASE_STATISTICS = 0x7;
Runtime.CODE_MIRROR = 0x8;
Runtime.DOCUMENT = 0x9;
Runtime.CONTROL_KIT = 0xa;
Runtime.THREE = 0xb;
Runtime.NODE_JS_IMAGE = 0xc;
Runtime.WEB_IMAGE = 0xd;
Runtime.BULLET = 0xe;
Runtime.STATS = 0xf;
//GENERATED_OUT_OF_CLASS_IMPLEMENTATION_END
//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START

View File

@ -224,14 +224,21 @@ class SystemRuntime extends System {
//CUSTOM_STATIC_ON_GET_RUNTIME_METHOD_START
if (object instanceof R3.Component.DOM) {
return new R3.Runtime.DOM.Document();
if (SystemRuntime.CurrentProject === null) {
console.log('There currently is no active project - using the default DOM runtime');
return new R3.Runtime.DOM.Document();
} else {
console.log('TODO: implement a project based DOM runtime');
}
}
if (object instanceof R3.Image) {
if (SystemRuntime.CurrentProject === null) {
return new R3.Runtime.Image.WebImage();
} else {
console.log('TODO: implement a project based Image runtime');
}
}
//CUSTOM_STATIC_ON_GET_RUNTIME_METHOD_END
}

View File

@ -89,13 +89,13 @@ class System {
//GENERATED_STATIC_OPTIONS_INIT_END
//GENERATED_OUT_OF_CLASS_IMPLEMENTATION_START
System.SYSTEM_DOM = 0x0;
System.SYSTEM_INPUT = 0x1;
System.SYSTEM_LINKING = 0x2;
System.SYSTEM_RENDER = 0x3;
System.SYSTEM_RUNTIME = 0x4;
System.SYSTEM_SOCKET = 0x5;
System.SYSTEM_STORAGE = 0x6;
System.DOM = 0x0;
System.INPUT = 0x1;
System.LINKING = 0x2;
System.RENDER = 0x3;
System.RUNTIME = 0x4;
System.SOCKET = 0x5;
System.STORAGE = 0x6;
System.MAX_SYSTEM = 0x7;
//GENERATED_OUT_OF_CLASS_IMPLEMENTATION_END