Skip to content

Commit f2a1eeb

Browse files
authored
Add files via upload
1 parent 5e07aa3 commit f2a1eeb

File tree

9 files changed

+154
-63
lines changed

9 files changed

+154
-63
lines changed

Connection.tscn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ offset_bottom = 52.0
1818
theme_override_styles/panel = SubResource("StyleBoxEmpty_gipfx")
1919

2020
[node name="Status" type="Label" parent="Status_BG"]
21-
z_index = 1
2221
texture_filter = 1
2322
layout_mode = 0
2423
offset_left = 1.0

Containers.tscn

Lines changed: 24 additions & 24 deletions
Large diffs are not rendered by default.

Input.tscn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,11 @@ placeholder_text = "Input something here....."
1818
alignment = 1
1919
keep_editing_on_text_submit = true
2020

21+
[node name="Button" type="Button" parent="."]
22+
offset_right = 446.0
23+
offset_bottom = 32.0
24+
25+
[connection signal="text_change_rejected" from="Command" to="." method="_on_command_text_change_rejected"]
26+
[connection signal="text_changed" from="Command" to="." method="_on_command_text_changed"]
2127
[connection signal="text_submitted" from="Command" to="." method="_on_command_text_submitted"]
28+
[connection signal="pressed" from="Button" to="." method="_on_button_pressed"]

Options.tscn

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
[gd_scene load_steps=8 format=3 uid="uid://6wgctohcvfte"]
1+
[gd_scene load_steps=9 format=3 uid="uid://6wgctohcvfte"]
22

33
[ext_resource type="Texture2D" uid="uid://c3fn1ppgdav4d" path="res://assets/backpack.png" id="1_2r1l1"]
44
[ext_resource type="Script" uid="uid://cjyiwpvt3l6me" path="res://options.gd" id="1_p8250"]
55
[ext_resource type="Texture2D" uid="uid://c30y87tpk5nvi" path="res://assets/status.png" id="2_bwr58"]
66
[ext_resource type="Texture2D" uid="uid://db7d38mogv2yf" path="res://assets/skills.png" id="3_dfe3t"]
77
[ext_resource type="Texture2D" uid="uid://c4nrcqenb1u7i" path="res://assets/spells.png" id="4_t1d33"]
88
[ext_resource type="Texture2D" uid="uid://cirk3qabkxsfu" path="res://assets/exit.png" id="6_dfe3t"]
9+
[ext_resource type="Texture2D" uid="uid://cig85t7o0v7p2" path="res://assets/perception.png" id="6_t1d33"]
910

1011
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_5pjjr"]
1112

@@ -52,6 +53,12 @@ layout_mode = 2
5253
texture_normal = ExtResource("4_t1d33")
5354
stretch_mode = 0
5455

56+
[node name="look_button" type="TextureButton" parent="Buttons_BG/GridContainer"]
57+
texture_filter = 1
58+
layout_mode = 2
59+
texture_normal = ExtResource("6_t1d33")
60+
stretch_mode = 0
61+
5562
[node name="exit_button" type="TextureButton" parent="Buttons_BG/GridContainer"]
5663
texture_filter = 1
5764
layout_mode = 2
@@ -62,4 +69,5 @@ stretch_mode = 0
6269
[connection signal="pressed" from="Buttons_BG/GridContainer/status_button" to="." method="_on_status_button_pressed"]
6370
[connection signal="pressed" from="Buttons_BG/GridContainer/skills_button" to="." method="_on_skills_button_pressed"]
6471
[connection signal="pressed" from="Buttons_BG/GridContainer/spells_button" to="." method="_on_spells_button_pressed"]
72+
[connection signal="pressed" from="Buttons_BG/GridContainer/look_button" to="." method="_on_look_button_pressed"]
6573
[connection signal="pressed" from="Buttons_BG/GridContainer/exit_button" to="." method="_on_exit_button_pressed"]

input.gd

Lines changed: 68 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,79 @@
11
extends Node2D
22

3+
var _previous_cmd: Array = []
4+
var _cmd_index: int = -1
5+
var _input_editing: bool = false
6+
37
signal cmd_text_submitted(data: String)
48

5-
func _ready():
9+
func _ready() -> void:
610
$"../Options".connect("button_commands_submitted", Callable(self, "_on_button_command_text_submitted"))
11+
$"../TextProcessor".connect("auto_commands_submitted", Callable(self, "_on_auto_commands_submitted"))
12+
$Command.connect("focus_entered", Callable(self, "_on_focus_entered"))
13+
$Command.connect("focus_exited", Callable(self, "_on_focus_exited"))
14+
15+
func _on_auto_commands_submitted(cmd: String) -> void:
16+
emit_signal("cmd_text_submitted", cmd)
17+
18+
func _on_focus_entered() -> void:
19+
_input_editing = true
20+
21+
func _on_focus_exited() -> void:
22+
_input_editing = false
723

824
func _on_button_command_text_submitted(data: String) -> void:
9-
if len(data) > 0:
25+
if data.strip_edges() != "":
1026
emit_signal("cmd_text_submitted", data)
11-
27+
1228
func _on_command_text_submitted(data: String) -> void:
13-
if len(data) > 0:
14-
emit_signal("cmd_text_submitted", data)
15-
$Command.clear()
29+
data = data.strip_edges()
30+
if data == "":
1631
return
17-
var new_text = $Command.text
18-
emit_signal("cmd_text_submitted", new_text)
32+
emit_signal("cmd_text_submitted", data)
33+
if _previous_cmd.size() >= 10:
34+
_previous_cmd.pop_front()
35+
_previous_cmd.append(data)
36+
_cmd_index = _previous_cmd.size() # reset to latest
1937
$Command.clear()
20-
21-
func _unhandled_input(event: InputEvent) -> void:
22-
# Handle arrow key input globally (even when Command has focus)
23-
if event is InputEventKey and event.pressed:
24-
if event.keycode in [KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT]:
25-
match event.keycode:
26-
KEY_UP:
27-
emit_signal("cmd_text_submitted", "n")
28-
KEY_DOWN:
29-
emit_signal("cmd_text_submitted", "s")
30-
KEY_LEFT:
31-
emit_signal("cmd_text_submitted", "w")
32-
KEY_RIGHT:
33-
emit_signal("cmd_text_submitted", "e")
38+
39+
func _process(_delta: float) -> void:
40+
if _input_editing:
41+
# ESC to exit edit mode
42+
if Input.is_action_just_pressed("ui_cancel"):
43+
_input_editing = false
44+
$Command.release_focus()
45+
return
46+
47+
# Handle command history navigation
48+
if Input.is_action_just_pressed("ui_up"):
49+
if _previous_cmd.size() == 0:
50+
return
51+
_cmd_index = max(_cmd_index - 1, 0)
52+
$Command.text = _previous_cmd[_cmd_index]
53+
$Command.caret_column = $Command.text.length()
54+
elif Input.is_action_just_pressed("ui_down"):
55+
if _previous_cmd.size() == 0:
56+
return
57+
_cmd_index = min(_cmd_index + 1, _previous_cmd.size() - 1)
58+
$Command.text = _previous_cmd[_cmd_index]
59+
$Command.caret_column = $Command.text.length()
60+
61+
else:
62+
if Input.is_action_just_pressed("ui_accept"):
63+
_input_editing = true
64+
$Command.grab_focus()
65+
return
66+
67+
# Handle directional movement when not typing
68+
if Input.is_action_just_pressed("ui_up"):
69+
emit_signal("cmd_text_submitted", "n")
70+
elif Input.is_action_just_pressed("ui_down"):
71+
emit_signal("cmd_text_submitted", "s")
72+
elif Input.is_action_just_pressed("ui_left"):
73+
emit_signal("cmd_text_submitted", "w")
74+
elif Input.is_action_just_pressed("ui_right"):
75+
emit_signal("cmd_text_submitted", "e")
76+
77+
func _on_button_pressed() -> void:
78+
_input_editing = true
79+
$Command.grab_focus()

map.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func organize_exits(data: String) -> String:
4343
for raw_line in data.split("\n", false):
4444
var line := raw_line.rstrip("\r")
4545
line = re_paren.sub(line, "", true)
46-
print(i, line)
46+
#print(i, line)
4747
organized_exits.append(line + "\n")
4848
var text = "".join(organized_exits)
4949
return text

options.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ func _on_spells_button_pressed() -> void:
1616

1717
func _on_exit_button_pressed() -> void:
1818
emit_signal("button_commands_submitted", "quit")
19+
20+
func _on_look_button_pressed() -> void:
21+
emit_signal("button_commands_submitted", "look")

status.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ func _ready():
55
$Status_BG/TextDisplay.bbcode_enabled = true # important
66

77
func _on_status_text_received(bb_line: String) -> void:
8-
print(bb_line)
8+
#print(bb_line)
99
var n := bb_line.length()
1010
if n >= 2:
1111
bb_line = bb_line.substr(24, n -49)

text_processor.gd

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ signal status_text(text: String)
66
signal mobs_text(text: String)
77
signal exits_text(text: String)
88
signal container_request(data: Array)
9+
signal auto_commands_submitted(cmd: String)
910

1011
const _LEFT_CHARS := {"╔": true, "║": true, "╚": true}
1112
const _RIGHT_CHARS := {"╗": true, "║": true, "╝": true}
1213

1314
var _in_map := false
1415
var _cur_map: Array = []
1516
var _backpack_prohibit = false
17+
var _prevent_location_name = false
18+
var _prevent_location_desc = false
1619

1720
# remember first line + left index to compute prefix
1821
var _first_line_raw := ""
@@ -279,30 +282,26 @@ func _process_one_bb_line(bb_chunk: String) -> void:
279282

280283
# After processing all lines in the chunk, append descriptions once
281284
var descs_size = descs.size()
282-
#print("Desc size = ", descs_size)
283-
#print("Start to process desc.....")
284-
285285
var text = ""
286286

287287
# one line message
288288
if descs_size == 1:
289-
#print("------------------------------")
290-
#print("One line desc: ", descs)
291-
#print("------------------------------")
292289
if _visible_prefix(descs[0], 1) == "(":
293290
# status text
294291
emit_signal("status_text", str(descs[0]))
295292
return
296293
elif _visible_prefix(descs[0], 100) in ["TEXTMASK:false", "TEXTMASK:true"]:
297294
return
298295
else:
299-
$TextDisplay.append_text(bb_chunk)
296+
# classified as short msg
297+
var short_msg = _visible_prefix(descs[0], 30)
298+
if len(short_msg) > 3:
299+
if short_msg not in ["look", "status", "equipment", "skills", "spells"]:
300+
$TextDisplay.append_text(bb_chunk)
301+
return
300302

301303
# two line message
302304
if descs_size == 2:
303-
#print("------------------------------")
304-
#print("Two line desc: ", descs)
305-
#print("------------------------------")
306305
if _visible_prefix(descs[0], 5) == "Exits":
307306
# exits
308307
emit_signal("exits_text", bb_chunk)
@@ -311,6 +310,24 @@ func _process_one_bb_line(bb_chunk: String) -> void:
311310
emit_signal("mobs_text", descs[0])
312311
else:
313312
$TextDisplay.append_text(bb_chunk)
313+
# auto refresh the mobs
314+
var l0_prefix_100 = _visible_prefix(descs[0], 100)
315+
if contains_term(l0_prefix_100, "enters"):
316+
_prevent_location_name = true
317+
_prevent_location_desc = true
318+
emit_signal("auto_commands_submitted", "look")
319+
if contains_term(l0_prefix_100, "leaves"):
320+
_prevent_location_name = true
321+
_prevent_location_desc = true
322+
emit_signal("auto_commands_submitted", "look")
323+
if contains_term(l0_prefix_100, "died"):
324+
_prevent_location_name = true
325+
_prevent_location_desc = true
326+
emit_signal("auto_commands_submitted", "look")
327+
if contains_term(l0_prefix_100, "prepares"):
328+
_prevent_location_name = true
329+
_prevent_location_desc = true
330+
emit_signal("auto_commands_submitted", "look")
314331
return
315332

316333
# big message
@@ -348,7 +365,11 @@ func _process_one_bb_line(bb_chunk: String) -> void:
348365
# location name
349366
emit_signal("location_name", bb_chunk)
350367
emit_signal("mobs_text", "")
351-
$TextDisplay.append_text(bb_chunk)
368+
if not _prevent_location_name:
369+
$TextDisplay.append_text(bb_chunk)
370+
else:
371+
_prevent_location_name = false
372+
return
352373

353374
elif l2_prefix_100 == "┌─ .:Info ──────────────────────┐ ┌─ .:Attributes ───────────────────────────┐":
354375
# status table
@@ -382,8 +403,12 @@ func _process_one_bb_line(bb_chunk: String) -> void:
382403
$TextDisplay.append_text(bb_chunk)
383404

384405
else:
385-
$TextDisplay.append_text(text + "\n")
386-
406+
if not _prevent_location_desc:
407+
$TextDisplay.append_text(text + "\n")
408+
else:
409+
_prevent_location_desc = false
410+
return
411+
387412
# ---------------- helpers ----------------
388413
func _line_map_slice_indices(bb_line: String) -> Array:
389414
var left := -1
@@ -474,3 +499,6 @@ func _closing_for_stack(stack: Array) -> String:
474499
if String(stack[i]).begins_with("[color"):
475500
s += "[/color]"
476501
return s
502+
503+
func contains_term(message: String, term: String) -> bool:
504+
return message.find(term) != -1

0 commit comments

Comments
 (0)