godot-vn/game.gd

106 lines
2.3 KiB
GDScript3
Raw Normal View History

2018-09-21 02:43:57 +01:00
extends Node
2018-09-22 20:22:16 +01:00
# types of fades?
class Fade:
func _init():
pass
2018-09-21 20:03:52 +01:00
const Data = preload("res://data.gd")
2018-09-21 02:43:57 +01:00
2018-09-21 20:03:52 +01:00
# pull them into Game too
const DEFAULT_CHARS_PER_SECOND = Data.DEFAULT_CHARS_PER_SECOND
const Characters = Data.Characters
const Images = Data.Images
const Scenes = Data.Scenes
const Themes = Data.Themes
2018-09-21 02:43:57 +01:00
2018-09-21 20:03:52 +01:00
# generic game config globals
var game_started = false setget _on_game_started_set
2018-09-21 19:50:37 +01:00
var reading_speed = 1.0 setget _on_set_reading_speed
var master_vol = 50 setget _on_set_master_vol
var music_vol = 50 setget _on_set_music_vol
var sfx_vol = 50 setget _on_set_sfx_vol
2018-09-21 03:37:07 +01:00
2018-09-21 19:50:37 +01:00
# options state
signal on_reading_speed_changed(new_value)
signal on_master_volume_changed(new_value)
2018-09-21 02:43:57 +01:00
signal on_music_volume_changed(new_value)
signal on_sfx_volume_changed(new_value)
signal on_settings_enter()
signal on_settings_exit()
2018-09-21 19:50:37 +01:00
# music related
onready var music_player = get_node("music_player")
onready var sfx_player = get_node("sfx_player")
# transition node
onready var transition = get_node("trans_layer/transition")
2018-09-21 20:03:52 +01:00
# actual game state here
var current_registry
2018-09-21 18:45:08 +01:00
2018-09-21 19:50:37 +01:00
func _ready():
pass
2018-09-21 02:43:57 +01:00
func _register_functions():
2018-09-21 18:45:08 +01:00
# default VN.. functions
2018-09-21 03:11:14 +01:00
current_registry["SWITCH_SCENE"] = funcref(self, "_switch_scene_fnc")
2018-09-21 18:45:08 +01:00
current_registry["SET_BACKGROUND"] = funcref(self, "_set_background_fnc")
func _set_background_fnc(args):
if args.size() == 1:
var bg_name = args[0]
var bg_texture = load(Images[bg_name])
SceneSwitcher.current_scene.set_background(bg_texture)
2018-09-21 03:11:14 +01:00
func _switch_scene_fnc(args):
if args.size() == 1:
var scene_name = args[0]
2018-09-21 18:51:38 +01:00
var scene_path = Scenes[scene_name]
switch_scene_to(scene_path)
2018-09-21 02:43:57 +01:00
func _on_game_started_set(v):
if v and not game_started:
2018-09-21 03:11:14 +01:00
print("STARTO")
2018-09-21 02:43:57 +01:00
_on_game_start()
game_started = v
2018-09-21 19:50:37 +01:00
func _on_set_reading_speed(s):
pass
2018-09-21 19:39:08 +01:00
func _on_set_master_vol(v):
pass
func _on_set_music_vol(v):
pass
func _on_set_sfx_vol(v):
pass
2018-09-21 02:43:57 +01:00
func _on_game_start():
# all game state here
current_registry = {}
2018-09-21 19:50:37 +01:00
2018-09-21 03:11:14 +01:00
# register all de stuff
_register_functions()
2018-09-21 02:43:57 +01:00
2018-09-21 18:51:38 +01:00
# public interface sorta
2018-09-21 19:39:08 +01:00
func switch_scene_to(scene_path, fade = true):
if fade:
transition.start_transition()
yield(transition, "on_transition_time")
2018-09-21 20:14:12 +01:00
2018-09-21 18:51:38 +01:00
SceneSwitcher.goto_scene(scene_path)
2018-09-21 19:39:08 +01:00
if fade:
yield(transition, "on_transition_completed")
if SceneSwitcher.current_scene.has_method("on_scene_start"):
SceneSwitcher.current_scene.on_scene_start()
2018-09-21 19:50:37 +01:00