Push project up
This commit is contained in:
12
scripts/data/data_bridge.tscn
Normal file
12
scripts/data/data_bridge.tscn
Normal file
@@ -0,0 +1,12 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://dy51wny4x53f4"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://52eithlmedm3" path="res://scripts/data/game_data.gd" id="1_hulqm"]
|
||||
[ext_resource type="Script" uid="uid://bs4vblwa3u5jq" path="res://scripts/data/multiplayer_data.gd" id="4_setx2"]
|
||||
|
||||
[node name="data_bridge" type="Node"]
|
||||
|
||||
[node name="game_data" type="Node" parent="."]
|
||||
script = ExtResource("1_hulqm")
|
||||
|
||||
[node name="multiplayer_data" type="Node" parent="."]
|
||||
script = ExtResource("4_setx2")
|
||||
34
scripts/data/game_data.gd
Normal file
34
scripts/data/game_data.gd
Normal file
@@ -0,0 +1,34 @@
|
||||
class_name GameData extends Node
|
||||
|
||||
|
||||
var client1: int
|
||||
var client2: int
|
||||
var player_id: String = ""
|
||||
|
||||
var game_address: String = "0.0.0.0"
|
||||
var game_port: int = 8080
|
||||
var game_mode: String = ""
|
||||
|
||||
enum PlayerType {
|
||||
Player1,
|
||||
Player2
|
||||
}
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
Globals.game_data = self
|
||||
|
||||
@rpc("authority", "reliable")
|
||||
func set_game_address(address: String) -> void:
|
||||
game_address = address
|
||||
|
||||
@rpc("authority", "reliable")
|
||||
func set_game_port(port: String) -> void:
|
||||
game_port = int(port)
|
||||
|
||||
|
||||
func set_game_mode(_mode: String) -> void:
|
||||
pass
|
||||
|
||||
func set_player_id(is_player_1: bool) -> void:
|
||||
player_id = "Player 1" if is_player_1 else "Player 2"
|
||||
1
scripts/data/game_data.gd.uid
Normal file
1
scripts/data/game_data.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://52eithlmedm3
|
||||
63
scripts/data/game_state.gd
Normal file
63
scripts/data/game_state.gd
Normal file
@@ -0,0 +1,63 @@
|
||||
class_name GameState extends Node
|
||||
|
||||
|
||||
@warning_ignore_start("unused_signal")
|
||||
signal update_cue_cam_position
|
||||
|
||||
signal balls_stopped_moving
|
||||
signal white_ball_sunk
|
||||
signal white_ball_needs_hard_reset
|
||||
signal reload_scene
|
||||
signal process_ball
|
||||
signal reap_ball
|
||||
@warning_ignore_restore("unused_signal")
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
Globals.game_state = self
|
||||
|
||||
func load_game_scene(scene_str: String) -> void:
|
||||
var scene = load(scene_str).instantiate()
|
||||
var target = get_tree().root.get_node_or_null("shell/scene")
|
||||
|
||||
if not target:
|
||||
target = get_tree().root.get_node("game_core/scene")
|
||||
|
||||
target.add_child(scene)
|
||||
|
||||
func set_game_scene(scene_str: String) -> void:
|
||||
var scene = load(scene_str).instantiate()
|
||||
var target = get_tree().root.get_node_or_null("shell/scene")
|
||||
|
||||
if not target:
|
||||
target = get_tree().root.get_node("game_core/scene")
|
||||
|
||||
if "game" in scene_str:
|
||||
scene.name = "game"
|
||||
elif "lobby" in scene_str:
|
||||
scene.name = "lobby_screen"
|
||||
elif "start" in scene_str:
|
||||
scene.name = "start_screen"
|
||||
|
||||
clear_game_scene(target)
|
||||
|
||||
target.add_child(scene)
|
||||
|
||||
func clear_game_scene(container: Node) -> void:
|
||||
for child in container.get_children():
|
||||
child.queue_free()
|
||||
|
||||
await get_tree().process_frame
|
||||
|
||||
func switch_active_player() -> void:
|
||||
# TODO: Move away from using client ID or mask it with a map ID
|
||||
if Globals.multiplayer_data.current_turn_player_id == Globals.game_data.client1:
|
||||
Globals.multiplayer_data.rpc(
|
||||
"set_active_player_id",
|
||||
Globals.game_data.client2
|
||||
)
|
||||
elif Globals.multiplayer_data.current_turn_player_id == Globals.game_data.client2:
|
||||
Globals.multiplayer_data.rpc(
|
||||
"set_active_player_id",
|
||||
Globals.game_data.client1
|
||||
)
|
||||
1
scripts/data/game_state.gd.uid
Normal file
1
scripts/data/game_state.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://rol2c8o8q2ty
|
||||
16
scripts/data/multiplayer_data.gd
Normal file
16
scripts/data/multiplayer_data.gd
Normal file
@@ -0,0 +1,16 @@
|
||||
class_name MultiplayerData extends Node
|
||||
|
||||
|
||||
var is_multiplayer_active: bool = false
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
Globals.multiplayer_data = self
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func set_multiplayer_active() -> void:
|
||||
is_multiplayer_active = true
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func set_active_player_id(_id: int) -> void:
|
||||
pass
|
||||
1
scripts/data/multiplayer_data.gd.uid
Normal file
1
scripts/data/multiplayer_data.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bs4vblwa3u5jq
|
||||
Reference in New Issue
Block a user