From c8ac0438b63811a3e9946b79b9a58f717d5a52b3 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Thu, 13 Nov 2025 15:22:21 +0100 Subject: [PATCH] Core - Made AbstarctGameRules public --- PckStudio.Core/GameRule/AbstractGameRule.cs | 8 ++++++++ PckStudio.Core/GameRule/DistributeItems.cs | 10 +++++----- PckStudio.Core/GameRule/LevelRules.cs | 14 +++++++++++--- PckStudio.Core/GameRule/NamedArea.cs | 17 ++++++++++------- .../GameRule/OnGameStartSpawnPositions.cs | 2 +- PckStudio.Core/GameRule/OnInitialiseWorld.cs | 2 +- PckStudio.Core/GameRule/RootGameRule.cs | 2 +- PckStudio.Core/GameRule/SpawnPositionSet.cs | 3 ++- PckStudio.Core/GameRule/UpdatePlayer.cs | 10 +++++----- 9 files changed, 44 insertions(+), 24 deletions(-) diff --git a/PckStudio.Core/GameRule/AbstractGameRule.cs b/PckStudio.Core/GameRule/AbstractGameRule.cs index a32f4085..8714465c 100644 --- a/PckStudio.Core/GameRule/AbstractGameRule.cs +++ b/PckStudio.Core/GameRule/AbstractGameRule.cs @@ -21,9 +21,17 @@ namespace PckStudio.Core.GameRule gameRule.AddRules(a); return gameRule; } + public static implicit operator GameRuleFile.GameRule(AbstractGameRule abstractGameRule) { return abstractGameRule.InternalGetGameRule(); } + + public static implicit operator GameRuleFile(AbstractGameRule abstractGameRule) + { + var grf = new GameRuleFile(); + grf.AddGameRules(abstractGameRule._gameRules.Select(agr => agr.InternalGetGameRule())); + return grf; + } } } diff --git a/PckStudio.Core/GameRule/DistributeItems.cs b/PckStudio.Core/GameRule/DistributeItems.cs index 189e837c..e86c70e2 100644 --- a/PckStudio.Core/GameRule/DistributeItems.cs +++ b/PckStudio.Core/GameRule/DistributeItems.cs @@ -7,9 +7,9 @@ using OMI.Formats.GameRule; namespace PckStudio.Core.GameRule { - internal sealed class DistributeItems : AbstractGameRule + public sealed class DistributeItems : AbstractGameRule { - private static string[] _strings = + private static string[] _idStrings = { "StartItems", "OuterItems", @@ -24,9 +24,9 @@ namespace PckStudio.Core.GameRule } private DistributeItemsId _id; - internal void AddPosition(int x, int y, int z) => AddRule(new WorldPosition(x, y, z)); + public void AddPosition(int x, int y, int z) => AddRule(new WorldPosition(x, y, z)); - public DistributeItems(DistributeItemsId id) + internal DistributeItems(DistributeItemsId id) { _id = id; } @@ -34,7 +34,7 @@ namespace PckStudio.Core.GameRule protected override GameRuleFile.GameRule GetGameRule() { var gameRule = new GameRuleFile.GameRule("DistributeItems"); - gameRule.AddParameter(new GameRuleFile.GameRuleParameter("id", _strings[(int)_id])); + gameRule.AddParameter(new GameRuleFile.GameRuleParameter("id", _idStrings[(int)_id])); return gameRule; } } diff --git a/PckStudio.Core/GameRule/LevelRules.cs b/PckStudio.Core/GameRule/LevelRules.cs index 1f08e945..3ad79d8c 100644 --- a/PckStudio.Core/GameRule/LevelRules.cs +++ b/PckStudio.Core/GameRule/LevelRules.cs @@ -8,22 +8,30 @@ using OMI.Formats.GameRule; namespace PckStudio.Core.GameRule { - internal sealed class LevelRules : AbstractGameRule + public sealed class LevelRules : AbstractGameRule { private readonly GameRuleFile.GameRuleParameter[] _parameters; + private readonly MiniGameId _miniGameId; public static LevelRules GetDefault(Vector3 pos, Vector2 rot) => new LevelRules([new UpdatePlayer(pos, rot)]); - public static LevelRules GetMiniGameLevelRules(MiniGameId miniGame) => new LevelRules(Enumerable.Empty(), new GameRuleFile.IntParameter("ruleType", (int)miniGame)); + public static LevelRules GetMiniGameLevelRules(MiniGameId miniGame) => new LevelRules(miniGame); - public LevelRules(IEnumerable gameRules, params GameRuleFile.GameRuleParameter[] parameters) + public LevelRules(IEnumerable gameRules, MiniGameId miniGameId, params GameRuleFile.GameRuleParameter[] parameters) { AddRules(gameRules); _parameters = parameters; + _miniGameId = miniGameId; } + public LevelRules(IEnumerable gameRules, params GameRuleFile.GameRuleParameter[] parameters) : this(gameRules, MiniGameId.None, parameters) { } + + public LevelRules(MiniGameId miniGameId) : this(Enumerable.Empty(), miniGameId) { } + protected override GameRuleFile.GameRule GetGameRule() { var gameRule = new GameRuleFile.GameRule("LevelRules"); + if (_miniGameId != MiniGameId.None) + gameRule.AddParameter(new GameRuleFile.IntParameter("ruleType", (int)_miniGameId)); gameRule.AddParameters(_parameters); return gameRule; } diff --git a/PckStudio.Core/GameRule/NamedArea.cs b/PckStudio.Core/GameRule/NamedArea.cs index cfdb6d3e..af115c0c 100644 --- a/PckStudio.Core/GameRule/NamedArea.cs +++ b/PckStudio.Core/GameRule/NamedArea.cs @@ -5,6 +5,7 @@ using System.Numerics; using System.Text; using System.Threading.Tasks; using OMI.Formats.GameRule; +using PckStudio.Core.Extensions; namespace PckStudio.Core.GameRule { @@ -22,17 +23,19 @@ namespace PckStudio.Core.GameRule End = end; } + public NamedArea(string name, BoundingBox boundingBox) : this(name, boundingBox.Start.ToNumericsVector(), boundingBox.End.ToNumericsVector()) { } + protected override GameRuleFile.GameRule GetGameRule() { - GameRuleFile.GameRule gameRule = new GameRuleFile.GameRule("NamedArea", null); + GameRuleFile.GameRule gameRule = new GameRuleFile.GameRule("NamedArea"); gameRule.AddParameters( new GameRuleFile.GameRuleParameter("name", Name), - new GameRuleFile.IntParameter("x0", (int)Start.X), - new GameRuleFile.IntParameter("y0", (int)Start.Y), - new GameRuleFile.IntParameter("z0", (int)Start.Z), - new GameRuleFile.IntParameter("x1", (int)End.X), - new GameRuleFile.IntParameter("y1", (int)End.Y), - new GameRuleFile.IntParameter("z1", (int)End.Z) + new GameRuleFile.FloatParameter("x0", Start.X), + new GameRuleFile.FloatParameter("y0", Start.Y), + new GameRuleFile.FloatParameter("z0", Start.Z), + new GameRuleFile.FloatParameter("x1", End.X), + new GameRuleFile.FloatParameter("y1", End.Y), + new GameRuleFile.FloatParameter("z1", End.Z) ); return gameRule; } diff --git a/PckStudio.Core/GameRule/OnGameStartSpawnPositions.cs b/PckStudio.Core/GameRule/OnGameStartSpawnPositions.cs index cf66e3a0..d1eacbd1 100644 --- a/PckStudio.Core/GameRule/OnGameStartSpawnPositions.cs +++ b/PckStudio.Core/GameRule/OnGameStartSpawnPositions.cs @@ -8,7 +8,7 @@ using OMI.Formats.GameRule; namespace PckStudio.Core.GameRule { - internal sealed class OnGameStartSpawnPositions : AbstractGameRule + public sealed class OnGameStartSpawnPositions : AbstractGameRule { public SpawnPositionSet OnStart { get; } = new SpawnPositionSet(SpawnPositionSet.SpanPositionMethod.OnStart); public SpawnPositionSet OnRespawn { get; } = new SpawnPositionSet(SpawnPositionSet.SpanPositionMethod.OnRespawn); diff --git a/PckStudio.Core/GameRule/OnInitialiseWorld.cs b/PckStudio.Core/GameRule/OnInitialiseWorld.cs index ef36e45d..8bfaeb0a 100644 --- a/PckStudio.Core/GameRule/OnInitialiseWorld.cs +++ b/PckStudio.Core/GameRule/OnInitialiseWorld.cs @@ -7,7 +7,7 @@ using OMI.Formats.GameRule; namespace PckStudio.Core.GameRule { - internal sealed class OnInitialiseWorld : AbstractGameRule + public sealed class OnInitialiseWorld : AbstractGameRule { public DistributeItems StartItems { get; } = new DistributeItems(DistributeItems.DistributeItemsId.StartItems); public DistributeItems OuterItems { get; } = new DistributeItems(DistributeItems.DistributeItemsId.OuterItems); diff --git a/PckStudio.Core/GameRule/RootGameRule.cs b/PckStudio.Core/GameRule/RootGameRule.cs index 2720758c..7447ef6a 100644 --- a/PckStudio.Core/GameRule/RootGameRule.cs +++ b/PckStudio.Core/GameRule/RootGameRule.cs @@ -7,7 +7,7 @@ using OMI.Formats.GameRule; namespace PckStudio.Core.GameRule { - internal sealed class RootGameRule : AbstractGameRule + public sealed class RootGameRule : AbstractGameRule { protected override GameRuleFile.GameRule GetGameRule() => new GameRuleFile.GameRule("__ROOT__"); //! name is irrelevant } diff --git a/PckStudio.Core/GameRule/SpawnPositionSet.cs b/PckStudio.Core/GameRule/SpawnPositionSet.cs index 31c4c86c..a68b1c8e 100644 --- a/PckStudio.Core/GameRule/SpawnPositionSet.cs +++ b/PckStudio.Core/GameRule/SpawnPositionSet.cs @@ -8,7 +8,7 @@ using OMI.Formats.GameRule; namespace PckStudio.Core.GameRule { - internal sealed class SpawnPositionSet : AbstractGameRule + public sealed class SpawnPositionSet : AbstractGameRule { internal enum SpanPositionMethod { @@ -20,6 +20,7 @@ namespace PckStudio.Core.GameRule internal SpawnPositionSet(SpanPositionMethod method) => _method = method; public void AddSpawnPosition(int x, int y, int z, int xRot, int yRot) => AddRule(new UpdatePlayer(new Vector3(x, y, z), new Vector2(xRot, yRot))); + public void AddSpawnPosition(int x, int y, int z) => AddSpawnPosition(x, y, z, 0, 0); protected override GameRuleFile.GameRule GetGameRule() { diff --git a/PckStudio.Core/GameRule/UpdatePlayer.cs b/PckStudio.Core/GameRule/UpdatePlayer.cs index c6dd59dc..7919421b 100644 --- a/PckStudio.Core/GameRule/UpdatePlayer.cs +++ b/PckStudio.Core/GameRule/UpdatePlayer.cs @@ -23,11 +23,11 @@ namespace PckStudio.Core.GameRule { var gameRule = new GameRuleFile.GameRule("UpdatePlayer"); gameRule.AddParameters( - new GameRuleFile.IntParameter("x", (int)_spawn.X), - new GameRuleFile.IntParameter("y", (int)_spawn.Y), - new GameRuleFile.IntParameter("z", (int)_spawn.Z), - new GameRuleFile.IntParameter("xRot", (int)_rot.X), - new GameRuleFile.IntParameter("yRot", (int)_rot.Y) + new GameRuleFile.FloatParameter("x", _spawn.X), + new GameRuleFile.FloatParameter("y", _spawn.Y), + new GameRuleFile.FloatParameter("z", _spawn.Z), + new GameRuleFile.FloatParameter("xRot", _rot.X), + new GameRuleFile.FloatParameter("yRot", _rot.Y) ); return gameRule; }