Fix circular imports
This commit is contained in:
parent
3b8b12833a
commit
fb8c42a2cc
4 changed files with 106 additions and 77 deletions
|
|
@ -23,7 +23,7 @@ proc newArray*(arr: GodotArray): Array {.inline.} =
|
|||
new(result, arrayFinalizer)
|
||||
result.godotArray = arr
|
||||
|
||||
import poolarrays, variants
|
||||
import poolarrays
|
||||
|
||||
proc newArray*(pca: PoolColorArray): Array {.inline.} =
|
||||
new(result, arrayFinalizer)
|
||||
|
|
@ -127,10 +127,10 @@ proc len*(self: Array): int {.inline.} =
|
|||
proc sort*(self: var Array) {.inline.} =
|
||||
self.godotArray.sort()
|
||||
|
||||
iterator items*(arr: Array): Variant {.inline.} =
|
||||
iterator items*(arr: Array): Variant =
|
||||
for i in 0..<arr.len:
|
||||
yield arr[i]
|
||||
|
||||
iterator pairs*(arr: Array): tuple[key: int, val: Variant] {.inline.} =
|
||||
iterator pairs*(arr: Array): tuple[key: int, val: Variant] =
|
||||
for i in 0..<arr.len:
|
||||
yield (i, arr[i])
|
||||
|
|
|
|||
|
|
@ -35,6 +35,13 @@ proc clear*(self: var Dictionary) {.inline.} =
|
|||
|
||||
import variants, arrays
|
||||
|
||||
proc newVariant*(dict: Dictionary): Variant {.inline.} =
|
||||
new(result, variantFinalizer)
|
||||
initGodotVariant(result.godotVariant[], dict.godotDictionary)
|
||||
|
||||
proc asDictionary*(self: Variant): Dictionary {.inline.} =
|
||||
newDictionary(self.godotVariant[].asGodotDictionary)
|
||||
|
||||
proc contains*(self: Dictionary; key: Variant): bool {.inline.}=
|
||||
self.godotDictionary.contains(key.godotVariant[])
|
||||
|
||||
|
|
@ -47,8 +54,6 @@ proc del*(self: var Dictionary; key: Variant) {.inline.} =
|
|||
proc hash*(self: Dictionary): Hash {.inline.} =
|
||||
hash(self.godotDictionary.godotHash())
|
||||
|
||||
import arrays, variants
|
||||
|
||||
proc keys*(self: Dictionary): Array {.inline.} =
|
||||
newArray(self.godotDictionary.keys())
|
||||
|
||||
|
|
@ -79,16 +84,16 @@ proc toJson*(self: Dictionary): string {.inline.} =
|
|||
result = $s
|
||||
s.deinit()
|
||||
|
||||
iterator keys*(dict: Dictionary): Variant {.inline.} =
|
||||
iterator keys*(dict: Dictionary): Variant =
|
||||
let keyArr = dict.keys()
|
||||
for key in keyArr:
|
||||
yield key
|
||||
|
||||
iterator values*(dict: Dictionary): Variant {.inline.} =
|
||||
iterator values*(dict: Dictionary): Variant =
|
||||
let valArr = dict.values()
|
||||
for val in valArr:
|
||||
yield val
|
||||
|
||||
iterator pairs*(dict: Dictionary): tuple[key, val: Variant] {.inline.} =
|
||||
iterator pairs*(dict: Dictionary): tuple[key, val: Variant] =
|
||||
for key in keys(dict):
|
||||
yield (key, dict[key])
|
||||
|
|
|
|||
|
|
@ -3,68 +3,69 @@
|
|||
import vector2, vector3, colors
|
||||
import internal.godotpoolarrays, internal.godotstrings
|
||||
|
||||
type
|
||||
PoolByteArray* = ref object
|
||||
godotPoolByteArray: GodotPoolByteArray
|
||||
PoolIntArray* = ref object
|
||||
godotPoolIntArray: GodotPoolIntArray
|
||||
PoolRealArray* = ref object
|
||||
godotPoolRealArray: GodotPoolRealArray
|
||||
PoolVector2Array* = ref object
|
||||
godotPoolVector2Array: GodotPoolVector2Array
|
||||
PoolVector3Array* = ref object
|
||||
godotPoolVector3Array: GodotPoolVector3Array
|
||||
PoolColorArray* = ref object
|
||||
godotPoolColorArray: GodotPoolColorArray
|
||||
PoolStringArray* = ref object
|
||||
godotPoolStringArray: GodotPoolStringArray
|
||||
# type
|
||||
# PoolByteArray* = ref object
|
||||
# godotPoolByteArray: GodotPoolByteArray
|
||||
# PoolIntArray* = ref object
|
||||
# godotPoolIntArray: GodotPoolIntArray
|
||||
# PoolRealArray* = ref object
|
||||
# godotPoolRealArray: GodotPoolRealArray
|
||||
# PoolVector2Array* = ref object
|
||||
# godotPoolVector2Array: GodotPoolVector2Array
|
||||
# PoolVector3Array* = ref object
|
||||
# godotPoolVector3Array: GodotPoolVector3Array
|
||||
# PoolColorArray* = ref object
|
||||
# godotPoolColorArray: GodotPoolColorArray
|
||||
# PoolStringArray* = ref object
|
||||
# godotPoolStringArray: GodotPoolStringArray
|
||||
|
||||
proc godotPoolByteArray*(self: PoolByteArray):
|
||||
ptr GodotPoolByteArray {.inline.} =
|
||||
## WARNING: do not keep the returned value for longer than the lifetime of
|
||||
## the array.
|
||||
addr self.godotPoolByteArray
|
||||
# proc godotPoolByteArray*(self: PoolByteArray):
|
||||
# ptr GodotPoolByteArray {.inline.} =
|
||||
# ## WARNING: do not keep the returned value for longer than the lifetime of
|
||||
# ## the array.
|
||||
# addr self.godotPoolByteArray
|
||||
|
||||
proc godotPoolIntArray*(self: PoolIntArray):
|
||||
ptr GodotPoolIntArray {.inline.} =
|
||||
## WARNING: do not keep the returned value for longer than the lifetime of
|
||||
## the array.
|
||||
addr self.godotPoolIntArray
|
||||
# proc godotPoolIntArray*(self: PoolIntArray):
|
||||
# ptr GodotPoolIntArray {.inline.} =
|
||||
# ## WARNING: do not keep the returned value for longer than the lifetime of
|
||||
# ## the array.
|
||||
# addr self.godotPoolIntArray
|
||||
|
||||
proc godotPoolRealArray*(self: PoolRealArray):
|
||||
ptr GodotPoolRealArray {.inline.} =
|
||||
## WARNING: do not keep the returned value for longer than the lifetime of
|
||||
## the array.
|
||||
addr self.godotPoolRealArray
|
||||
# proc godotPoolRealArray*(self: PoolRealArray):
|
||||
# ptr GodotPoolRealArray {.inline.} =
|
||||
# ## WARNING: do not keep the returned value for longer than the lifetime of
|
||||
# ## the array.
|
||||
# addr self.godotPoolRealArray
|
||||
|
||||
proc godotPoolVector2Array*(self: PoolVector2Array):
|
||||
ptr GodotPoolVector2Array {.inline.} =
|
||||
## WARNING: do not keep the returned value for longer than the lifetime of
|
||||
## the array.
|
||||
addr self.godotPoolVector2Array
|
||||
# proc godotPoolVector2Array*(self: PoolVector2Array):
|
||||
# ptr GodotPoolVector2Array {.inline.} =
|
||||
# ## WARNING: do not keep the returned value for longer than the lifetime of
|
||||
# ## the array.
|
||||
# addr self.godotPoolVector2Array
|
||||
|
||||
proc godotPoolVector3Array*(self: PoolVector3Array):
|
||||
ptr GodotPoolVector3Array {.inline.} =
|
||||
## WARNING: do not keep the returned value for longer than the lifetime of
|
||||
## the array.
|
||||
addr self.godotPoolVector3Array
|
||||
# proc godotPoolVector3Array*(self: PoolVector3Array):
|
||||
# ptr GodotPoolVector3Array {.inline.} =
|
||||
# ## WARNING: do not keep the returned value for longer than the lifetime of
|
||||
# ## the array.
|
||||
# addr self.godotPoolVector3Array
|
||||
|
||||
proc godotPoolColorArray*(self: PoolColorArray):
|
||||
ptr GodotPoolColorArray {.inline.} =
|
||||
## WARNING: do not keep the returned value for longer than the lifetime of
|
||||
## the array.
|
||||
addr self.godotPoolColorArray
|
||||
# proc godotPoolColorArray*(self: PoolColorArray):
|
||||
# ptr GodotPoolColorArray {.inline.} =
|
||||
# ## WARNING: do not keep the returned value for longer than the lifetime of
|
||||
# ## the array.
|
||||
# addr self.godotPoolColorArray
|
||||
|
||||
proc godotPoolStringArray*(self: PoolStringArray):
|
||||
ptr GodotPoolStringArray {.inline.} =
|
||||
## WARNING: do not keep the returned value for longer than the lifetime of
|
||||
## the array.
|
||||
addr self.godotPoolStringArray
|
||||
# proc godotPoolStringArray*(self: PoolStringArray):
|
||||
# ptr GodotPoolStringArray {.inline.} =
|
||||
# ## WARNING: do not keep the returned value for longer than the lifetime of
|
||||
# ## the array.
|
||||
# addr self.godotPoolStringArray
|
||||
|
||||
import godotbase, arrays
|
||||
|
||||
template definePoolArray(T, GodotT, DataT, fieldName, newProcName, initProcName;
|
||||
noData = false) =
|
||||
template definePoolArrayBase(T, GodotT, DataT, fieldName, newProcName,
|
||||
initProcName) =
|
||||
type
|
||||
T* = ref object
|
||||
fieldName: GodotT
|
||||
|
||||
proc poolArrayFinalizer(arr: T) =
|
||||
arr.fieldName.deinit()
|
||||
|
|
@ -73,14 +74,22 @@ template definePoolArray(T, GodotT, DataT, fieldName, newProcName, initProcName;
|
|||
new(result, poolArrayFinalizer)
|
||||
initProcName(result.fieldName)
|
||||
|
||||
proc newProcName*(arr: Array): T {.inline.} =
|
||||
new(result, poolArrayFinalizer)
|
||||
initProcName(result.fieldName, arr.godotArray[])
|
||||
proc fieldName*(self: T): ptr GodotT {.inline.} =
|
||||
## WARNING: do not keep the returned value for longer than the lifetime of
|
||||
## the array.
|
||||
addr self.fieldName
|
||||
|
||||
proc newProcName*(arr: GodotT): T {.inline.} =
|
||||
new(result, poolArrayFinalizer)
|
||||
result.fieldName = arr
|
||||
|
||||
template definePoolArray(T, GodotT, DataT, fieldName, newProcName, initProcName;
|
||||
noData = false) =
|
||||
|
||||
proc newProcName*(arr: Array): T {.inline.} =
|
||||
new(result, poolArrayFinalizer)
|
||||
initProcName(result.fieldName, arr.godotArray[])
|
||||
|
||||
proc add*(self: var T; arr: T) {.inline.} =
|
||||
self.fieldName.add(arr.fieldName)
|
||||
|
||||
|
|
@ -120,6 +129,30 @@ template definePoolArray(T, GodotT, DataT, fieldName, newProcName, initProcName;
|
|||
for i in 0..<arr.len:
|
||||
yield (i, arr[i])
|
||||
|
||||
definePoolArrayBase(PoolByteArray, GodotPoolByteArray, uint8,
|
||||
godotPoolByteArray, newPoolByteArray,
|
||||
initGodotPoolByteArray)
|
||||
definePoolArrayBase(PoolIntArray, GodotPoolIntArray, cint,
|
||||
godotPoolIntArray, newPoolIntArray,
|
||||
initGodotPoolIntArray)
|
||||
definePoolArrayBase(PoolRealArray, GodotPoolRealArray, float64,
|
||||
godotPoolRealArray, newPoolRealArray,
|
||||
initGodotPoolRealArray)
|
||||
definePoolArrayBase(PoolVector2Array, GodotPoolVector2Array, Vector2,
|
||||
godotPoolVector2Array, newPoolVector2Array,
|
||||
initGodotPoolVector2Array)
|
||||
definePoolArrayBase(PoolVector3Array, GodotPoolVector3Array, Vector3,
|
||||
godotPoolVector3Array, newPoolVector3Array,
|
||||
initGodotPoolVector3Array)
|
||||
definePoolArrayBase(PoolColorArray, GodotPoolColorArray, Color,
|
||||
godotPoolColorArray, newPoolColorArray,
|
||||
initGodotPoolColorArray)
|
||||
definePoolArrayBase(PoolStringArray, GodotPoolStringArray, string,
|
||||
godotPoolStringArray, newPoolStringArray,
|
||||
initGodotPoolStringArray)
|
||||
|
||||
import godotbase, arrays
|
||||
|
||||
definePoolArray(PoolByteArray, GodotPoolByteArray, uint8,
|
||||
godotPoolByteArray, newPoolByteArray,
|
||||
initGodotPoolByteArray)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ proc godotVariant*(v: Variant): ptr GodotVariant {.inline.} =
|
|||
proc getType*(v: Variant): VariantType =
|
||||
v.godotVariant.getType()
|
||||
|
||||
proc variantFinalizer(v: Variant) =
|
||||
proc variantFinalizer*(v: Variant) =
|
||||
if not v.noDeinit:
|
||||
v.godotVariant.deinit()
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ proc newVariant*(s: string): Variant {.inline.} =
|
|||
godotStr.deinit()
|
||||
|
||||
import basis, nodepaths
|
||||
import planes, poolarrays, quats, rect2, rect3, rids
|
||||
import planes, quats, rect2, rect3, rids
|
||||
import transforms, transform2d, vector2
|
||||
import vector3, colors
|
||||
|
||||
|
|
@ -135,7 +135,7 @@ proc newVariant*(obj: ptr GodotObject): Variant {.inline.} =
|
|||
new(result, variantFinalizer)
|
||||
initGodotVariant(result.godotVariant, obj)
|
||||
|
||||
import arrays
|
||||
import arrays, poolarrays
|
||||
|
||||
proc newVariant*(arr: Array): Variant {.inline.} =
|
||||
new(result, variantFinalizer)
|
||||
|
|
@ -163,12 +163,6 @@ proc newVariant*(pv3a: PoolVector3Array): Variant {.inline.} =
|
|||
proc newVariant*(pca: PoolColorArray): Variant {.inline.} =
|
||||
initGodotVariant(result.godotVariant, pca.godotPoolColorArray[])
|
||||
|
||||
import dictionaries
|
||||
|
||||
proc newVariant*(dict: Dictionary): Variant {.inline.} =
|
||||
new(result, variantFinalizer)
|
||||
initGodotVariant(result.godotVariant, dict.godotDictionary[])
|
||||
|
||||
proc asBool*(self: Variant): bool {.inline.} =
|
||||
self.godotVariant.asBool()
|
||||
|
||||
|
|
@ -249,9 +243,6 @@ proc asPoolVector3Array*(self: Variant): PoolVector3Array =
|
|||
proc asPoolColorArray*(self: Variant): PoolColorArray =
|
||||
newPoolColorArray(self.godotVariant.asGodotPoolColorArray())
|
||||
|
||||
proc asDictionary*(self: Variant): Dictionary {.inline.} =
|
||||
newDictionary(self.godotVariant.asGodotDictionary)
|
||||
|
||||
proc hasMethod*(self: Variant; meth: string): bool =
|
||||
var s = meth.toGodotString()
|
||||
result = self.godotVariant.hasMethod(s)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue