storytelling-assistant/main.gd

89 lines
2.7 KiB
GDScript3
Raw Normal View History

2024-11-25 17:16:38 +00:00
extends Control
@export var seed: int = 0
@onready var otherview: int = 0
@onready var selfview: int = 0
@onready var trueview: int = 0
# variables for nodes
@onready var sound: Node2D = $Sounds
2024-11-25 17:16:38 +00:00
@onready var roll_dice: TextureButton = $Roll/Roll_dice
@onready var psyline_other: Control = $Psy_line_other
2024-11-28 10:13:57 +00:00
@onready var pin_other: CheckBox = $Others_panel/Pin
2024-11-25 17:16:38 +00:00
@onready var psyline_self: Control = $Psy_line_self
2024-11-28 10:13:57 +00:00
@onready var pin_self: CheckBox = $Self_panel/Pin
2024-11-25 17:16:38 +00:00
@onready var psyline_true: Control = $Psy_line_true
2024-11-28 10:13:57 +00:00
@onready var pin_true: CheckBox = $True_panel/Pin
2024-11-25 17:16:38 +00:00
@onready var traits: Control = $Traits
@onready var keep_psy: CheckBox = $Roll/Keep_psy
@onready var keep_traits: CheckBox = $Roll/Keep_traits
@onready var language_choice: MenuButton = $Language
@onready var soundplayer: EAEventBankMounter = $SoundPlayer
2024-11-25 17:16:38 +00:00
2024-11-28 10:13:57 +00:00
2024-11-25 17:16:38 +00:00
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
lets_roll(seed, 0)
2024-11-25 17:16:38 +00:00
roll_dice.pressed.connect(_on_roll_dice_pressed)
language_choice.get_popup().connect("id_pressed", _on_menu_language_selected)
2024-11-28 17:52:35 +00:00
func _process(_delta: float) -> void:
2024-11-25 17:16:38 +00:00
# Roll new result"
if Input.is_action_just_pressed("roll"):
lets_roll(seed)
# Exit the app
if Input.is_action_just_pressed("ui_cancel"):
get_tree().quit()
func _on_roll_dice_pressed() -> void:
lets_roll(seed)
func lets_roll(chosen_seed: int, noise: bool = 1) -> void:
2024-11-25 17:16:38 +00:00
# Random psy profiles
var possible_psy: int = $Psy_line_other.resources.size()
var random = RandomNumberGenerator.new()
random.seed = chosen_seed
# Play sound if wanted
if noise:
EventAudio.play_2d("DICEROLL", sound)
2024-11-25 17:16:38 +00:00
# Randomize psychology
if not keep_psy.button_pressed:
2024-11-28 10:13:57 +00:00
if not pin_other.button_pressed:
random.randomize()
var result_other: int = random.randi_range(0, possible_psy - 1)
psyline_other.choice.select(result_other)
psyline_other.on_item_selected(result_other)
if not pin_self.button_pressed:
random.randomize()
var result_self: int = random.randi_range(0, possible_psy - 1)
psyline_self.choice.select(result_self)
psyline_self.on_item_selected(result_self)
if not pin_true.button_pressed:
random.randomize()
var result_true: int = random.randi_range(0, possible_psy - 1)
psyline_true.choice.select(result_true)
psyline_true.on_item_selected(result_true)
2024-11-25 17:16:38 +00:00
# Randomize trait
if not keep_traits.button_pressed:
2024-11-28 17:06:02 +00:00
traits.build_traits()
2024-11-27 14:20:30 +00:00
func update_language(new_language: String) -> void:
2024-11-28 10:13:57 +00:00
# Change the localisation on Translation Server
2024-11-27 14:20:30 +00:00
TranslationServer.set_locale(new_language)
emit_signal("language_changed", new_language)
func _on_menu_language_selected(id: int) -> void:
2024-11-28 10:13:57 +00:00
# To call proper locale when button signal is emitted
match id:
0:
TranslationServer.set_locale("fr")
1:
TranslationServer.set_locale("en")