Skip to content

Commit

Permalink
Review and update the GameManager and create a PlayerManager for #15.
Browse files Browse the repository at this point in the history
  • Loading branch information
Makosai committed Apr 8, 2024
1 parent 9036cc4 commit f72ffc4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 40 deletions.
1 change: 1 addition & 0 deletions godot/scenes/misc/managers.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ offset_bottom = 40.0
text = "FPS: N/A"

[node name="GameManager" type="Node" parent="."]
process_mode = 4
script = ExtResource("1_scrx5")

[node name="UIManager" type="Node" parent="."]
Expand Down
63 changes: 23 additions & 40 deletions godot/scenes/misc/scripts/managers/game_manager.gd
Original file line number Diff line number Diff line change
@@ -1,55 +1,38 @@
class_name GameManager extends Node
## This is the main game manager. It handles the game state, FPS, and window size.

# TODO: Re-enable
# var myPlayer = preload("res://scripts/mob/attackable/player/my_player.tscn")
# var player: Player
static var instance: GameManager

static var current_ui: UI_TYPES = UI_TYPES.MAIN_MENU :
static var state: GAME_STATES = GAME_STATES.MENU:
set(value):
current_ui = _on_current_ui_change(value)
state = value

match value:
UI_TYPES.PLAY:
GAME_STATES.PLAY:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
_:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
update_fps()
get:
return current_ui
static func _on_current_ui_change(value: UI_TYPES) -> UI_TYPES: return value
enum UI_TYPES { PLAY, PAUSE, MAIN_MENU, INVENTORY }

static var instance: GameManager
return state
enum GAME_STATES {MENU, PLAY, PAUSE}

# Singleton
func _init():
if instance == null:
instance = self
else:
self.queue_free()
queue_free()
free()

func _ready():
GameManager.update_fps()
GameManager.setup_sound_manager()
GameManager.set_window_size()

func load_player():
print(get_node("/root/Map_Reia"))

if !get_tree().get_current_scene().is_in_group("map"):
print("The current scene is not a map. Can't load the player.")

var map = get_tree().get_current_scene() as MapHandler

var newPlayer := myPlayer.instantiate() as Player

if !Engine.is_editor_hint() && GameManager.instance.player == null:
print("Setting player")
## GameManager.instance.player = newPlayer
## map.players.add_child(newPlayer)

# Handles releasing and capturing the mouse
func _input(_event: InputEvent):
# Let the UI handle the rest
if current_ui != UI_TYPES.PLAY:
if state != GAME_STATES.PLAY:
return

if Input.is_action_just_pressed("quit"):
Expand All @@ -64,25 +47,25 @@ func _input(_event: InputEvent):
print("click")

static func toggle_pause():
match current_ui:
UI_TYPES.PLAY:
current_ui = UI_TYPES.PAUSE
UI_TYPES.PAUSE:
current_ui = UI_TYPES.PLAY
match state:
GAME_STATES.PLAY:
state = GAME_STATES.PAUSE
GAME_STATES.PAUSE:
state = GAME_STATES.PLAY

static func update_fps():
var max_fps = Constants.GAME_DEFAULT_FPS if current_ui == UI_TYPES.PLAY else Constants.UI_DEFAULT_FPS
var max_fps = Constants.GAME_DEFAULT_FPS if state == GAME_STATES.PLAY else Constants.UI_DEFAULT_FPS
print("FPS: ", max_fps)
Engine.set_max_fps(max_fps)

static func set_window_size():
DisplayServer.window_set_min_size(Vector2i(1152, 648))

static func setup_sound_manager():
SoundManager.set_default_music_bus("Music")
SoundManager.set_default_sound_bus("SFX")
SoundManager.set_default_ui_sound_bus("Interface")
SoundManager.set_default_dialogue_bus("Dialogue")

# Temp
SoundManager.set_master_volume(5.0/100.0)

static func set_window_size():
DisplayServer.window_set_min_size(Vector2i(1152, 648))
# Temporary
SoundManager.set_master_volume(5.0 / 100.0)
22 changes: 22 additions & 0 deletions godot/scenes/misc/scripts/managers/player_manager.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
extends Node
## This should be scrapped and instead placed in the Player script itself.
## More designing is required.

# TODO: Re-enable
# var myPlayer = preload("res://scripts/mob/attackable/player/my_player.tscn")
# var player: Player

func load_player():
print(get_node("/root/Map_Reia"))

if !get_tree().get_current_scene().is_in_group("map"):
print("The current scene is not a map. Can't load the player.")

var map = get_tree().get_current_scene() as MapHandler

# var newPlayer := myPlayer.instantiate() as Player

if !Engine.is_editor_hint()&&GameManager.instance.player == null:
print("Setting player")
## GameManager.instance.player = newPlayer
## map.players.add_child(newPlayer)

0 comments on commit f72ffc4

Please sign in to comment.