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]
|
||||
|
||||
screen=2
|
||||
mode="windowed"
|
||||
position=Vector2i(1921, 31)
|
||||
mode="maximized"
|
||||
position=Vector2i(1920, 23)
|
||||
size=Vector2i(1416, 1000)
|
||||
|
||||
[ScriptEditor]
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
state={
|
||||
"bookmarks": PackedInt32Array(),
|
||||
"breakpoints": PackedInt32Array(),
|
||||
"column": 15,
|
||||
"column": 0,
|
||||
"folded_lines": Array[int]([]),
|
||||
"h_scroll_position": 0,
|
||||
"row": 13,
|
||||
"scroll_position": 0.0,
|
||||
"row": 72,
|
||||
"scroll_position": 50.0,
|
||||
"selection": false,
|
||||
"syntax_highlighter": "GDScript"
|
||||
}
|
||||
|
|
|
@ -23,62 +23,54 @@ var has_red_potion = false
|
|||
var has_green_potion = false
|
||||
var coin_count = 0
|
||||
|
||||
var word_chunks = [] # Array to store the tokenized words
|
||||
var current_chunk_index = 0 # Keeps track of the current chunk
|
||||
var word_chunks = [] # Stores the words to show in chunks
|
||||
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:
|
||||
# Add mystical Latin phrase at the end for a wizard or knight
|
||||
full_text += " Ave Domine Limosus, dominator omnium slime!"
|
||||
# Add wizard/knight-style ending at the end
|
||||
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)
|
||||
current_chunk_index = 0
|
||||
$"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:
|
||||
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 tokens = []
|
||||
for match in matches:
|
||||
tokens.append(match.strings[0]) # Append each matched token
|
||||
tokens.append(match.strings[0])
|
||||
return tokens
|
||||
|
||||
# Process function to handle input and display text chunks
|
||||
func _process(delta):
|
||||
# Check if there are more chunks to display and listen for input
|
||||
if current_chunk_index * 5 < word_chunks.size():
|
||||
if Input.is_action_just_pressed("ui_accept"): # Trigger on just pressed input
|
||||
# Called every frame, listens for just-pressed input to show next chunk
|
||||
func _process(_delta):
|
||||
if Input.is_action_just_pressed("ui_accept_text"):
|
||||
if current_chunk_index * 7 < word_chunks.size():
|
||||
_display_next_chunk()
|
||||
# If all chunks are displayed, show an empty chunk and hide the TextEdit
|
||||
elif current_chunk_index * 5 >= word_chunks.size() and $"TextEdit".visible:
|
||||
elif $"TextEdit".visible:
|
||||
_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:
|
||||
# Clear the current text
|
||||
$"TextEdit".text = ""
|
||||
|
||||
# Show the next 5 words
|
||||
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
|
||||
var start = current_chunk_index * 7
|
||||
var end = min(start + 7, word_chunks.size())
|
||||
var chunk_text = " ".join(word_chunks.slice(start, end))
|
||||
$"TextEdit".text = chunk_text
|
||||
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:
|
||||
# Display an empty chunk (effectively clearing the TextEdit)
|
||||
$"TextEdit".text = ""
|
||||
# Hide the TextEdit after the empty chunk
|
||||
$"TextEdit".visible = false
|
||||
set_process(false)
|
||||
|
||||
|
||||
|
||||
func resetGame():
|
||||
|
|
Loading…
Add table
Reference in a new issue