Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Marge fixes from question
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremi360 committed Jul 7, 2019
1 parent 33b09b6 commit 2301208
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 22 deletions.
17 changes: 9 additions & 8 deletions addons/Rakugo/lib/jump.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@ func invoke(
id_of_scene:String,
node_name:String,
dialog_name:String,
change := true,
state := 0
state := 0,
force_reload := false
) ->void :

var r = Rakugo
var scenes_links = load(r.scenes_links).get_as_dict()
var path = r.current_scene
r.current_node_name = node_name
r.current_dialog_name = dialog_name
r.story_state = state
r.current_scene = id_of_scene

r.debug(["jump to scene:", r.current_scene, "with dialog:", dialog_name, "from:", r.story_state])

if change:
if r.current_root_node != null:
r.current_root_node.queue_free()
if scenes_links.has(id_of_scene):
path = scenes_links[id_of_scene].resource_path

var path = r.current_scene
if (r.current_scene_path != path) or force_reload:
r.current_scene = path

if scenes_links.has(id_of_scene):
path = scenes_links[id_of_scene].resource_path
if r.current_root_node != null:
r.current_root_node.queue_free()

var lscene = load(path)
r.current_root_node = lscene.instance()
Expand Down
3 changes: 2 additions & 1 deletion addons/Rakugo/lib/load_file.gd
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func invoke(save_folder: String, save_name: String, variables: Dictionary):
save.scene,
save.node_name,
save.dialog_name,
true, save.story_state
save.story_state,
true
)

r.history_id = save.history_id
Expand Down
10 changes: 6 additions & 4 deletions addons/Rakugo/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ var current_scene:= ""
# {["scene_id", "node_name", "dialog_name", story_step]:{"type":type, "parameters": parameters}}
var history:= {}
var global_history:= {}

var variables:= {}

# don't save this
onready var menu_node:RakugoMenu = $Menu
var current_scene_path: = ""
var current_root_node:Node = null
var current_statement:Statement = null
var skip_auto:= false
Expand Down Expand Up @@ -736,13 +736,13 @@ func _get_history_id() -> int:
## id_of_current_scene is id to scene defined in scenes_links or full path to scene
func jump(
id_of_scene:String, node_name:String,
dialog_name:String, change:= true, state := 0
dialog_name:String, state := 0
) -> void:

$Jump.invoke(
id_of_scene,
node_name, dialog_name,
change, state
state
)

## use this to assign beginning scene and dialog
Expand All @@ -752,7 +752,9 @@ func on_begin(path_to_current_scene:String, node_name:String, dialog_name:String
if loading_in_progress:
return

jump(path_to_current_scene, node_name , dialog_name, false)
var resource = load(scenes_links).get_as_dict()
current_scene_path = resource[path_to_current_scene].resource_path
jump(path_to_current_scene, node_name , dialog_name)

func can_go_back():
return is_save_exits("back")
Expand Down
19 changes: 12 additions & 7 deletions addons/Rakugo/nodes/gdscript_dialog.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends RootNode
extends Node
class_name GDScriptDialog

export (Array, String) var begin_from = ["", ""]
Expand All @@ -24,19 +24,24 @@ func check_dialog(node_name, dialog_name, check_for) -> bool:
if node_name != name:
result = false

var real_name = name
if name.begins_with("@"):
var real_name = name.split("@", false)[0]
real_name = name.split("@", false)[0]

if node_name != real_name:
result = false
if node_name != real_name:
result = false

else:
result = true
else:
result = true

if dialog_name != check_for:
result = false

Rakugo.debug(["check_dialog:", result, "(", name, node_name, "), (", dialog_name, check_for, ")"])
Rakugo.debug([
"check_dialog:", result,
"(",'"'+name +'"', '"'+node_name+'"', '"'+real_name+'"', ")",
"(", '"'+dialog_name+'"', '"'+check_for+'"', ")"
])
return result

func define(var_name:String, value = null, save_included := true) -> RakugoVar:
Expand Down
120 changes: 120 additions & 0 deletions addons/Rakugo/nodes/rakugo_spatial.gd
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
2 changes: 1 addition & 1 deletion addons/Rakugo/nodes/root_node.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extends Node
class_name RootNode

export var root = false
export var root = true

func _ready() -> void:
if Rakugo.current_root_node != self and root:
Expand Down
2 changes: 1 addition & 1 deletion addons/Rakugo/statements/menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func on_exit(_type : int, new_parameters : Dictionary = {}) -> void:

if "final_choice" in parameters:
var dialog_name : String = parameters.choices.values()[parameters.final_choice]
Rakugo.jump(Rakugo.current_scene, Rakugo.current_node_name, dialog_name, false)
Rakugo.jump(Rakugo.current_scene, Rakugo.current_node_name, dialog_name)

else:
print("no final_choice recived")
Expand Down

0 comments on commit 2301208

Please sign in to comment.