tidied the code some more

This commit is contained in:
Jaap Marsman 2025-04-04 18:39:56 +08:00
parent 255942f8bf
commit 6df90dc006
9 changed files with 63 additions and 90 deletions

View File

@ -1,20 +1,14 @@
extends CanvasLayer
@onready var gi = $"/root/GlobalInts"
@onready var global_ints = gi
@onready var main_window = $"../../AppWindow"
func _ready():
pass # Replace with function body.
func _on_CancelButton_pressed():
func _on_CancelButton_pressed() -> void:
main_window.refresh_descriptors()
$"%EditScreen".visible = false
func _on_OKButton_pressed():
func _on_OKButton_pressed() -> void:
global_ints.one_acronym = $"%1AcronymE".text
global_ints.two_acronym = $"%2AcronymE".text
global_ints.three_acronym = $"%3AcronymE".text
@ -33,12 +27,12 @@ func _on_OKButton_pressed():
global_ints.four_explanation = $"%4ExplanationE".text
global_ints.five_explanation = $"%5ExplanationE".text
$"%EditScreen".visible = false
$"%EditScreen".hide()
main_window.refresh_descriptors()
func _on_ClearAll_pressed():
func _on_ClearAll_pressed() -> void:
$"%1AcronymE".text = ""
$"%1ItemE".text = ""
$"%1ExplanationE".text = ""

View File

@ -1,16 +1,13 @@
extends Panel
@onready var global_ints = $"/root/GlobalInts"
func _on_OkButton_pressed():
func _on_OkButton_pressed() -> void:
if $"%NameLine".text and $"NameContainer/ObserverLine".text and $"NameContainer/ObservedActivity".text != "":
$"%InstructionPanel".visible = true
$"%NameChangePanel".visible = false
$"%InstructionPanel".show()
$"%NameChangePanel".hide()
global_ints.observed_person_name = $"%NameLine".text
global_ints.observer_person_name = $"NameContainer/ObserverLine".text
global_ints.observed_activity = $"NameContainer/ObservedActivity".text
else:
$"%ObservedNameLabel".visible = false
$"%WarningLabel".visible = true
$"%ObservedNameLabel".hide()
$"%WarningLabel".show()

View File

@ -1,29 +1,25 @@
extends CanvasLayer
@onready var global_ints = $"/root/GlobalInts"
var time_lefts : int
var toggle_observation : bool = false
var observation_button_pressed : bool = false
func _ready():
$"Panel/BehaviourButtons".visible = false
pass
func _ready() -> void:
$"Panel/BehaviourButtons".hide()
func _process(_delta):
func _process(_delta) -> void:
time_lefts = $"TwentySecondTimer".time_left
$"Panel/TimeRemaining".text = str(time_lefts)
if time_lefts == 5 && toggle_observation == false:
print("We're at the five second mark!")
toggle_observation = true
$"Panel/BehaviourButtons".visible = true
$"Panel/BehaviourButtons".show()
func calculate_percentages():
func calculate_percentages() -> void:
global_ints.total_observed_time = global_ints.total_behaviours / 3
global_ints.one_behaviour_percent = int((float(global_ints.one_behaviour_score) / global_ints.total_behaviours) * 100)
@ -36,14 +32,14 @@ func calculate_percentages():
global_ints.five_behaviour_percent = int((float(global_ints.five_behaviour_score) / global_ints.total_behaviours) * 100)
func on_interval_moment():
func on_interval_moment() -> void:
print("Timer reaches 0 - Let's check if buttons have been pressed and count something")
toggle_observation = false
# Otherwise - a 6 is registered (nothing selected)
# Buttons are to become visible again
global_ints.locked_observations_intervals_remaining -= 1
global_ints.locked_observations_completed += 1
$"Panel/BehaviourButtons".visible = false
$"Panel/BehaviourButtons".hide()
if observation_button_pressed == false:
global_ints.six_behaviour_score += 1
@ -55,7 +51,7 @@ func on_interval_moment():
$"Panel/DescriptorBox/ObservationsRemaining".text = str(global_ints.locked_observations_intervals_remaining)
func _on_TwentySecondTimer_timeout():
func _on_TwentySecondTimer_timeout() -> void:
if global_ints.locked_observations_intervals_remaining == 1:
on_interval_moment()
print("We're completely done - no intervals remain")
@ -71,49 +67,49 @@ func _on_TwentySecondTimer_timeout():
$"TwentySecondTimer".stop()
global_ints.generate_results = true
calculate_percentages()
$"../Results".visible = true
$"../Results".show()
if global_ints.locked_observations_intervals_remaining > 1:
on_interval_moment()
func _on_BehaviourOne_pressed():
func _on_BehaviourOne_pressed() -> void:
global_ints.one_behaviour_score += 1
global_ints.total_behaviours += 1
observation_button_pressed = true
$"Panel/BehaviourButtons".visible = false
$"Panel/BehaviourButtons".hide()
print(str(global_ints.one_behaviour_score))
func _on_BehaviourTwo_pressed():
func _on_BehaviourTwo_pressed() -> void:
global_ints.two_behaviour_score += 1
global_ints.total_behaviours += 1
observation_button_pressed = true
$"Panel/BehaviourButtons".visible = false
$"Panel/BehaviourButtons".hide()
func _on_BehaviourThree_pressed():
func _on_BehaviourThree_pressed() -> void:
global_ints.three_behaviour_score += 1
global_ints.total_behaviours += 1
observation_button_pressed = true
$"Panel/BehaviourButtons".visible = false
$"Panel/BehaviourButtons".hide()
func _on_BehaviourFour_pressed():
func _on_BehaviourFour_pressed() -> void:
global_ints.four_behaviour_score += 1
global_ints.total_behaviours += 1
observation_button_pressed = true
$"Panel/BehaviourButtons".visible = false
$"Panel/BehaviourButtons".hide()
func _on_BehaviourFive_pressed():
func _on_BehaviourFive_pressed() -> void:
global_ints.five_behaviour_score += 1
global_ints.total_behaviours += 1
observation_button_pressed = true
$"Panel/BehaviourButtons".visible = false
$"Panel/BehaviourButtons".hide()
func _on_Button_pressed():
func _on_Button_pressed() -> void:
on_interval_moment()
print("We're aborting, so deal with as completely done - no intervals remain")
@ -130,4 +126,4 @@ func _on_Button_pressed():
$"TwentySecondTimer".stop()
global_ints.generate_results = true
calculate_percentages()
$"../Results".visible = true
$"../Results".show()

View File

@ -1,13 +1,6 @@
extends ProgressBar
@onready var global_ints = $"/root/GlobalInts"
func _ready():
pass # Replace with function body.
func _process(_delta):
func _process(_delta) -> void:
value = global_ints.locked_observations_intervals_remaining
max_value = global_ints.locked_observation_intervals

View File

@ -1,17 +1,16 @@
extends CanvasLayer
@onready var global_ints = $"/root/GlobalInts"
var js_interface;
var image : Image
var fileName : String = "results.png"
func _ready():
func _ready() -> void:
if OS.get_name() == "Web":
_define_js()
js_interface = JavaScriptBridge.get_interface("_HTML5FileExchange");
func _define_js()->void:
#Define JS script
JavaScriptBridge.eval("""
@ -40,18 +39,16 @@ func _define_js()->void:
}
""", true)
func _process(_delta):
pass
func take_screenshot():
func take_screenshot() -> void:
image = get_viewport().get_texture().get_image()
if OS.get_name() == "Web" or OS.has_feature('JavaScript'):
print("We're on the web")
# We're on the web
# We're on the web
image.clear_mipmaps()
var buffer = image.save_png_to_buffer()
JavaScriptBridge.download_buffer(buffer, fileName)
@ -77,28 +74,29 @@ func take_screenshot():
var _openfolder = OS.shell_open("file://" + docs)
func _on_SaveReport_pressed():
func _on_SaveReport_pressed() -> void:
await get_tree().process_frame
$"%SaveReport".visible = false
$"%BackMainMenu".visible = false
$"%SaveReport".hide()
$"%BackMainMenu".hide()
await get_tree().process_frame
take_screenshot()
$"%SaveReport".show()
$"%BackMainMenu".show()
$"%SaveReport".visible = true
$"%BackMainMenu".visible = true
func _on_BackMainMenu_pressed():
func _on_BackMainMenu_pressed() -> void:
global_ints.reset_all_vars()
var _ignore = get_tree().reload_current_scene()
func _on_Results_visibility_changed():
func _on_Results_visibility_changed() -> void:
if global_ints.generate_results == true:
global_ints.generate_results = false
var result_text : String
result_text = str("Date: " , global_ints.ddmmyyyy , "\nTime: ", global_ints.observation_start_time , " to " , global_ints.observation_end_time , "\n \nThis Time Sampling Form (TSF) observation was completed by " , global_ints.observer_person_name , ". " , global_ints.observed_person_name , " was observed for " , global_ints.total_observed_time , " minute(s) during " , global_ints.observed_activity , ". \n \nDuring the observation, The ", global_ints.one_behaviour," behaviour was observed ", global_ints.one_behaviour_score, " out of ",global_ints.total_behaviours," times, resulting in ",global_ints.one_behaviour_percent,"%. The ",global_ints.two_behaviour," behaviour was observed ",global_ints.two_behaviour_score," out of ",global_ints.total_behaviours," times, resulting in ",global_ints.two_behaviour_percent,"%. The ",global_ints.three_behaviour," behaviour was observed ",global_ints.three_behaviour_score," out of ",global_ints.total_behaviours," times, resulting in ",global_ints.three_behaviour_percent,"%. The ", global_ints.four_behaviour," behaviour was observed ",global_ints.four_behaviour_score," out of ",global_ints.total_behaviours," times, resulting in ",global_ints.four_behaviour_percent,"%. The ",global_ints.five_behaviour," behaviour was observed ",global_ints.five_behaviour_score," out of ",global_ints.total_behaviours," times, resulting in ",global_ints.five_behaviour_percent,"%. ",global_ints.six_behaviour_score," intervals were not scored.")
$"%FullResult".text = result_text

View File

@ -1,14 +1,9 @@
extends ProgressBar
@onready var global_ints = $"/root/GlobalInts"
var time_lefts : int
func _ready():
pass
func _process(_delta):
func _process(_delta) -> void:
time_lefts = $"%TwentySecondTimer".time_left
value = time_lefts

View File

@ -65,7 +65,7 @@ var three_behaviour_percent : float
var four_behaviour_percent : float
var five_behaviour_percent : float
func reset_all_vars():
func reset_all_vars() -> void:
observation_minutes = 15
generate_results = false

View File

@ -8,7 +8,6 @@ var update_text : String
var text_buffer : String
@onready var date_time_display = $"%CurrentTime"
@onready var global_ints = $"/root/GlobalInts"
@onready var minute_label = $"StartScreen/InstructionPanel/MinuteBox/MinuteLabel"
@ -78,7 +77,7 @@ func set_language() -> void:
print(TranslationServer.get_locale())
if TranslationServer.get_locale() != "nl":
print("We're not Dutch")
global_ints.manual_url = "https://docs.internationalsengroup.org/tsf.html"
global_ints.manual_url = "https://docs.jaapmarsman.com/tsf.html"
if TranslationServer.get_locale() == "nl":
print("We're Dutch")
global_ints.manual_url = "https://www.lerenleukermaken.nl/"
@ -93,14 +92,14 @@ func _ready() -> void:
minute_label.text = str(global_ints.observation_minutes)
global_ints.observed_person_name = ""
refresh_descriptors()
$"StartScreen".visible = true
$"%NameChangePanel".visible = true
$"%InstructionScreen".visible = true
$"%WarningLabel".visible = false
$"ObservationWindow".visible = false
$"Results".visible = false
$"EditScreen".visible = false
$"%UpdatePanel".visible = false
$"StartScreen".show()
$"%NameChangePanel".show()
$"%InstructionScreen".show()
$"%WarningLabel".hide()
$"ObservationWindow".hide()
$"Results".hide()
$"EditScreen".hide()
$"%UpdatePanel".hide()
update_date()
set_language()
check_for_updates()
@ -176,14 +175,15 @@ func _on_Start_pressed() -> void:
func _on_ChangeItems_pressed() -> void:
$"EditScreen".visible = true
$"EditScreen".show()
func _on_InsOkButton_pressed() -> void:
$"%InstructionScreen".visible = false
$"%InstructionScreen".hide()
func _on_MinuteMinus_button_down() -> void:
# Holding it down makes it work too - not yet
# if global_ints.observation_minutes >= 2:
# global_ints.observation_minutes -= 1
# minute_label.text = str(global_ints.observation_minutes)
@ -195,4 +195,4 @@ func _on_GoToUpdate_pressed() -> void:
func _on_IgnoreUpdate_pressed() -> void:
$"%UpdatePanel".visible = false
$"%UpdatePanel".hide()

View File

@ -25,7 +25,7 @@ config/windows_native_icon="res://Assets/icons/icon.ico"
[autoload]
GlobalInts="*res://global_ints.gd"
global_ints="*res://global_ints.gd"
[display]