From 81a55f96b87009946e7b8ed2b4ee232214c7117e Mon Sep 17 00:00:00 2001 From: Josef Date: Sun, 12 May 2024 19:02:28 +0200 Subject: [PATCH] Icon Update --- cpp-class-member.js | 84 ++++++++++++++++++- create-cpp.js | 22 ++++- rokojori-action-library | 2 +- .../RJSequenceAction.json | 10 --- .../_RJSequenceAction.json | 11 +++ 5 files changed, 112 insertions(+), 17 deletions(-) delete mode 100644 rokojori-action-library-definitions/RJSequenceAction.json create mode 100644 rokojori-action-library-definitions/_RJSequenceAction.json diff --git a/cpp-class-member.js b/cpp-class-member.js index 203d985..22c7338 100644 --- a/cpp-class-member.js +++ b/cpp-class-member.js @@ -10,6 +10,7 @@ class CppClassMember isMethod = false; isVirtual = false; isStatic = false; + isSignal = false; type = "void"; parameters = []; @@ -36,6 +37,11 @@ class CppClassMember this.isStatic = true; } + if ( "signal" === names[ i ] ) + { + this.isSignal = true; + } + } if ( this.isMethod ) @@ -83,7 +89,24 @@ class CppClassMember getMethodBinding( className ) { - if ( this.isVirtual ) + if ( this.isSignal ) + { + //ADD_SIGNAL(MethodInfo("session_supported", PropertyInfo(Variant::STRING, "session_mode"), PropertyInfo(Variant::BOOL, "supported"))); + let parameterInfos = ""; + + for ( let i = 0; i < this.parameters.length; i++ ) + { + let type = stringToVariantType( this.parameters[ i ].type ); + let name = this.parameters[ i ].name; + + let pi = `, PropertyInfo(Variant::${type}, "${name}")`; + + parameterInfos += pi; + } + + return `ADD_SIGNAL (MethodInfo( "${this.name}" ${parameterInfos}) );`; + } + else if ( this.isVirtual ) { return `GDVIRTUAL_BIND( ${this.name} );`; } @@ -95,7 +118,11 @@ class CppClassMember getHeaderDefinition() { - if ( this.isMethod ) + if ( this.isSignal ) + { + return `/* signal ${this.name} */`; + } + else if ( this.isMethod ) { return this.getMethodHeaderDefinition(); } @@ -143,4 +170,57 @@ module.exports = { CppParameter, CppClassMember +} + + +function stringToVariantType( stringType ) +{ + switch( stringType ) + { + case "bool": return "BOOL"; + case "int": return "INT"; + case "float": return "FLOAT"; + case "String": return "STRING"; + + // Math types. + case "Vector2": return "VECTOR2"; + case "Vector2i": return "VECTOR2I"; + case "Rect2": return "RECT2"; + case "Rect2i": return "RECT2I"; + case "Transform2D": return "TRANSFORM2D"; + case "Vector3": return "VECTOR3"; + case "Vector3i": return "VECTOR3I"; + case "Vector4": return "VECTOR4"; + case "Vector4i": return "VECTOR4I"; + case "Plane": return "PLANE"; + case "AABB": return "AABB"; + case "Quaternion": return "QUATERNION"; + case "Basis": return "BASIS"; + case "Transform3D": return "TRANSFORM3D"; + case "Projection": return "PROJECTION"; + + // Miscellaneous types. + case "Color": return "COLOR"; + case "RID": return "RID"; + case "Object": return "OBJECT"; + case "Callable": return "CALLABLE"; + case "Signal": return "SIGNAL"; + case "StringName": return "STRING_NAME"; + case "NodePath": return "NODE_PATH"; + case "Dictionary": return "DICTIONARY"; + case "Array": return "ARRAY"; + + // Arrays. + case "PackedByteArray": return "PACKED_BYTE_ARRAY"; + case "PackedInt32Array": return "PACKED_INT32_ARRAY"; + case "PackedInt64Array": return "PACKED_INT64_ARRAY"; + case "PackedFloat32Array": return "PACKED_FLOAT32_ARRAY"; + case "PackedFloat64Array": return "PACKED_FLOAT64_ARRAY"; + case "PackedStringArray": return "PACKED_STRING_ARRAY"; + case "PackedVector2Array": return "PACKED_VECTOR2_ARRAY"; + case "PackedVector3Array": return "PACKED_VECTOR3_ARRAY"; + case "PackedColorArray": return "PACKED_COLOR_ARRAY"; + } + + return null; } \ No newline at end of file diff --git a/create-cpp.js b/create-cpp.js index 16ef88a..a2d9a29 100644 --- a/create-cpp.js +++ b/create-cpp.js @@ -3,7 +3,7 @@ const path = require( "path" ); const { loadJSON, getFiles, saveUTF8, getMatches, loadUTF8, insertText } = require( "./library.js" ); const { CppClassMember } = require( "./cpp-class-member.js" ); -function createCppHeader( className, extendingClassName, headerDefine, protectedMembers, publicMembers ) +function createCppHeader( className, extendingClassName, headerDefine, protectedMembers, publicMembers, includes ) { let cppHeader = @@ -14,6 +14,7 @@ let cppHeader = #ifndef ${headerDefine} #define ${headerDefine} +${includes} #include "./${extendingClassName}.h" @@ -92,6 +93,8 @@ function createIncludes( className ) async function main() { let files = await getFiles( definitionsPath ); + files = files.filter( f => ! f.startsWith( "_" ) ); + let typesFile = await loadUTF8( registerTypesPath ); let types = getRegistratedTypes( typesFile ); @@ -185,7 +188,7 @@ function getHeaderDefine( className ) className = output.join( "" ); - return "ROKOJORI_CORE__" + className + "_H"; + return "ROKOJORI__" + className + "_H"; } function getRegistratedTypes( text ) @@ -209,7 +212,11 @@ async function createCppFiles( definitionPath, types, missingTypes ) { console.log( "Creating: ", definitionPath ); - let data = await loadJSON( path.join( definitionsPath, definitionPath ) ); + let jsonPath = path.join( definitionsPath, definitionPath ); + + let data = await loadJSON( jsonPath ); + + //console.log( "data:", jsonPath, data ); let classNameResult = /(\w+)(?:\:(\w+))?/.exec( data.class ); @@ -229,7 +236,14 @@ async function createCppFiles( definitionPath, types, missingTypes ) let bindings = protectedBindings.concat( publicBindings ).join( "\n " ); - let header = createCppHeader( className, extendingClass, headerDefine, protectedHeader, publicHeader ); + let includes = ""; + + if ( data.includes ) + { + includes = data.includes.map( inc => `#include "${inc}"` ); + } + + let header = createCppHeader( className, extendingClass, headerDefine, protectedHeader, publicHeader, includes ); let implementation = createCppImplementation( className, bindings ); //console.log( header ); diff --git a/rokojori-action-library b/rokojori-action-library index 26aea1a..d6b9687 160000 --- a/rokojori-action-library +++ b/rokojori-action-library @@ -1 +1 @@ -Subproject commit 26aea1a20d5bc2e35486517e2849b02f3b5d585b +Subproject commit d6b968703d75749c4f7ded3abe5ec9beba97ae8d diff --git a/rokojori-action-library-definitions/RJSequenceAction.json b/rokojori-action-library-definitions/RJSequenceAction.json deleted file mode 100644 index d098989..0000000 --- a/rokojori-action-library-definitions/RJSequenceAction.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "class":"RJSequenceAction:RJAction", - - "public": - { - "virtual dispatchStartEvent()":{}, - "virtual dispatchCancelEvent()":{}, - "virtual dispatchEndEvent()":{} - } -} \ No newline at end of file diff --git a/rokojori-action-library-definitions/_RJSequenceAction.json b/rokojori-action-library-definitions/_RJSequenceAction.json new file mode 100644 index 0000000..1684aed --- /dev/null +++ b/rokojori-action-library-definitions/_RJSequenceAction.json @@ -0,0 +1,11 @@ +{ + "class":"RJSequenceAction:RJActions", + + "public": + { + "virtual dispatchStart()" : { "type":"int" }, + "virtual dispatchCancel()" : { "parameters":[ { "id":"int" } ] }, + "virtual dispatchEnd()" : { "parameters":[ { "id":"int" } ] }, + "signal onSequenceDone()" : { "parameters":[ { "id":"int" } ] } + } +} \ No newline at end of file