Skip to content

Commit

Permalink
Allow getting/setting draw position from script
Browse files Browse the repository at this point in the history
  • Loading branch information
dsrw committed Dec 7, 2023
1 parent 5118a40 commit d25b433
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/controllers/script_controllers/host_bridge.nim
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ proc `color=`(self: Unit, color: Colors) =

proc show(self: Unit): bool =
Visible in assert_present(self).global_flags

proc `show=`(self: Unit, value: bool) =
assert_present(self)
if value:
Expand Down Expand Up @@ -401,6 +401,16 @@ proc `drawing=`(self: Build, drawing: bool) =
proc initial_position(self: Build): Vector3 =
self.initial_position

proc draw_position(self: Build): Vector3 =
self.position + self.draw_transform.origin

proc draw_position_set(self: Build, position: Vector3) =
if Global in self.global_flags:
self.draw_transform_value.origin = position - self.position
else:
self.draw_transform_value.origin =
(position - self.position).local_to(self.parent)

proc save(self: Build, name: string) =
self.save_points[name] =
(self.draw_transform, self.color_value.value, self.drawing)
Expand Down Expand Up @@ -532,7 +542,8 @@ proc bridge_to_vm*(worker: Worker) =
play, all_bots

result.bridged_from_vm "builds",
drawing, `drawing=`, initial_position, save, restore, all_builds
drawing, `drawing=`, initial_position, save, restore, all_builds,
draw_position, draw_position_set

result.bridged_from_vm "signs",
message, `message=`, more, `more=`, height, `height=`, width, `width=`,
Expand Down
5 changes: 5 additions & 0 deletions vmlib/enu/builds.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ bridged_to_host:
proc all_builds(): seq[Build]
proc save*(self: Build, name = "default")
proc restore*(self: Build, name = "default")
proc draw_position*(self: Build): Vector3
proc `draw_position=`*(self: Build, value: Vector3)

proc `draw_position=`*(self: Build, unit: Unit) =
self.draw_position = unit.position

proc all*(_: type Build): seq[Build] = all_builds()

Expand Down
4 changes: 2 additions & 2 deletions vmlib/enu/class_macros.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import types
import base_api, macro_helpers

const me_props = ["seed", "global", "lock"]
const target_props = ["position", "start_position", "speed", "scale", "glow",
"global", "seed", "color", "height", "show", "sign"]
const target_props = ["position", "start_position", "draw_position", "speed",
"scale", "glow", "global", "seed", "color", "height", "show", "sign"]

proc params_to_assignments(nodes: seq[NimNode]): NimNode =
result = new_stmt_list()
Expand Down

0 comments on commit d25b433

Please sign in to comment.