Skip to content

Commit 8b22c9d

Browse files
authored
Merge pull request #283 from Jeremi360/true-false-v2
Add `true/false` keywords support PR v2
2 parents dd57c6e + 3823538 commit 8b22c9d

File tree

7 files changed

+82
-77
lines changed

7 files changed

+82
-77
lines changed

.gut_editor_config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
"post_run_script": "",
3434
"pre_run_script": "",
3535
"prefix": "Test",
36-
"selected": "TestFix273.gd",
36+
"selected": "TestVariablesRk.gd",
3737
"should_exit": false,
3838
"should_exit_on_success": false,
3939
"should_maximize": false,
4040
"show_help": false,
4141
"suffix": ".gd",
4242
"tests": [],
43-
"unit_test_name": null
43+
"unit_test_name": "test_variables"
4444
}

Test/TestParser/TestVariables/TestVariables.gd

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ func test_variables():
2727

2828
assert_variable("Sy.life", TYPE_INT, 10)
2929

30-
assert_eq(Rakugo.get_variable("g"), null)
30+
assert_variable("boolean", TYPE_BOOL, true)
31+
32+
assert_variable("boolean", TYPE_BOOL, false)
3133

32-
func test_variables_in_strings():
34+
func test_variables_in_strings():
3335
var file_path = "res://Test/TestParser/TestVariables/TestDynamicVars.rk"
3436

3537
var file_base_name = get_file_base_name(file_path)

Test/TestParser/TestVariables/TestVariables.rk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ a /= 1
88
b += 1
99
c += " world !"
1010
d -= 2
11-
Sy.life *= 2
1211
e = Sy.life
13-
f = 1
14-
f += "1"
12+
Sy.life *= 2
13+
boolean = true
14+
boolean = false

addons/Rakugo/Rakugo.gd

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ const save_folder = "application/addons/rakugo/save_folder"
99
#Godot setting's strings
1010
const game_title = "application/config/name"
1111

12-
const version := "2.3"
12+
const version := "2.3.1"
1313

14-
const StoreManager = preload ("res://addons/Rakugo/lib/systems/StoreManager.gd")
15-
const Parser = preload ("res://addons/Rakugo/lib/systems/Parser.gd")
16-
const Executer = preload ("res://addons/Rakugo/lib/systems/Executer.gd")
14+
const StoreManager = preload("res://addons/Rakugo/lib/systems/StoreManager.gd")
15+
const Parser = preload("res://addons/Rakugo/lib/systems/Parser.gd")
16+
const Executer = preload("res://addons/Rakugo/lib/systems/Executer.gd")
1717

1818
var waiting_step := false: get = is_waiting_step
1919

@@ -203,9 +203,9 @@ func get_character_variable(character_tag: String, var_name: String):
203203
(
204204
"Rakugo character with tag "
205205
+ character_tag
206-
+ " does not have this variable: "
206+
+" does not have this variable: "
207207
+ var_name
208-
+ ", returning null"
208+
+", returning null"
209209
)
210210
)
211211
push_error("Available variables are: " + str(character.keys()))
@@ -220,19 +220,19 @@ func get_character_variable(character_tag: String, var_name: String):
220220
func _ready():
221221
var version = ProjectSettings.get_setting(game_version)
222222
var title = ProjectSettings.get_setting(game_title)
223-
get_window().set_title(title + " " + version)
223+
get_window().set_title(title + " " + str(version))
224224

225225
var narrator_name = ProjectSettings.get_setting(narrator_name)
226226
define_character("narrator", narrator_name)
227227

228228
## Save all variables, characters, script_name and last line readed on last executed script, in user://save/save_name/save.json file.
229-
func save_game(save_name: String="quick"):
229+
func save_game(save_name: String = "quick"):
230230
mutex.lock()
231231
store_manager.save_game(executer.get_current_thread_datas(), save_name)
232232
mutex.unlock()
233233

234234
## Load all variables, characters, script_name and last line readed on last executed script, from user://save/save_name/save.json file if existed.
235-
func load_game(save_name:="quick"):
235+
func load_game(save_name := "quick"):
236236
last_thread_datas = store_manager.load_game(save_name)
237237
parse_script(last_thread_datas["path"])
238238
sg_game_loaded.emit()
@@ -272,7 +272,7 @@ func parse_script(file_name: String) -> int:
272272

273273
## Executer
274274
## Execute a script previously registered with parse_script.
275-
func execute_script(script_name: String, label_name: String="", index: int=0) -> int:
275+
func execute_script(script_name: String, label_name: String = "", index: int = 0) -> int:
276276
var error = FAILED
277277

278278
mutex.lock()
@@ -292,7 +292,7 @@ func stop_last_script():
292292
mutex.unlock()
293293

294294
## Do parse_script, if return OK then do execute_script.
295-
func parse_and_execute_script(file_name: String, label_name: String="") -> int:
295+
func parse_and_execute_script(file_name: String, label_name: String = "") -> int:
296296
var error = FAILED
297297

298298
mutex.lock()

addons/Rakugo/lib/systems/Executer.gd

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ const jump_error = "Executer::do_execute_jump, can not jump to unknow label : "
44

55
var stop_thread := false
66

7-
var current_thread:Thread
7+
var current_thread: Thread
88

9-
var current_semaphore:Semaphore
9+
var current_semaphore: Semaphore
1010

11-
var threads:Dictionary
11+
var threads: Dictionary
1212

1313
var regex := {
1414
NAME = "[a-zA-Z][a-zA-Z_0-9]*",
@@ -18,7 +18,7 @@ var regex := {
1818

1919
var regex_cache := {}
2020

21-
var menu_jump_index:int
21+
var menu_jump_index: int
2222

2323
func _init():
2424
for key in regex:
@@ -34,7 +34,7 @@ func get_current_thread_datas() -> Dictionary:
3434
if current_thread:
3535
var dico = threads[current_thread.get_id()]
3636

37-
return {"file_base_name":dico["file_base_name"], "last_index":dico["last_index"]}
37+
return {"file_base_name": dico["file_base_name"], "last_index": dico["last_index"]}
3838

3939
return {}
4040

@@ -46,27 +46,27 @@ func stop_current_thread() -> int:
4646
dico["semaphore"].post()
4747
return OK
4848

49-
func execute_script(parsed_script:Dictionary, label_name:String = "", index:int = 0) -> int:
49+
func execute_script(parsed_script: Dictionary, label_name: String = "", index: int = 0) -> int:
5050
stop_current_thread()
5151

5252
current_thread = Thread.new()
5353

5454
current_semaphore = Semaphore.new()
5555

5656
var thread_parameters = {
57-
"thread":current_thread,
58-
"semaphore":current_semaphore,
59-
"parsed_script":parsed_script,
60-
"file_base_name":parsed_script["path"].get_file().get_basename(),
61-
"stop":false
57+
"thread": current_thread,
58+
"semaphore": current_semaphore,
59+
"parsed_script": parsed_script,
60+
"file_base_name": parsed_script["path"].get_file().get_basename(),
61+
"stop": false
6262
}
6363

6464
if index > 0:
6565
thread_parameters["last_index"] = index
6666
elif !label_name.is_empty():
6767
thread_parameters["label_name"] = label_name
6868

69-
if current_thread.start(Callable(self,"do_execute_script").bind(thread_parameters)) != OK:
69+
if current_thread.start(Callable(self, "do_execute_script").bind(thread_parameters)) != OK:
7070
threads.erase(current_thread.get_id())
7171

7272
current_thread = null
@@ -76,7 +76,7 @@ func execute_script(parsed_script:Dictionary, label_name:String = "", index:int
7676
return FAILED
7777
return OK
7878

79-
func do_execute_script_end(parameters:Dictionary):
79+
func do_execute_script_end(parameters: Dictionary):
8080
parameters["thread"].wait_to_finish()
8181

8282
if parameters.has("error"):
@@ -91,13 +91,13 @@ func do_execute_script_end(parameters:Dictionary):
9191

9292
current_semaphore = null
9393

94-
func do_execute_jump(jump_label:String, labels:Dictionary) -> int:
94+
func do_execute_jump(jump_label: String, labels: Dictionary) -> int:
9595
if labels.has(jump_label):
9696
return labels[jump_label]
9797

9898
return -1
9999

100-
func do_execute_script(parameters:Dictionary):
100+
func do_execute_script(parameters: Dictionary):
101101
var thread = parameters["thread"]
102102

103103
threads[thread.get_id()] = parameters
@@ -108,7 +108,7 @@ func do_execute_script(parameters:Dictionary):
108108

109109
Rakugo.call_thread_safe("send_execute_script_start", parameters["file_base_name"])
110110

111-
var parse_array:Array = parsed_script["parse_array"]
111+
var parse_array: Array = parsed_script["parse_array"]
112112

113113
var labels = parsed_script["labels"]
114114

@@ -133,11 +133,11 @@ func do_execute_script(parameters:Dictionary):
133133
while !parameters["stop"] and index < parse_array.size():
134134
parameters["last_index"] = index
135135

136-
var line:Array = parse_array[index]
136+
var line: Array = parse_array[index]
137137

138138
var result = line[1]
139139

140-
match(line[0]):
140+
match (line[0]):
141141
"EXIT":
142142
parameters["stop"] = true
143143
break
@@ -200,9 +200,9 @@ func do_execute_script(parameters:Dictionary):
200200
semephore.wait()
201201

202202
"MENU":
203-
var menu_choices:PackedStringArray
203+
var menu_choices: PackedStringArray
204204

205-
var menu_jumps:Dictionary
205+
var menu_jumps: Dictionary
206206

207207
for i in line[2].size():
208208
var menu_choice_result = line[2][i]
@@ -241,16 +241,18 @@ func do_execute_script(parameters:Dictionary):
241241
var rvar_name = result["rvar_name"]
242242
var text = result["text"]
243243

244-
var value
244+
var value = null
245245

246246
if !rvar_name.is_empty():
247247
value = Rakugo.get_variable(rvar_name)
248-
249-
if !value:
248+
249+
if value == null:
250250
parameters["error"] = "Executer::do_execute_script::SET_VARIABLE, can not get variable :" + rvar_name
251251
parameters["stop"] = true
252252
break
253-
253+
254+
elif !result["bool"].is_empty():
255+
value = result["bool"] == "true"
254256
elif !text.is_empty():
255257
value = text
256258
else:
@@ -283,7 +285,7 @@ func do_execute_script(parameters:Dictionary):
283285
parameters["stop"] = true
284286
break
285287

286-
match(assignment):
288+
match (assignment):
287289
"+=":
288290
value = lvalue + value
289291

0 commit comments

Comments
 (0)