From 378ff808ec2600f94c7a6f0fb02fef2184901c93 Mon Sep 17 00:00:00 2001 From: Josef Date: Fri, 26 Jul 2024 07:45:02 +0200 Subject: [PATCH] Properties Update --- create-cpp.js | 47 +++++++++++++++++-- godot | 2 +- library.js | 8 ++++ rokojori-action-library | 2 +- .../RJTimeLineManager.json | 4 +- .../properties/RJBoolProperty.json | 10 ++++ .../properties/RJNodeProperty.json | 10 ++++ .../properties/RJNumberProperty.json | 12 +++++ .../properties/RJStringProperty.json | 10 ++++ 9 files changed, 96 insertions(+), 9 deletions(-) create mode 100644 rokojori-action-library-definitions/properties/RJBoolProperty.json create mode 100644 rokojori-action-library-definitions/properties/RJNodeProperty.json create mode 100644 rokojori-action-library-definitions/properties/RJNumberProperty.json create mode 100644 rokojori-action-library-definitions/properties/RJStringProperty.json diff --git a/create-cpp.js b/create-cpp.js index 6107adf..ebaab3b 100644 --- a/create-cpp.js +++ b/create-cpp.js @@ -1,6 +1,6 @@ const fs = require( "node:fs/promises" ); const path = require( "path" ); -const { loadJSON, getFiles, saveUTF8, getMatches, loadUTF8, insertText } = require( "./library.js" ); +const { loadJSON, getFiles, saveUTF8, getMatches, loadUTF8, insertText, isDirectory } = require( "./library.js" ); const { CppClassMember } = require( "./cpp-class-member.js" ); function createCppHeader( className, extendingClassName, headerDefine, protectedMembers, @@ -121,7 +121,7 @@ async function main() for ( let file of files ) { - await createCppFiles( file, types, missingTypes ); + await createCppFiles( path.join( definitionsPath, file ), types, missingTypes ); } if ( missingTypes.length === 0 ) @@ -175,9 +175,29 @@ function grabMembers( membersData ) let nameDefinition = it; let memberData = membersData[ it ]; - let classMember = new CppClassMember( nameDefinition, memberData ); + let actionRegex = /^\s*action\s+(\w+)\s*$/; + + if ( actionRegex.test( nameDefinition ) ) + { + let name = actionRegex.exec( nameDefinition )[ 1 ]; + let upperCaseName = name[ 0 ].toUpperCase() + name.substring( 1 ); + let actionName = `on${upperCaseName}`; + + let signal = `signal ${name}()`; + let actionGetter = `virtual get_${actionName}():Ref`; + let actionSetter = `virtual set_${actionName}()`; + + members.push( new CppClassMember( signal, {} ) ); + members.push( new CppClassMember( actionGetter, {} ) ); + members.push( new CppClassMember( actionSetter, { "action":"Ref"} ) ); + } + else + { + let classMember = new CppClassMember( nameDefinition, memberData ); + members.push( classMember ); + } + - members.push( classMember ); } return members; @@ -230,7 +250,22 @@ async function createCppFiles( definitionPath, types, missingTypes ) { console.log( "Creating: ", definitionPath ); - let jsonPath = path.join( definitionsPath, definitionPath ); + let jsonPath = definitionPath; + // path.join( definitionsPath, definitionPath ); + + let isDir = await isDirectory( jsonPath ); + + if ( isDir ) + { + let files = await getFiles( jsonPath ); + + for ( let file of files ) + { + await createCppFiles( path.join( jsonPath, file ), types, missingTypes ); + } + + return Promise.resolve(); + } let data = await loadJSON( jsonPath ); @@ -297,6 +332,8 @@ async function createCppFiles( definitionPath, types, missingTypes ) let rawFilePath = path.join( outputPath, className ); await saveUTF8( rawFilePath + ".h", header ); await saveUTF8( rawFilePath + ".cpp", implementation ); + + return Promise.resolve(); } diff --git a/godot b/godot index 11d3768..f0e20ef 160000 --- a/godot +++ b/godot @@ -1 +1 @@ -Subproject commit 11d3768132582d192b8464769f26b493ae822321 +Subproject commit f0e20efb33adbf9d6d9c111d646685a30bdd8f4f diff --git a/library.js b/library.js index 799eca3..9465d99 100644 --- a/library.js +++ b/library.js @@ -6,6 +6,13 @@ async function getFiles( filePath ) return await fs.readdir( filePath ); } +async function isDirectory( filePath ) +{ + let stats = await fs.stat( filePath ); + + return stats.isDirectory(); +} + async function exists( filePath ) { try @@ -154,6 +161,7 @@ function insertText( sourceText, insertText, insertPosition ) module.exports = { exists, + isDirectory, loadUTF8, saveUTF8, loadJSON, diff --git a/rokojori-action-library b/rokojori-action-library index c19d8b7..650c341 160000 --- a/rokojori-action-library +++ b/rokojori-action-library @@ -1 +1 @@ -Subproject commit c19d8b71d88206e99fa2c987d369ac713c275d41 +Subproject commit 650c34164ae6a39bdce2d748888092c660a1ebd6 diff --git a/rokojori-action-library-definitions/RJTimeLineManager.json b/rokojori-action-library-definitions/RJTimeLineManager.json index 9a9616c..826b95b 100644 --- a/rokojori-action-library-definitions/RJTimeLineManager.json +++ b/rokojori-action-library-definitions/RJTimeLineManager.json @@ -38,8 +38,8 @@ "isPersistent": "bool" }, - "signal onEvent()" : { "callbackID": "int" }, + "signal onEvent()" : { "callbackID": "int" }, - "signal onSpan()" : { "callbackID": "int", "spanType": "int" } + "signal onSpan()" : { "callbackID": "int", "spanType": "int" } } } \ No newline at end of file diff --git a/rokojori-action-library-definitions/properties/RJBoolProperty.json b/rokojori-action-library-definitions/properties/RJBoolProperty.json new file mode 100644 index 0000000..e5cacdb --- /dev/null +++ b/rokojori-action-library-definitions/properties/RJBoolProperty.json @@ -0,0 +1,10 @@ +{ + "class":"RJBoolProperty:RJNetworkNode", + + "public": + { + "virtual set()" : { "value":"bool" }, + "virtual get():bool": {}, + "signal onChange()" : {} + } +} \ No newline at end of file diff --git a/rokojori-action-library-definitions/properties/RJNodeProperty.json b/rokojori-action-library-definitions/properties/RJNodeProperty.json new file mode 100644 index 0000000..0987148 --- /dev/null +++ b/rokojori-action-library-definitions/properties/RJNodeProperty.json @@ -0,0 +1,10 @@ +{ + "class":"RJNodeProperty:RJNetworkNode", + + "public": + { + "virtual set()" : { "value":"Ref" }, + "virtual get():Ref": {}, + "signal onChange()" : {} + } +} \ No newline at end of file diff --git a/rokojori-action-library-definitions/properties/RJNumberProperty.json b/rokojori-action-library-definitions/properties/RJNumberProperty.json new file mode 100644 index 0000000..60eb4de --- /dev/null +++ b/rokojori-action-library-definitions/properties/RJNumberProperty.json @@ -0,0 +1,12 @@ +{ + "class":"RJNumberProperty:RJNetworkNode", + + "includes":[ "./RJAction.h" ], + + "public": + { + "virtual set()" : { "value":"double" }, + "virtual get():double": {}, + "action changed" : {} + } +} \ No newline at end of file diff --git a/rokojori-action-library-definitions/properties/RJStringProperty.json b/rokojori-action-library-definitions/properties/RJStringProperty.json new file mode 100644 index 0000000..adbdd69 --- /dev/null +++ b/rokojori-action-library-definitions/properties/RJStringProperty.json @@ -0,0 +1,10 @@ +{ + "class":"RJStringProperty:RJNetworkNode", + + "public": + { + "virtual set()" : { "value":"String" }, + "virtual get():String": {}, + "signal onChange()" : {} + } +} \ No newline at end of file