storytelling-assistant/main.gd

88 lines
2.7 KiB
GDScript

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
@onready var roll_dice: TextureButton = $Roll/Roll_dice
@onready var psyline_other: Control = $Psy_line_other
@onready var pin_other: CheckBox = $Others_panel/Pin
@onready var psyline_self: Control = $Psy_line_self
@onready var pin_self: CheckBox = $Self_panel/Pin
@onready var psyline_true: Control = $Psy_line_true
@onready var pin_true: CheckBox = $True_panel/Pin
@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
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
lets_roll(seed, 0)
roll_dice.pressed.connect(_on_roll_dice_pressed)
language_choice.get_popup().connect("id_pressed", _on_menu_language_selected)
func _process(_delta: float) -> void:
# 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:
# 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)
# Randomize psychology
if not keep_psy.button_pressed:
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)
# Randomize trait
if not keep_traits.button_pressed:
traits.build_traits()
func update_language(new_language: String) -> void:
# Change the localisation on Translation Server
TranslationServer.set_locale(new_language)
emit_signal("language_changed", new_language)
func _on_menu_language_selected(id: int) -> void:
# To call proper locale when button signal is emitted
match id:
0:
TranslationServer.set_locale("fr")
1:
TranslationServer.set_locale("en")