mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-22 18:15:30 +00:00
Add AbstractGameRule.cs & derived classes
This commit is contained in:
23
PckStudio.Core/GameRule/AbstractGameRule.cs
Normal file
23
PckStudio.Core/GameRule/AbstractGameRule.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OMI.Formats.GameRule;
|
||||
|
||||
namespace PckStudio.Core.GameRule
|
||||
{
|
||||
internal abstract class AbstractGameRule
|
||||
{
|
||||
private List<AbstractGameRule> _gameRules = new List<AbstractGameRule>();
|
||||
protected void AddRule(AbstractGameRule gameRule) => _gameRules.Add(gameRule);
|
||||
|
||||
protected abstract GameRuleFile.GameRule GetGameRule();
|
||||
public static implicit operator GameRuleFile.GameRule(AbstractGameRule abstractGameRule)
|
||||
{
|
||||
GameRuleFile.GameRule gameRule = abstractGameRule.GetGameRule();
|
||||
gameRule.AddRules(abstractGameRule._gameRules.Select(agr => agr.GetGameRule()));
|
||||
return gameRule;
|
||||
}
|
||||
}
|
||||
}
|
||||
41
PckStudio.Core/GameRule/DistributeItems.cs
Normal file
41
PckStudio.Core/GameRule/DistributeItems.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OMI.Formats.GameRule;
|
||||
|
||||
namespace PckStudio.Core.GameRule
|
||||
{
|
||||
internal sealed class DistributeItems : AbstractGameRule
|
||||
{
|
||||
private static string[] _strings =
|
||||
{
|
||||
"StartItems",
|
||||
"OuterItems",
|
||||
"HVItems"
|
||||
};
|
||||
|
||||
internal enum DistributeItemsId
|
||||
{
|
||||
StartItems,
|
||||
OuterItems,
|
||||
HighValueItems
|
||||
}
|
||||
private DistributeItemsId _id;
|
||||
|
||||
internal void AddPosition(int x, int y, int z) => AddRule(new WorldPosition(x, y, z));
|
||||
|
||||
public DistributeItems(DistributeItemsId id)
|
||||
{
|
||||
_id = id;
|
||||
}
|
||||
|
||||
protected override GameRuleFile.GameRule GetGameRule()
|
||||
{
|
||||
var gameRule = new GameRuleFile.GameRule("DistributeItems");
|
||||
gameRule.AddParameter(new GameRuleFile.GameRuleParameter("id", _strings[(int)_id]));
|
||||
return gameRule;
|
||||
}
|
||||
}
|
||||
}
|
||||
40
PckStudio.Core/GameRule/NamedArea.cs
Normal file
40
PckStudio.Core/GameRule/NamedArea.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OMI.Formats.GameRule;
|
||||
|
||||
namespace PckStudio.Core.GameRule
|
||||
{
|
||||
internal sealed class NamedArea : AbstractGameRule
|
||||
{
|
||||
public string Name { get; }
|
||||
|
||||
public Vector3 Start { get; }
|
||||
public Vector3 End { get; }
|
||||
|
||||
public NamedArea(string name, Vector3 start, Vector3 end)
|
||||
{
|
||||
Name = name;
|
||||
Start = start;
|
||||
End = end;
|
||||
}
|
||||
|
||||
protected override GameRuleFile.GameRule GetGameRule()
|
||||
{
|
||||
GameRuleFile.GameRule gameRule = new GameRuleFile.GameRule("NamedArea", null);
|
||||
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)
|
||||
);
|
||||
return gameRule;
|
||||
}
|
||||
}
|
||||
}
|
||||
23
PckStudio.Core/GameRule/OnGameStartSpawnPositions.cs
Normal file
23
PckStudio.Core/GameRule/OnGameStartSpawnPositions.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OMI.Formats.GameRule;
|
||||
|
||||
namespace PckStudio.Core.GameRule
|
||||
{
|
||||
internal sealed class OnGameStartSpawnPositions : AbstractGameRule
|
||||
{
|
||||
public SpawnPositionSet OnStart { get; } = new SpawnPositionSet(SpawnPositionSet.SpanPositionMethod.OnStart);
|
||||
public SpawnPositionSet OnRespawn { get; } = new SpawnPositionSet(SpawnPositionSet.SpanPositionMethod.OnRespawn);
|
||||
|
||||
protected override GameRuleFile.GameRule GetGameRule()
|
||||
{
|
||||
AddRule(OnStart);
|
||||
AddRule(OnRespawn);
|
||||
return new GameRuleFile.GameRule("OnGameStartSpawnPositions");
|
||||
}
|
||||
}
|
||||
}
|
||||
24
PckStudio.Core/GameRule/OnInitialiseWorld.cs
Normal file
24
PckStudio.Core/GameRule/OnInitialiseWorld.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OMI.Formats.GameRule;
|
||||
|
||||
namespace PckStudio.Core.GameRule
|
||||
{
|
||||
internal sealed class OnInitialiseWorld : AbstractGameRule
|
||||
{
|
||||
public DistributeItems StartItems { get; } = new DistributeItems(DistributeItems.DistributeItemsId.StartItems);
|
||||
public DistributeItems OuterItems { get; } = new DistributeItems(DistributeItems.DistributeItemsId.OuterItems);
|
||||
public DistributeItems HighValueItems { get; } = new DistributeItems(DistributeItems.DistributeItemsId.HighValueItems);
|
||||
|
||||
protected override GameRuleFile.GameRule GetGameRule()
|
||||
{
|
||||
AddRule(StartItems);
|
||||
AddRule(OuterItems);
|
||||
AddRule(HighValueItems);
|
||||
return new GameRuleFile.GameRule("OnInitialiseWorld");
|
||||
}
|
||||
}
|
||||
}
|
||||
31
PckStudio.Core/GameRule/SpawnPositionSet.cs
Normal file
31
PckStudio.Core/GameRule/SpawnPositionSet.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OMI.Formats.GameRule;
|
||||
|
||||
namespace PckStudio.Core.GameRule
|
||||
{
|
||||
internal sealed class SpawnPositionSet : AbstractGameRule
|
||||
{
|
||||
internal enum SpanPositionMethod
|
||||
{
|
||||
OnStart,
|
||||
OnRespawn
|
||||
}
|
||||
private SpanPositionMethod _method;
|
||||
|
||||
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)));
|
||||
|
||||
protected override GameRuleFile.GameRule GetGameRule()
|
||||
{
|
||||
var gameRule = new GameRuleFile.GameRule("SpawnPositionSet");
|
||||
gameRule.AddParameter(new GameRuleFile.IntParameter("method", (int)_method));
|
||||
return gameRule;
|
||||
}
|
||||
}
|
||||
}
|
||||
35
PckStudio.Core/GameRule/UpdatePlayer.cs
Normal file
35
PckStudio.Core/GameRule/UpdatePlayer.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OMI.Formats.GameRule;
|
||||
|
||||
namespace PckStudio.Core.GameRule
|
||||
{
|
||||
internal sealed class UpdatePlayer : AbstractGameRule
|
||||
{
|
||||
private Vector3 _spawn;
|
||||
private Vector2 _rot;
|
||||
|
||||
public UpdatePlayer(Vector3 spawn, Vector2 rot)
|
||||
{
|
||||
_spawn = spawn;
|
||||
_rot = rot;
|
||||
}
|
||||
|
||||
protected override GameRuleFile.GameRule GetGameRule()
|
||||
{
|
||||
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)
|
||||
);
|
||||
return gameRule;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
PckStudio.Core/GameRule/WorldPosition.cs
Normal file
26
PckStudio.Core/GameRule/WorldPosition.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OMI.Formats.GameRule;
|
||||
|
||||
namespace PckStudio.Core.GameRule
|
||||
{
|
||||
internal sealed class WorldPosition(int x, int y, int z) : AbstractGameRule
|
||||
{
|
||||
private Vector3 _pos = new Vector3(x, y, z);
|
||||
|
||||
protected override GameRuleFile.GameRule GetGameRule()
|
||||
{
|
||||
var gameRule = new GameRuleFile.GameRule("WorldPosition");
|
||||
gameRule.AddParameters(
|
||||
new GameRuleFile.IntParameter("x", (int)_pos.X),
|
||||
new GameRuleFile.IntParameter("y", (int)_pos.Y),
|
||||
new GameRuleFile.IntParameter("z", (int)_pos.Z)
|
||||
);
|
||||
return gameRule;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,6 +99,14 @@
|
||||
<Compile Include="FileDialogFilter.cs" />
|
||||
<Compile Include="FileFormats\PckAudioFile.cs" />
|
||||
<Compile Include="GameConstants.cs" />
|
||||
<Compile Include="GameRule\AbstractGameRule.cs" />
|
||||
<Compile Include="GameRule\DistributeItems.cs" />
|
||||
<Compile Include="GameRule\NamedArea.cs" />
|
||||
<Compile Include="GameRule\OnGameStartSpawnPositions.cs" />
|
||||
<Compile Include="GameRule\OnInitialiseWorld.cs" />
|
||||
<Compile Include="GameRule\SpawnPositionSet.cs" />
|
||||
<Compile Include="GameRule\UpdatePlayer.cs" />
|
||||
<Compile Include="GameRule\WorldPosition.cs" />
|
||||
<Compile Include="Interfaces\IDLCPackage.cs" />
|
||||
<Compile Include="Interfaces\IDLCPackageLocationInfo.cs" />
|
||||
<Compile Include="Interfaces\IEditor.cs" />
|
||||
|
||||
Reference in New Issue
Block a user