Skip to content

Commit

Permalink
Good night, and good luck!
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisl8 committed Mar 12, 2024
1 parent ddac9c6 commit b956cb2
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 43 deletions.
8 changes: 8 additions & 0 deletions network_websocket.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var uuid_util: Resource = preload("res://addons/uuid/uuid.gd")

var ServerCamera: PackedScene = preload("res://server_camera/server_camera.tscn")

var player_focus_button: PackedScene = preload("res://server_camera/player_focus_button.tscn")


func _process(_delta: float) -> void:
if not ready_to_connect:
Expand Down Expand Up @@ -553,3 +555,9 @@ func player_joined(id: int, data: String) -> void:
# Clean up initial map data sending data in MapController to avoid memory leak
# and possible corruption if another player joins later and gets the same multiplayer_id
Globals.world_map.server_side_per_player_initial_map_data.erase(id)

# Add another "Focus to Player" button to Server
var new_player_focus_button: Button = player_focus_button.instantiate()
var server_camera: Node = get_node_or_null("/root/Main/Map/ServerCamera/")
if server_camera:
server_camera.add_child(new_player_focus_button)
40 changes: 33 additions & 7 deletions player/player.tscn
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
[gd_scene load_steps=23 format=3 uid="uid://cnckqfxi8eyk8"]
[gd_scene load_steps=22 format=3 uid="uid://cnckqfxi8eyk8"]

[ext_resource type="Script" path="res://player/player_controller.gd" id="1_ntq5g"]
[ext_resource type="Script" path="res://player/prompts.gd" id="4_8hopg"]
[ext_resource type="Script" path="res://player/player_interaction_controller.gd" id="4_rfuvf"]
[ext_resource type="Texture2D" uid="uid://cgoy7vka18x5b" path="res://player/player_atlas.png" id="5_e4w6p"]
[ext_resource type="Script" path="res://player/player_legs_manager.gd" id="5_h6bhr"]
[ext_resource type="Script" path="res://player/player_inventory_manager.gd" id="5_xpvfg"]
[ext_resource type="Script" path="res://player/save_map_button.gd" id="6_a1bjq"]
[ext_resource type="Script" path="res://player/player_leg_controller.gd" id="6_dfoja"]
[ext_resource type="Script" path="res://player/equal_two_segment_ik_controller.gd" id="7_g23pf"]
[ext_resource type="Script" path="res://player/antenna_physics_controller.gd" id="10_c7nhb"]
Expand Down Expand Up @@ -247,12 +246,39 @@ offset_top = -10.0
offset_right = 5.0
color = Color(0.431373, 0.431373, 0.431373, 1)

[node name="Save Map" type="Button" parent="CanvasLayer/Control"]
[node name="Tools" type="Control" parent="CanvasLayer"]
layout_mode = 3
anchors_preset = 0
offset_right = 40.0
offset_bottom = 40.0

[node name="Title" type="Label" parent="CanvasLayer/Tools"]
layout_mode = 0
offset_right = 40.0
offset_bottom = 23.0
text = "Tools
"

[node name="Current" type="Label" parent="CanvasLayer/Tools"]
layout_mode = 0
offset_left = -1.0
offset_top = 27.0
offset_right = 135.0
offset_bottom = 76.0
text = "Left: Mine
Right: Place Block
"

[node name="Options" type="Label" parent="CanvasLayer/Tools"]
layout_mode = 0
offset_right = 8.0
offset_bottom = 8.0
text = "Save Map"
script = ExtResource("6_a1bjq")
offset_top = 88.0
offset_right = 77.0
offset_bottom = 189.0
text = "v - Mine
b - Build
f - Pick Up
g - Drag
"

[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
z_index = -1
Expand Down
29 changes: 2 additions & 27 deletions player/player_controller.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ extends RigidBody2D

var update_synced_position: bool = false
var update_synced_rotation: bool = false

var player_spawnable_items: Array = ["Ball", "Box", "SoupMachine"]
var player_spawn_item_next: int = 0
var player_is_placing: bool = false


func _ready() -> void:
Expand Down Expand Up @@ -137,7 +137,7 @@ func add_inventory_data(data: Dictionary) -> void:
inventory_manager.add_data(data)


func _spawn_item() -> 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)
Expand All @@ -146,31 +146,6 @@ func _spawn_item() -> void:
)


func _input(event: InputEvent) -> void:
if event.is_action_pressed(&"craft"):
Globals.player_has_done.press_craft_button = true
player_is_placing = true
_spawn_item()
elif event.is_action_released(&"craft"):
player_is_placing = false
$"Interaction Controller".de_spawn_placing_item.rpc()
if event is InputEventMouseButton:
if event.button_index == 4 and event.pressed and player_is_placing:
# Scroll Up
player_spawn_item_next += 1
if player_spawn_item_next > player_spawnable_items.size() - 1:
player_spawn_item_next = 0
$"Interaction Controller".de_spawn_placing_item.rpc()
_spawn_item()
elif event.button_index == 5 and event.pressed and player_is_placing:
# Scroll Down
player_spawn_item_next -= 1
if player_spawn_item_next < 0:
player_spawn_item_next = player_spawnable_items.size() - 1
$"Interaction Controller".de_spawn_placing_item.rpc()
_spawn_item()


func _on_personal_space_body_entered(body: Node2D) -> void:
if is_multiplayer_authority() and body.has_method("nearby"):
if is_multiplayer_authority():
Expand Down
26 changes: 26 additions & 0 deletions player/player_interaction_controller.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ 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
var left_hand_tool: String = "Mine"


func update_mining_particle_length() -> void:
Expand Down Expand Up @@ -175,6 +176,11 @@ func de_spawn_placing_item() -> void:


func _input(event: InputEvent) -> void:
var previous_left_hand_tool: String = left_hand_tool
if event.is_action_released(&"build"):
left_hand_tool = "Build"
Globals.player_has_done.press_craft_button = true
owner.spawn_item()
if event is InputEventMouseButton:
if event.button_index == 1 and event.is_pressed():
mouse_left_down = true
Expand All @@ -183,6 +189,26 @@ func _input(event: InputEvent) -> void:
elif event.button_index == 2 and event.is_pressed():
right_mouse_clicked()

if left_hand_tool == "Build":
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:
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
de_spawn_placing_item.rpc()
owner.spawn_item()
if previous_left_hand_tool != left_hand_tool:
# Tool changed
if previous_left_hand_tool == "Build":
de_spawn_placing_item.rpc()


func mine_raycast() -> void:
if current_mining_time > mining_speed:
Expand Down
9 changes: 0 additions & 9 deletions player/save_map_button.gd

This file was deleted.

4 changes: 4 additions & 0 deletions server_camera/player_focus_button.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[gd_scene format=3 uid="uid://dt0wy64nq1yqr"]

[node name="PlayerFocusButton" type="Button"]
text = "Focus On ???"

0 comments on commit b956cb2

Please sign in to comment.