Add workshop related code

main
copygirl 7 months ago
parent 8ab1d8d06c
commit fdd34928e8
  1. 8
      Game.cs
  2. 4
      game.tscn
  3. 9
      player/Player.cs
  4. 11
      scenes/Workshop.cs
  5. 15
      scenes/workshop.tscn
  6. 7
      scripts/Players.cs
  7. 15
      scripts/Workshops.cs

@ -4,9 +4,13 @@ public partial class Game : Node
{
public static Game Instance { get; private set; }
public static new MultiplayerManager Multiplayer { get; private set; }
public static Players Players { get; private set; }
public static Player LocalPlayer { get; private set; }
public static Workshops Workshops { get; private set; }
public static Workshop LocalWorkshop { get; private set; }
public override void _EnterTree()
{
// Set invariant culture so formatting is consistent.
@ -14,7 +18,11 @@ public partial class Game : Node
Instance = this;
Multiplayer = this.GetNodeOrThrow<MultiplayerManager>(nameof(MultiplayerManager));
Players = this.GetNodeOrThrow<Players>(nameof(Players));
LocalPlayer = Players.Single();
Workshops = this.GetNodeOrThrow<Workshops>(nameof(Workshops));
LocalWorkshop = Workshops.Single();
}
}

@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=3 uid="uid://cqitgdxo33amx"]
[gd_scene load_steps=12 format=3 uid="uid://cqitgdxo33amx"]
[ext_resource type="Script" path="res://scripts/MultiplayerManager.cs" id="1_7shyh"]
[ext_resource type="Script" path="res://Game.cs" id="1_uywdd"]
@ -7,6 +7,7 @@
[ext_resource type="Script" path="res://scripts/Players.cs" id="4_l8q75"]
[ext_resource type="Material" uid="uid://c0q35rri3vb07" path="res://assets/shaders/outline_material.tres" id="5_a3fxj"]
[ext_resource type="Script" path="res://scripts/OutlineCamera.cs" id="5_qpc14"]
[ext_resource type="Script" path="res://scripts/Workshops.cs" id="5_rns2j"]
[ext_resource type="PackedScene" uid="uid://c5ooi36ibspfo" path="res://ui/menu.tscn" id="6_ol0j5"]
[ext_resource type="Texture2D" uid="uid://lxxfestfg2dt" path="res://assets/crosshair.png" id="7_0l5tv"]
[ext_resource type="Script" path="res://scripts/Crosshair.cs" id="8_mfhgr"]
@ -24,6 +25,7 @@ script = ExtResource("4_l8q75")
[node name="1" parent="Players" instance=ExtResource("2_iv2f7")]
[node name="Workshops" type="Node" parent="."]
script = ExtResource("5_rns2j")
[node name="1" parent="Workshops" instance=ExtResource("3_4u5ql")]

@ -1,8 +1,15 @@
public partial class Player : CharacterBody3D
{
public int PeerId => GetMultiplayerAuthority();
/// <summary> Returns whether is the local player. </summary>
public bool IsLocal => this.IsAuthority();
/// <summary> Gets the peer ID of this player. </summary>
public int PeerId => GetMultiplayerAuthority();
/// <summary> Gets the workshop owned by this player. </summary>
public Workshop Workshop => Game.Workshops.ByPeerId(PeerId);
public MovementController Movement { get; private set; }
public CameraController Camera { get; private set; }
public AnimationController Animation { get; private set; }

@ -0,0 +1,11 @@
public partial class Workshop : Area3D
{
/// <summary> Returns whether this workshop is owned by the local player. </summary>
public bool IsLocal => this.IsAuthority();
/// <summary> Gets the peer ID of the player owning this workshop. </summary>
public int PeerId => GetMultiplayerAuthority();
/// <summary> Gets the player that owns this workshop. </summary>
public Player Player => Game.Players.ByPeerId(PeerId);
}

@ -1,5 +1,6 @@
[gd_scene load_steps=14 format=3 uid="uid://bwfuet1irfi17"]
[gd_scene load_steps=16 format=3 uid="uid://bwfuet1irfi17"]
[ext_resource type="Script" path="res://scenes/Workshop.cs" id="1_i8qyc"]
[ext_resource type="Script" path="res://scenes/ItemManager.cs" id="1_l6hw6"]
[ext_resource type="PackedScene" uid="uid://yvy5vvaqgxy8" path="res://objects/crate.tscn" id="2_j6a20"]
[ext_resource type="Texture2D" uid="uid://dts3g3ivc4stn" path="res://assets/palettes/metal.png" id="3_kvstu"]
@ -9,6 +10,9 @@
[ext_resource type="PackedScene" uid="uid://bjgfm5x7a0dab" path="res://objects/bolt.tscn" id="5_r6ljd"]
[ext_resource type="PackedScene" uid="uid://54575e3ygpxl" path="res://objects/grid.tscn" id="6_okibm"]
[sub_resource type="BoxShape3D" id="BoxShape3D_q481w"]
size = Vector3(15, 5, 15)
[sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_5erfn"]
[sub_resource type="PlaneMesh" id="PlaneMesh_tg4vq"]
@ -23,11 +27,18 @@ size = Vector3(2, 0.1, 1)
[sub_resource type="BoxMesh" id="BoxMesh_efbik"]
size = Vector3(0.1, 0.9, 0.1)
[node name="Workshop" type="Node3D"]
[node name="Workshop" type="Area3D"]
collision_layer = 0
collision_mask = 0
script = ExtResource("1_i8qyc")
[node name="ItemManager" type="Node" parent="."]
script = ExtResource("1_l6hw6")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0)
shape = SubResource("BoxShape3D_q481w")
[node name="Sun" type="DirectionalLight3D" parent="."]
transform = Transform3D(0.866025, 0, -0.5, 0.25, 0.866025, 0.433013, 0.433013, -0.5, 0.75, 0, 5, 0)

@ -1,12 +1,13 @@
public partial class Players : Node
, IReadOnlyCollection<Player>
{
public int Count
=> GetChildCount();
public Player ByPeerId(int peerId)
=> this.GetNodeOrThrow<Player>(peerId.ToString());
// IReadOnlyCollection implementation
public int Count
=> GetChildCount();
public IEnumerator<Player> GetEnumerator()
=> GetChildren().Cast<Player>().GetEnumerator();
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()

@ -0,0 +1,15 @@
public partial class Workshops : Node
, IReadOnlyCollection<Workshop>
{
public Workshop ByPeerId(int peerId)
=> this.GetNodeOrThrow<Workshop>(peerId.ToString());
// IReadOnlyCollection implementation
public int Count
=> GetChildCount();
public IEnumerator<Workshop> GetEnumerator()
=> GetChildren().Cast<Workshop>().GetEnumerator();
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
=> GetEnumerator();
}
Loading…
Cancel
Save