Skip to content

Commit

Permalink
Another API change: Dictionary was ambiguous and just happens too muc…
Browse files Browse the repository at this point in the history
…h in Swift code, so it has been remapped to GDictionary
  • Loading branch information
migueldeicaza committed Sep 23, 2023
1 parent 38c5f65 commit 4edb7b0
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Generator/Generator/Arguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func getArgumentDeclaration (_ argument: JGodotArgument, eliminate: String, kind
}
} else if argumentType == "Dictionary" {
if dv == "{}" {
def = " = SwiftGodot.Dictionary ()"
def = " = GDictionary ()"
} else {
print ("Generator: \(argumentType) missing support for default value: \(dv)")
}
Expand Down
8 changes: 4 additions & 4 deletions Generator/Generator/BuiltinGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ func generateBuiltinMethods (_ p: Printer,
p ("get") {
p ("var keyCopy = key")
p ("var result = Variant.zero")
p ("if Dictionary.keyed_checker (&content, &keyCopy.content) != 0") {
p ("Dictionary.keyed_getter (&content, &keyCopy.content, &result)")
p ("if GDictionary.keyed_checker (&content, &keyCopy.content) != 0") {
p ("GDictionary.keyed_getter (&content, &keyCopy.content, &result)")
p ("return Variant (fromContent: result)")
}
p ("else") {
Expand All @@ -390,10 +390,10 @@ func generateBuiltinMethods (_ p: Printer,
p ("set") {
p ("var keyCopy = key")
p ("if var newCopy = newValue") {
p ("Dictionary.keyed_setter (&content, &keyCopy.content, &newCopy.content)")
p ("GDictionary.keyed_setter (&content, &keyCopy.content, &newCopy.content)")
}
p ("else") {
p ("Dictionary.keyed_setter (&content, &keyCopy.content, nil)")
p ("GDictionary.keyed_setter (&content, &keyCopy.content, nil)")
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Generator/Generator/ClassGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func makeDefaultInit (godotType: String, initCollection: String = "") -> String
return "String ()"
case "Array":
return "GArray ()"
case "Dictionary":
return "GDictionary ()"
case let t where t.starts (with: "typedarray::"):
let nestedTypeName = String (t.dropFirst(12))
let simple = SimpleType(type: nestedTypeName)
Expand Down
8 changes: 8 additions & 0 deletions Generator/Generator/TypeHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ func mapTypeName (_ name: String) -> String {
if name == "Array" {
return "GArray"
}
if name == "Dictionary" {
return "GDictionary"
}
return name
}
func mapTypeNameDoc (_ name: String) -> String {
Expand All @@ -152,6 +155,9 @@ func mapTypeNameDoc (_ name: String) -> String {
if name == "Type" {
return "GType"
}
if name == "Dictionary" {
return "GDictionary"
}
return mapTypeName (name)
}

Expand Down Expand Up @@ -290,6 +296,8 @@ func getGodotType (_ t: TypeWithMeta?, kind: ArgumentKind = .classes) -> String
} else {
return "GString"
}
case "Dictionary":
return "GDictionary"
case "Array":
return "GArray"
case "void*":
Expand Down
2 changes: 1 addition & 1 deletion Sources/SimpleExtension/Demo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SwiftSprite: Sprite2D {
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)
let dict2: GDictionary? = GDictionary(imageVariant)
GD.print("dictionary2: \(dict2) \(dict2?["type"]) \(dict2?["value"])")

// part b
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MainLevel: Node2D {
self.spawnpoint = getNodeOrNull(path: "Spawnpoint") as? Node2D

teleportArea?.bodyEntered.connect { [self] enteredBody in
if enteredBody.isClass(class: "\(PlayerController.self)") {
if enteredBody.isClass("\(PlayerController.self)") {
teleportPlayerToTop()
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftGodot/SwiftGodot.docc/Variants.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ You can create Variants from the following structures and types:

* Swift's Bool, Int, Int64, Strings and Floats
* Godot's GString, Vector, Rect, Transform, Plane, Quaternion, AABB, Basis,
Projection, NodePaths, RIDs, Callable, Dictionary, Array and PackedArrays.
Projection, NodePaths, RIDs, Callable, GDictionary, Array and PackedArrays.
* Godot's objects

You wrap your data type by calling one of the ``Variant`` constructors, and then
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftGodot/Variant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public class Variant: Hashable, Equatable, ExpressibleByStringLiteral {
Variant.fromTypeMap [GType.signal.rawValue] (&content, &value.content)
}

public init (_ value: Dictionary) {
public init (_ value: GDictionary) {
Variant.fromTypeMap [GType.dictionary.rawValue] (&content, &value.content)
}

Expand Down

0 comments on commit 4edb7b0

Please sign in to comment.