mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-07-12 22:48:20 +00:00
Core - Made AbstarctGameRules public
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<AbstractGameRule>(), new GameRuleFile.IntParameter("ruleType", (int)miniGame));
|
||||
public static LevelRules GetMiniGameLevelRules(MiniGameId miniGame) => new LevelRules(miniGame);
|
||||
|
||||
public LevelRules(IEnumerable<AbstractGameRule> gameRules, params GameRuleFile.GameRuleParameter[] parameters)
|
||||
public LevelRules(IEnumerable<AbstractGameRule> gameRules, MiniGameId miniGameId, params GameRuleFile.GameRuleParameter[] parameters)
|
||||
{
|
||||
AddRules(gameRules);
|
||||
_parameters = parameters;
|
||||
_miniGameId = miniGameId;
|
||||
}
|
||||
|
||||
public LevelRules(IEnumerable<AbstractGameRule> gameRules, params GameRuleFile.GameRuleParameter[] parameters) : this(gameRules, MiniGameId.None, parameters) { }
|
||||
|
||||
public LevelRules(MiniGameId miniGameId) : this(Enumerable.Empty<AbstractGameRule>(), 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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user