Browse Source

Allow GameModule to directly access entities. Removes some pointless indirection and boilerplate code in GameState.

console
Nico de Poel 5 years ago
parent
commit
9345b0d15c
  1. 24
      Assets/Scripts/Game/GameState.cs
  2. 10
      Assets/Scripts/Modules/GameModule.cs

24
Assets/Scripts/Game/GameState.cs

@ -69,12 +69,10 @@ public class GameState
} }
} }
public void ClearEntityModel(int entityNum)
public Entity GetEntity(int entityNum)
{ {
if (entities.TryGetValue(entityNum, out var entity))
{
entity.ClearModel();
}
entities.TryGetValue(entityNum, out var entity);
return entity;
} }
public void SetEntityAliasModel(int entityNum, string modelName) public void SetEntityAliasModel(int entityNum, string modelName)
@ -99,22 +97,6 @@ public class GameState
// TODO: obtain Mesh from brush submodel and assign it to MeshRenderer // TODO: obtain Mesh from brush submodel and assign it to MeshRenderer
} }
public void UpdateEntityAnimation(int entityNum, float frameNum)
{
if (entities.TryGetValue(entityNum, out var entity))
{
entity.UpdateAnimation(frameNum);
}
}
public void SetEntityTransform(int entityNum, Vector3 position, Quaternion rotation)
{
if (entities.TryGetValue(entityNum, out var entity))
{
entity.SetTransform(position, rotation);
}
}
public void RemoveEntity(int entityNum) public void RemoveEntity(int entityNum)
{ {
if (entities.TryGetValue(entityNum, out var entity)) if (entities.TryGetValue(entityNum, out var entity))

10
Assets/Scripts/Modules/GameModule.cs

@ -16,7 +16,7 @@ public partial class GameModule
{ {
if (string.IsNullOrEmpty(modelName)) if (string.IsNullOrEmpty(modelName))
{ {
uq.GameState.ClearEntityModel(entityNum);
uq.GameState.GetEntity(entityNum)?.ClearModel();
return; return;
} }
@ -35,14 +35,14 @@ public partial class GameModule
if (modelName.EndsWith(".bsp")) if (modelName.EndsWith(".bsp"))
{ {
// TODO: non-world brush model // TODO: non-world brush model
uq.GameState.ClearEntityModel(entityNum);
uq.GameState.GetEntity(entityNum)?.ClearModel();
return; return;
} }
if (modelName.EndsWith(".spr")) if (modelName.EndsWith(".spr"))
{ {
// TODO: sprite // TODO: sprite
uq.GameState.ClearEntityModel(entityNum);
uq.GameState.GetEntity(entityNum)?.ClearModel();
return; return;
} }
@ -51,7 +51,7 @@ public partial class GameModule
private void SetEntityTransform(int entityNum, QVec3 origin, QVec3 angles) private void SetEntityTransform(int entityNum, QVec3 origin, QVec3 angles)
{ {
uq.GameState.SetEntityTransform(entityNum, origin.ToUnityPosition(), angles.ToUnityRotation());
uq.GameState.GetEntity(entityNum)?.SetTransform(origin.ToUnityPosition(), angles.ToUnityRotation());
} }
private void RemoveEntity(int entityNum) private void RemoveEntity(int entityNum)
@ -61,6 +61,6 @@ public partial class GameModule
private void UpdateEntityAnimation(int entityNum, float frameNum) private void UpdateEntityAnimation(int entityNum, float frameNum)
{ {
uq.GameState.UpdateEntityAnimation(entityNum, frameNum);
uq.GameState.GetEntity(entityNum)?.UpdateAnimation(frameNum);
} }
} }
Loading…
Cancel
Save