changed the word amount
This commit is contained in:
parent
d8bde52ed6
commit
a7f4c343de
3 changed files with 30 additions and 38 deletions
|
@ -38,8 +38,8 @@ selected_bottom_panel_item=0
|
||||||
[EditorWindow]
|
[EditorWindow]
|
||||||
|
|
||||||
screen=2
|
screen=2
|
||||||
mode="windowed"
|
mode="maximized"
|
||||||
position=Vector2i(1921, 31)
|
position=Vector2i(1920, 23)
|
||||||
size=Vector2i(1416, 1000)
|
size=Vector2i(1416, 1000)
|
||||||
|
|
||||||
[ScriptEditor]
|
[ScriptEditor]
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
state={
|
state={
|
||||||
"bookmarks": PackedInt32Array(),
|
"bookmarks": PackedInt32Array(),
|
||||||
"breakpoints": PackedInt32Array(),
|
"breakpoints": PackedInt32Array(),
|
||||||
"column": 15,
|
"column": 0,
|
||||||
"folded_lines": Array[int]([]),
|
"folded_lines": Array[int]([]),
|
||||||
"h_scroll_position": 0,
|
"h_scroll_position": 0,
|
||||||
"row": 13,
|
"row": 72,
|
||||||
"scroll_position": 0.0,
|
"scroll_position": 50.0,
|
||||||
"selection": false,
|
"selection": false,
|
||||||
"syntax_highlighter": "GDScript"
|
"syntax_highlighter": "GDScript"
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,62 +23,54 @@ var has_red_potion = false
|
||||||
var has_green_potion = false
|
var has_green_potion = false
|
||||||
var coin_count = 0
|
var coin_count = 0
|
||||||
|
|
||||||
var word_chunks = [] # Array to store the tokenized words
|
var word_chunks = [] # Stores the words to show in chunks
|
||||||
var current_chunk_index = 0 # Keeps track of the current chunk
|
var current_chunk_index = 0 # Tracks which chunk we're on
|
||||||
|
|
||||||
# Function to prepare and show text in 5-word chunks
|
# Call this to start displaying the text in chunks
|
||||||
func show_text_in_chunks(full_text: String) -> void:
|
func show_text_in_chunks(full_text: String) -> void:
|
||||||
# Add mystical Latin phrase at the end for a wizard or knight
|
# Add wizard/knight-style ending at the end
|
||||||
full_text += " Ave Domine Limosus, dominator omnium slime!"
|
full_text += " Ave Domine Limosus, gloria regni slime aeterni!"
|
||||||
|
|
||||||
# Split the full text into words, keeping punctuation separate
|
# Tokenize the full text into words and punctuation
|
||||||
word_chunks = tokenize_text(full_text)
|
word_chunks = tokenize_text(full_text)
|
||||||
current_chunk_index = 0
|
current_chunk_index = 0
|
||||||
$"TextEdit".visible = true
|
$"TextEdit".visible = true
|
||||||
$"TextEdit".text = "" # Clear the text before starting
|
$"TextEdit".text = "" # Start clean
|
||||||
|
|
||||||
set_process(true) # Enable processing for the _process function
|
set_process(true) # Allow input checking in _process
|
||||||
|
|
||||||
# Function to tokenize the text into words and punctuation separately
|
# Tokenize text into words and punctuation marks separately
|
||||||
func tokenize_text(text: String) -> Array:
|
func tokenize_text(text: String) -> Array:
|
||||||
var regex = RegEx.new()
|
var regex = RegEx.new()
|
||||||
regex.compile(r"[\w']+|[.,!?;]") # Regular expression to split words and punctuation
|
regex.compile(r"[\w']+|[.,!?;]") # Match words and punctuation
|
||||||
var matches = regex.search_all(text)
|
var matches = regex.search_all(text)
|
||||||
var tokens = []
|
var tokens = []
|
||||||
for match in matches:
|
for match in matches:
|
||||||
tokens.append(match.strings[0]) # Append each matched token
|
tokens.append(match.strings[0])
|
||||||
return tokens
|
return tokens
|
||||||
|
|
||||||
# Process function to handle input and display text chunks
|
# Called every frame, listens for just-pressed input to show next chunk
|
||||||
func _process(delta):
|
func _process(_delta):
|
||||||
# Check if there are more chunks to display and listen for input
|
if Input.is_action_just_pressed("ui_accept_text"):
|
||||||
if current_chunk_index * 5 < word_chunks.size():
|
if current_chunk_index * 7 < word_chunks.size():
|
||||||
if Input.is_action_just_pressed("ui_accept"): # Trigger on just pressed input
|
|
||||||
_display_next_chunk()
|
_display_next_chunk()
|
||||||
# If all chunks are displayed, show an empty chunk and hide the TextEdit
|
elif $"TextEdit".visible:
|
||||||
elif current_chunk_index * 5 >= word_chunks.size() and $"TextEdit".visible:
|
|
||||||
_display_empty_chunk()
|
_display_empty_chunk()
|
||||||
|
|
||||||
# Function to display only the next chunk of 5 words
|
# Show the current chunk of exactly 7 words
|
||||||
func _display_next_chunk() -> void:
|
func _display_next_chunk() -> void:
|
||||||
# Clear the current text
|
var start = current_chunk_index * 7
|
||||||
$"TextEdit".text = ""
|
var end = min(start + 7, word_chunks.size())
|
||||||
|
var chunk_text = " ".join(word_chunks.slice(start, end))
|
||||||
# Show the next 5 words
|
$"TextEdit".text = chunk_text
|
||||||
var start = current_chunk_index * 5
|
|
||||||
var end = min(start + 5, word_chunks.size()) # Ensure we don't go beyond the last word
|
|
||||||
var chunk_text = " ".join(word_chunks.slice(start, end)) # Join the next 5 words
|
|
||||||
$"TextEdit".text = chunk_text # Display only the current 5 words
|
|
||||||
|
|
||||||
# Move to the next chunk
|
|
||||||
current_chunk_index += 1
|
current_chunk_index += 1
|
||||||
|
|
||||||
# Function to display an empty chunk before closing the text
|
# Show empty chunk and hide the box
|
||||||
func _display_empty_chunk() -> void:
|
func _display_empty_chunk() -> void:
|
||||||
# Display an empty chunk (effectively clearing the TextEdit)
|
|
||||||
$"TextEdit".text = ""
|
$"TextEdit".text = ""
|
||||||
# Hide the TextEdit after the empty chunk
|
|
||||||
$"TextEdit".visible = false
|
$"TextEdit".visible = false
|
||||||
|
set_process(false)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func resetGame():
|
func resetGame():
|
||||||
|
|
Loading…
Add table
Reference in a new issue