Skip to content

Commit

Permalink
Variants are not structs in the binding, they are classes, so they ne…
Browse files Browse the repository at this point in the history
…ed a different marshaling code path
  • Loading branch information
migueldeicaza committed Jun 8, 2023
1 parent 85fc24a commit 0f45ae0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Generator/Generator/Arguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)"
}
Expand Down
2 changes: 1 addition & 1 deletion Generator/Generator/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
14 changes: 13 additions & 1 deletion Sources/SimpleExtension/Demo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down
7 changes: 7 additions & 0 deletions Testbed/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 0f45ae0

Please sign in to comment.