Skip to content

Commit

Permalink
Look at Me, doing OOP!
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisl8 committed Mar 24, 2024
1 parent 71b36df commit 5240c86
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 38 deletions.
1 change: 1 addition & 0 deletions global_variables.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extends Node

enum Tools { MINE, BUILD, PICKUP, DRAG }
enum ItemTypes { FREE, STRUCTURE }

var server_config: Dictionary = {}
var server_player_save_data_file_name: String = "user://server_player_data.dat"
Expand Down
26 changes: 17 additions & 9 deletions items/disc/disc.gd
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
extends RigidBody2D

@export var spawn_position: Vector2
@export var width_in_tiles: int = 2
@export var height_in_tiles: int = 2
extends RigidBody2dItem


func _ready() -> void:
Expand All @@ -19,11 +15,17 @@ func _physics_process(_delta: float) -> void:
if (
(
abs(position.x)
> Globals.world_map.max_radius_in_tiles * Globals.world_map.single_tile_width
> (
Globals.world_map.max_radius_in_tiles
* Globals.world_map.single_tile_width
)
)
or (
abs(position.y)
> Globals.world_map.max_radius_in_tiles * Globals.world_map.single_tile_width
> (
Globals.world_map.max_radius_in_tiles
* Globals.world_map.single_tile_width
)
)
):
queue_free()
Expand Down Expand Up @@ -52,10 +54,16 @@ func grab() -> void:
queue_free()
# Once that is done, tell the player node that grabbed me to spawn a "held" version
var player: Node = get_node_or_null(
str("/root/Main/Players/", multiplayer.get_remote_sender_id(), "/Interaction Controller")
str(
"/root/Main/Players/",
multiplayer.get_remote_sender_id(),
"/Interaction Controller"
)
)
if player and player.has_method("spawn_player_controlled_thing"):
player.spawn_player_controlled_thing.rpc(global_position, global_rotation, name)
player.spawn_player_controlled_thing.rpc(
global_position, global_rotation, name
)


var WaitingToSetLocation = false
Expand Down
8 changes: 8 additions & 0 deletions items/rigid_body_2d_item.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class_name RigidBody2dItem
extends RigidBody2D

@export var spawn_position: Vector2
@export var width_in_tiles: int = 2
@export var height_in_tiles: int = 2
@export var item_type: Globals.ItemTypes = Globals.ItemTypes.FREE
@export var snaps: bool = false
36 changes: 24 additions & 12 deletions items/soup_machine/soup_machine.gd
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
extends RigidBody2D

@export var spawn_position: Vector2
@export var width_in_tiles: int = 4
@export var height_in_tiles: int = 4

var item_type: String = "Entity"
extends RigidBody2dItem


func _ready() -> void:
item_type = Globals.ItemTypes.STRUCTURE
snaps = true
width_in_tiles = 4
height_in_tiles = 4
set_physics_process(is_multiplayer_authority())
if Globals.is_server and spawn_position:
position = spawn_position
Helpers.log_print(str("Setting Soup Machine position to ", spawn_position))
Helpers.log_print(
str("Setting Soup Machine position to ", spawn_position)
)


func _physics_process(_delta: float) -> void:
Expand All @@ -21,11 +21,17 @@ func _physics_process(_delta: float) -> void:
if (
(
abs(position.x)
> Globals.world_map.max_radius_in_tiles * Globals.world_map.single_tile_width
> (
Globals.world_map.max_radius_in_tiles
* Globals.world_map.single_tile_width
)
)
or (
abs(position.y)
> Globals.world_map.max_radius_in_tiles * Globals.world_map.single_tile_width
> (
Globals.world_map.max_radius_in_tiles
* Globals.world_map.single_tile_width
)
)
):
queue_free()
Expand Down Expand Up @@ -54,10 +60,16 @@ func grab() -> void:
queue_free()
# Once that is done, tell the player node that grabbed me to spawn a "held" version
var player: Node = get_node_or_null(
str("/root/Main/Players/", multiplayer.get_remote_sender_id(), "/Interaction Controller")
str(
"/root/Main/Players/",
multiplayer.get_remote_sender_id(),
"/Interaction Controller"
)
)
if player and player.has_method("spawn_player_controlled_thing"):
player.spawn_player_controlled_thing.rpc(global_position, global_rotation, name)
player.spawn_player_controlled_thing.rpc(
global_position, global_rotation, name
)


var WaitingToSetLocation = false
Expand Down
28 changes: 17 additions & 11 deletions items/square/square.gd
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
extends RigidBody2D

@export var spawn_position: Vector2
@export var width_in_tiles: int = 2
@export var height_in_tiles: int = 2

var item_type: String = "Entity"
extends RigidBody2dItem


func _ready() -> void:
Expand All @@ -21,11 +15,17 @@ func _physics_process(_delta: float) -> void:
if (
(
abs(position.x)
> Globals.world_map.max_radius_in_tiles * Globals.world_map.single_tile_width
> (
Globals.world_map.max_radius_in_tiles
* Globals.world_map.single_tile_width
)
)
or (
abs(position.y)
> Globals.world_map.max_radius_in_tiles * Globals.world_map.single_tile_width
> (
Globals.world_map.max_radius_in_tiles
* Globals.world_map.single_tile_width
)
)
):
queue_free()
Expand Down Expand Up @@ -57,11 +57,17 @@ func grab() -> void:
queue_free()
# Once that is done, tell the player node that grabbed me to spawn a "held" version
var player: Node = get_node_or_null(
str("/root/Main/Players/", multiplayer.get_remote_sender_id(), "/Interaction Controller")
str(
"/root/Main/Players/",
multiplayer.get_remote_sender_id(),
"/Interaction Controller"
)
)
if player and player.has_method("spawn_player_controlled_thing"):
print(global_position)
player.spawn_player_controlled_thing.rpc(global_position, global_rotation, name)
player.spawn_player_controlled_thing.rpc(
global_position, global_rotation, name
)


var WaitingToSetLocation = false
Expand Down
6 changes: 0 additions & 6 deletions player/player_controller.gd
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ func _ready() -> void:
space, PhysicsServer2D.SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION, 0.0
)

Helpers.log_print(
str(
"player_controller ready_: player == multiplayer.get_unique_id(): ",
player == multiplayer.get_unique_id()
)
)
$"Interaction Controller".initialize(player == multiplayer.get_unique_id())
$"Inventory Manager".initialize(player == multiplayer.get_unique_id())
$"Player Canvas/Control/Prompt".initialize(
Expand Down

0 comments on commit 5240c86

Please sign in to comment.