From 0f45ae05d0d185f2268ee2c311cbed8c773cdf9a Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Thu, 8 Jun 2023 17:50:05 -0400 Subject: [PATCH] Variants are not structs in the binding, they are classes, so they need a different marshaling code path --- Generator/Generator/Arguments.swift | 3 ++- Generator/Generator/main.swift | 2 +- Sources/SimpleExtension/Demo.swift | 14 +++++++++++++- Testbed/project.godot | 7 +++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Generator/Generator/Arguments.swift b/Generator/Generator/Arguments.swift index dfa283fba..19594b7f4 100644 --- a/Generator/Generator/Arguments.swift +++ b/Generator/Generator/Arguments.swift @@ -30,7 +30,6 @@ func getArgumentDeclaration (_ argument: JGodotArgument, eliminate: String, kind var def: String = "" if let dv = argument.defaultValue, dv != "" { let argumentType = argument.type - // TODO: // - handle creating initializers from enums (builtint) // - empty arrays @@ -48,6 +47,8 @@ func getArgumentDeclaration (_ argument: JGodotArgument, eliminate: String, kind if let ev = mapEnumValue (enumDef: argument.type, value: dv) { def = " = \(ev)" } + } else if argumentType == "Variant" { + // Not supported } else { def = " = \(dv)" } diff --git a/Generator/Generator/main.swift b/Generator/Generator/main.swift index 079c67dec..9a06150d9 100644 --- a/Generator/Generator/main.swift +++ b/Generator/Generator/main.swift @@ -71,7 +71,7 @@ for x in jsonApi.builtinClasses { isStructMap [String (x.name)] = value builtinMap [x.name] = x } -for x in ["Float", "Int", "float", "int", "Variant", "Int32", "Bool", "bool"] { +for x in ["Float", "Int", "float", "int", "Int32", "Bool", "bool"] { isStructMap [x] = true } diff --git a/Sources/SimpleExtension/Demo.swift b/Sources/SimpleExtension/Demo.swift index b4356910b..9005276fd 100644 --- a/Sources/SimpleExtension/Demo.swift +++ b/Sources/SimpleExtension/Demo.swift @@ -78,7 +78,19 @@ class SwiftSprite: Sprite2D { override func _process (delta: Double) { time_passed += delta - + + let imageVariant = ProjectSettings.shared.getSetting(name: "shader_globals/heightmap", defaultValue: Variant(-1)) + GD.print("Found this value IMAGE: \(imageVariant.gtype) variant: \(imageVariant) desc: \(imageVariant.description)") + + let dict2: Dictionary? = SwiftGodot.Dictionary(imageVariant) + GD.print("dictionary2: \(dict2) \(dict2?["type"]) \(dict2?["value"])") + + // part b + if let result = dict2?.get(key: Variant("type"), default: Variant(-1)) { + let value = String(result) + GD.print("2 Found this value \(value)") + } + SwiftSprite.lerp (from: 0.1, to: 10, weight: 1) var newPos = Vector2(x: Float (10 + (10 * sin(time_passed * 2.0))), y: Float (10.0 + (10.0 * cos(time_passed * 1.5)))) diff --git a/Testbed/project.godot b/Testbed/project.godot index cd174d2fc..24ef00fc2 100644 --- a/Testbed/project.godot +++ b/Testbed/project.godot @@ -22,3 +22,10 @@ paths=["res://example.gdextension"] [rendering] environment/defaults/default_environment="res://default_env.tres" + +[shader_globals] + +heightmap={ +"type": "sampler2D", +"value": "res://heightmap.png" +}