-
-
Notifications
You must be signed in to change notification settings - Fork 7
Rakugo Singleton
extends Node
const file_path = "res://Timeline.rk"
func _ready():
Rakugo.parser_add_regex_at_runtime("HW", "^hello_world$")
Rakugo.connect("parser_unhandled_regex", self, "_on_parser_unhandled_regex")
Rakugo.connect("say", self, "_on_say")
Rakugo.connect("step", self, "_on_step")
Rakugo.connect("ask", self, "_on_ask")
Rakugo.connect("menu", self, "_on_menu")
Rakugo.parse_and_execute_script(file_path)
func _on_say(character:Dictionary, text:String):
prints("say", character.get("name", "null"), text)
func _on_step():
prints("Press 'Enter' to continue...")
func _on_ask(character:Dictionary, question:String, default_answer:String):
prints("ask", character.get("name", "null"), question, default_answer)
func _on_menu(choices:Array):
prints("menu", choices)
func _on_parser_unhandled_regex(key:String, result:RegExMatch):
match(key):
"HW":
prints("regex hello, world !")
func _process(delta):
if Rakugo.is_waiting_step() and Input.is_action_just_pressed("ui_accept"):
Rakugo.do_step()
if Rakugo.is_waiting_ask_return() and Input.is_action_just_pressed("ui_up"):
Rakugo.ask_return("Bob")
if Rakugo.is_waiting_menu_return() and Input.is_action_just_pressed("ui_down"):
Rakugo.menu_return(0)
send when a Say instruction is executed.
send after a Say instruction is executed.
Rakugo script reading process is stop, and expects call of do_step.
send when a Ask instruction is executed.
Rakugo script reading process is stop, and expects call of ask_return.
send when a Menu instruction is executed.
Rakugo script reading process is stop, and expects call of menu_return.
#set or create a global variable
Rakugo.set_variable("life", 5)
#set or create a variable on character
Rakugo.set_variable("Sy.life", 5)
#get a global variable
var life = Rakugo.get_variable("life")
#get a character's variable
var sy_life = Rakugo.get_variable("Sy.life")
Only works with global variable.
# define/create a new character
Rakugo.define_character("Sy", "Sylvie")
Returns character with name defined in Project Settings: addons/rakugo/narrator/name
Parse a script and store it. You can execute it with execute_script
Execute a script previously registered with parse_script.
file_name, is file_path without folder_path and extension.
You can use file_path.get_file().get_basename().
You do not have to use parse_script and execute_script at same time.
const file_path = "res://Timeline.rk"
func _ready():
Rakugo.parse_script(file_path)
func _process(_delta):
...
Rakugo.execute_script(file_path.get_file().get_basename())
Do parse_script and execute_script at same time.
Save variables and characters in user://save/save_name/save.json file.
Load variables and characters from user://save/save_name/save.json file if exist.
Returns true when Rakugo script reading process is stop, and expects call of do_step.
Use it when is_waiting_step return true, to continue script reading process.