This repository has been archived by the owner on Nov 17, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
151 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
tool | ||
extends Spatial | ||
class_name RakugoSpatial, "res://addons/Rakugo/icons/rakugo_spatial.svg" | ||
|
||
signal on_substate(substate) | ||
|
||
var rnode : = RakugoNodeCore.new() | ||
|
||
export var node_id : = "" | ||
export var camera : = NodePath("") | ||
export (Array, String) var state : Array setget _set_state, _get_state | ||
|
||
var _state : Array | ||
var node_link:NodeLink | ||
var last_show_args:Dictionary | ||
|
||
func _ready() -> void: | ||
if(Engine.editor_hint): | ||
if node_id.empty(): | ||
node_id = name | ||
|
||
add_to_group("save", true) | ||
return | ||
|
||
Rakugo.connect("show", self, "_on_show") | ||
Rakugo.connect("hide", self, "_on_hide") | ||
rnode.connect("on_substate", self, "_on_rnode_substate") | ||
|
||
if node_id.empty(): | ||
node_id = name | ||
|
||
node_link = Rakugo.get_node_link(node_id) | ||
|
||
if not node_link: | ||
node_link = Rakugo.node_link(node_id, get_path()) | ||
|
||
else: | ||
node_link.node_path = get_path() | ||
|
||
add_to_group("save", true) | ||
|
||
func _on_rnode_substate(substate): | ||
emit_signal("on_substate", substate) | ||
|
||
func _on_show(node_id : String, state_value : Array, show_args : Dictionary) -> void: | ||
if self.node_id != node_id: | ||
return | ||
|
||
var cam_pos = Vector2(0, 0) | ||
|
||
if !camera.is_empty(): | ||
if 'x' in show_args: | ||
cam_pos.x = get_node(camera).project_position(Vector2(show_args.x,0)) | ||
|
||
if 'y' in show_args: | ||
cam_pos.y = get_node(camera).project_position(Vector2(show_args.y,0)) | ||
|
||
var def_pos = Vector2(translation.x , translation.y) | ||
var pos = rnode.show_at(cam_pos, show_args, def_pos) | ||
|
||
var z = translation.z | ||
|
||
if z in show_args: | ||
z = show_args.z | ||
|
||
translation = Vector3(pos.x, pos.y, z) | ||
|
||
_set_state(state_value) | ||
|
||
if not self.visible: | ||
show() | ||
|
||
func _set_state(value : Array) -> void: | ||
_state = value | ||
|
||
if not value: | ||
return | ||
|
||
if not rnode: | ||
return | ||
|
||
if not Engine.editor_hint: | ||
_state = rnode.setup_state(value) | ||
|
||
func _get_state() -> Array: | ||
return _state | ||
|
||
func _on_hide(_node_id : String) -> void: | ||
if _node_id != node_id: | ||
return | ||
|
||
hide() | ||
|
||
func _exit_tree() -> void: | ||
if(Engine.editor_hint): | ||
remove_from_group("save") | ||
return | ||
|
||
var id = NodeLink.new("").var_prefix + node_id | ||
Rakugo.variables.erase(id) | ||
|
||
func on_save() -> void: | ||
node_link.value["visible"] = visible | ||
node_link.value["state"] = _state | ||
node_link.value["show_args"] = last_show_args | ||
|
||
func on_load(game_version:String) -> void: | ||
node_link = Rakugo.get_node_link(node_id) | ||
visible = node_link.value["visible"] | ||
|
||
if visible: | ||
_state = node_link.value["state"] | ||
last_show_args = node_link.value["show_args"] | ||
_on_show(node_id, _state, last_show_args) | ||
|
||
else: | ||
_on_hide(node_id) | ||
|
||
func _on_substate(substate): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters