Skip to content

Commit

Permalink
Set GDScript formatter and linter line length to 100 not 80 . . . thi…
Browse files Browse the repository at this point in the history
…s should be in a config file really.
  • Loading branch information
chrisl8 committed Mar 24, 2024
1 parent ed089de commit 93f7519
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 161 deletions.
20 changes: 4 additions & 16 deletions items/disc/disc.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@ 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,13 +48,7 @@ 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)
24 changes: 5 additions & 19 deletions items/soup_machine/soup_machine.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ func _ready() -> void:
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,17 +19,11 @@ 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 @@ -60,13 +52,7 @@ 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)
20 changes: 4 additions & 16 deletions items/square/square.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@ 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,14 +51,8 @@ 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)
30 changes: 7 additions & 23 deletions player/player_controller.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ func _ready() -> void:

$"Interaction Controller".initialize(player == multiplayer.get_unique_id())
$"Inventory Manager".initialize(player == multiplayer.get_unique_id())
$"Player Canvas/Control/Prompt".initialize(
player == multiplayer.get_unique_id()
)
$"Player Canvas/Control/Prompt".initialize(player == multiplayer.get_unique_id())

set_process(player == multiplayer.get_unique_id())
set_physics_process(player == multiplayer.get_unique_id())
Expand Down Expand Up @@ -66,17 +64,11 @@ 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)
)
):
Network.reset_connection()
Expand All @@ -93,14 +85,10 @@ func _physics_process(delta: float) -> void:
var damp: float = 5000.0
var dampening: float = velocity.x
if velocity.x < 0.0:
dampening = (
velocity.x - (damp * delta) * (velocity.x / abs(velocity.x))
)
dampening = (velocity.x - (damp * delta) * (velocity.x / abs(velocity.x)))
dampening = clamp(dampening, velocity.x, 0.0)
elif velocity.x > 0:
dampening = (
velocity.x - (damp * delta) * (velocity.x / abs(velocity.x))
)
dampening = (velocity.x - (damp * delta) * (velocity.x / abs(velocity.x)))
dampening = clamp(dampening, 0.0, velocity.x)

velocity = Vector2(dampening, velocity.y)
Expand Down Expand Up @@ -134,9 +122,7 @@ func _integrate_forces(state: PhysicsDirectBodyState2D) -> void:
if update_synced_position and update_synced_rotation:
state.transform = Transform2D(synced_rotation, synced_position)
elif update_synced_position:
state.transform = Transform2D(
state.transform.get_rotation(), synced_position
)
state.transform = Transform2D(state.transform.get_rotation(), synced_position)
elif update_synced_rotation:
state.transform = Transform2D(synced_rotation, state.origin)
update_synced_position = false
Expand All @@ -152,9 +138,7 @@ func add_inventory_data(data: Dictionary) -> void:
func spawn_item() -> void:
var rng: RandomNumberGenerator = RandomNumberGenerator.new()
var id: int = rng.randi()
var thing_name_to_spawn: String = str(
player_spawnable_items[player_spawn_item_next], "-", id
)
var thing_name_to_spawn: String = str(player_spawnable_items[player_spawn_item_next], "-", id)
$"Interaction Controller".spawn_player_controlled_thing.rpc(
Vector2.ZERO, 0, thing_name_to_spawn, "Placing"
)
Expand Down
88 changes: 21 additions & 67 deletions player/player_interaction_controller.gd
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,14 @@ var tool_speed: float = 0.1
var current_tool_raycast_time: float = 100
var ball: Resource = preload("res://items/disc/disc.tscn")
var box: Resource = preload("res://items/square/square.tscn")
var soup_machine: Resource = preload(
"res://items/soup_machine/soup_machine.tscn"
)
var soup_machine: Resource = preload("res://items/soup_machine/soup_machine.tscn")
var controlled_item: RigidBody2D
var controlled_item_type: String = "Held"
var controlled_item_clear_of_collisions: bool = false


func update_mining_particle_length() -> void:
var extents: Vector3 = mining_particles.process_material.get(
"emission_box_extents"
)
var extents: Vector3 = mining_particles.process_material.get("emission_box_extents")
extents.x = mining_distance

mining_particles.process_material.set("emission_box_extents", extents)
Expand Down Expand Up @@ -90,9 +86,7 @@ func _process(delta: float) -> void:

arm_id_controller.target = mouse_position
head.look_at(mouse_position)
mining_particles.emitting = (
left_hand_tool_is_active and left_hand_tool == Globals.Tools.MINE
)
mining_particles.emitting = (left_hand_tool_is_active and left_hand_tool == Globals.Tools.MINE)

if controlled_item:
# Picked Up items drop when you release the mouse button because they "exist" already.
Expand All @@ -107,12 +101,8 @@ func _process(delta: float) -> void:
controlled_item.set_position(to_local(mouse_position))
elif is_multiplayer_authority():
var held_item_name: String = controlled_item.name
var held_item_global_position: Vector2 = (
controlled_item.global_position
)
Spawner.place_thing.rpc_id(
1, held_item_name, held_item_global_position
)
var held_item_global_position: Vector2 = controlled_item.global_position
Spawner.place_thing.rpc_id(1, held_item_name, held_item_global_position)
_drop_held_thing.rpc()
elif controlled_item_type == "Placing":
if (
Expand All @@ -122,12 +112,8 @@ func _process(delta: float) -> void:
):
Globals.player_has_done.built_an_item = true
var held_item_name: String = controlled_item.name
var held_item_global_position: Vector2 = (
controlled_item.global_position
)
Spawner.place_thing.rpc_id(
1, held_item_name, held_item_global_position
)
var held_item_global_position: Vector2 = controlled_item.global_position
Spawner.place_thing.rpc_id(1, held_item_name, held_item_global_position)
_drop_held_thing.rpc()
Globals.world_map.delete_drawing_canvas(held_item_name)
else:
Expand All @@ -142,9 +128,7 @@ func _process(delta: float) -> void:
controlled_item.name
)
)
controlled_item_clear_of_collisions = (
intersecting_tiles.all_tiles_are_empty
)
controlled_item_clear_of_collisions = (intersecting_tiles.all_tiles_are_empty)


#Re-add when arms sometimes need to target other locations
Expand All @@ -153,11 +137,7 @@ func _process(delta: float) -> void:
@rpc("call_local")
func _drop_held_thing() -> void:
Helpers.log_print(
str(
controlled_item.name,
" dropped by ",
multiplayer.get_remote_sender_id()
),
str(controlled_item.name, " dropped by ", multiplayer.get_remote_sender_id()),
"Cornflowerblue"
)
if controlled_item:
Expand Down Expand Up @@ -207,20 +187,15 @@ func _input(event: InputEvent) -> void:
if event.button_index == 4 and event.pressed:
# Scroll Up
owner.player_spawn_item_next += 1
if (
owner.player_spawn_item_next
> owner.player_spawnable_items.size() - 1
):
if owner.player_spawn_item_next > owner.player_spawnable_items.size() - 1:
owner.player_spawn_item_next = 0
de_spawn_placing_item.rpc()
owner.spawn_item()
elif event.button_index == 5 and event.pressed:
# Scroll Down
owner.player_spawn_item_next -= 1
if owner.player_spawn_item_next < 0:
owner.player_spawn_item_next = (
owner.player_spawnable_items.size() - 1
)
owner.player_spawn_item_next = (owner.player_spawnable_items.size() - 1)
de_spawn_placing_item.rpc()
owner.spawn_item()
if previous_left_hand_tool != left_hand_tool:
Expand All @@ -232,15 +207,11 @@ func _input(event: InputEvent) -> void:
func tool_raycast() -> void:
if current_tool_raycast_time > tool_speed:
current_tool_raycast_time = 0.0
var space_state: PhysicsDirectSpaceState2D = (
get_world_2d().direct_space_state
)
var space_state: PhysicsDirectSpaceState2D = get_world_2d().direct_space_state
var arm_position: Vector2 = arm_id_controller.global_position
var mining_particle_distance: float = (
clamp(
clamp(
arm_position.distance_to(mouse_position), 0, INTERACT_RANGE
),
clamp(arm_position.distance_to(mouse_position), 0, INTERACT_RANGE),
0.0,
mining_particles.global_position.distance_to(mouse_position)
)
Expand All @@ -250,19 +221,15 @@ func tool_raycast() -> void:
arm_position
+ (
(mouse_position - arm_position).normalized()
* clamp(
arm_position.distance_to(mouse_position), 0, INTERACT_RANGE
)
* clamp(arm_position.distance_to(mouse_position), 0, INTERACT_RANGE)
)
)
var query: PhysicsRayQueryParameters2D = (
PhysicsRayQueryParameters2D.create(arm_position, target_position)
var query: PhysicsRayQueryParameters2D = PhysicsRayQueryParameters2D.create(
arm_position, target_position
)
if left_hand_tool == Globals.Tools.MINE: # Only show the "laser" if mining
# LASER DRILL!!! ==>-----
Globals.world_map.draw_temp_line_on_map(
arm_position, target_position, Color.RED
)
Globals.world_map.draw_temp_line_on_map(arm_position, target_position, Color.RED)
query.exclude = [self]
var result: Dictionary = space_state.intersect_ray(query)
if result.size() > 0:
Expand All @@ -281,9 +248,7 @@ func tool_raycast() -> void:

if left_hand_tool == Globals.Tools.MINE:
if result["collider"] is TileMap and not controlled_item: # Do not mine while holding items, no matter what
Globals.world_map.mine_cell_at_position(
hit_point - result["normal"]
)
Globals.world_map.mine_cell_at_position(hit_point - result["normal"])
elif left_hand_tool == Globals.Tools.PICKUP:
if not controlled_item and result["collider"] is RigidBody2D: # You are ALREADY holding an item, you cannot hold two items. # You can currently only pick up RigidBodies.
var body: Node = result["collider"]
Expand Down Expand Up @@ -325,22 +290,12 @@ func spawn_player_controlled_thing(
# We can never control a new thing if we are already controlling something
# Whoever called this should have called de_spawn_placing_item() first if they were serious
return
var parsed_thing_name: Dictionary = Helpers.parse_thing_name(
controlled_item_name
)
var parsed_thing_name: Dictionary = Helpers.parse_thing_name(controlled_item_name)
var action: String = "picked up"
if spawned_item_type == "Placing":
action = "being placed"
Helpers.log_print(
str(
parsed_thing_name.name,
" ",
parsed_thing_name.id,
" ",
action,
" by ",
name
),
str(parsed_thing_name.name, " ", parsed_thing_name.id, " ", action, " by ", name),
"Cornflowerblue"
)
# Spawn a local version for myself
Expand All @@ -354,8 +309,7 @@ func spawn_player_controlled_thing(
controlled_item = soup_machine.instantiate()
_:
printerr(
"Invalid thing to spawn name into player held position: ",
parsed_thing_name.name
"Invalid thing to spawn name into player held position: ", parsed_thing_name.name
)
return
controlled_item_type = spawned_item_type
Expand Down
Loading

0 comments on commit 93f7519

Please sign in to comment.