From 96977ac79fa38517af73d240eb4d9ac901afceb4 Mon Sep 17 00:00:00 2001 From: HumanoidSandvichDispenser Date: Sat, 1 Jun 2024 19:12:23 -0700 Subject: [PATCH] Implement factions with bitflags instead --- BoundingBoxes/BoundingBox.cs | 4 ++-- Characters/Character.cs | 4 ++-- Characters/Doc.tscn | 1 + Utils/IFaction.cs | 9 ++++++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/BoundingBoxes/BoundingBox.cs b/BoundingBoxes/BoundingBox.cs index f1972ef..5c6d377 100644 --- a/BoundingBoxes/BoundingBox.cs +++ b/BoundingBoxes/BoundingBox.cs @@ -5,6 +5,6 @@ namespace SupaLidlGame.BoundingBoxes; public abstract partial class BoundingBox : Area2D, IFaction { - [Export] - public ushort Faction { get; set; } + [Export(PropertyHint.Flags)] + public FactionName Faction { get; set; } } diff --git a/Characters/Character.cs b/Characters/Character.cs index 7a067ea..afd9ff8 100644 --- a/Characters/Character.cs +++ b/Characters/Character.cs @@ -93,8 +93,8 @@ public partial class Character : CharacterBody2D, IFaction [Export] public BoundingBoxes.Hurtbox Hurtbox { get; set; } - [Export] - public ushort Faction { get; set; } + [Export(PropertyHint.Flags)] + public FactionName Faction { get; set; } public AnimationPlayer MovementAnimation { get; set; } diff --git a/Characters/Doc.tscn b/Characters/Doc.tscn index 3643012..6e90a99 100644 --- a/Characters/Doc.tscn +++ b/Characters/Doc.tscn @@ -573,6 +573,7 @@ Sprite = NodePath("Sprite") Inventory = NodePath("Inventory") StateMachine = NodePath("StateMachine") Hurtbox = NodePath("Hurtbox") +Faction = 2 [node name="Stats" type="Node" parent="."] script = ExtResource("5_a7fiw") diff --git a/Utils/IFaction.cs b/Utils/IFaction.cs index 29e1c8d..e5902c6 100644 --- a/Utils/IFaction.cs +++ b/Utils/IFaction.cs @@ -2,13 +2,20 @@ using Godot; namespace SupaLidlGame.Utils; +[System.Flags] +public enum FactionName +{ + Player = 1, + Doc = 2, +} + public interface IFaction { /// /// The faction index that this entity belongs to. /// [Export] - public ushort Faction { get; set; } + public FactionName Faction { get; set; } public bool AlignsWith(IFaction other) {