New Inventory System + Overhaul

Removed universal GameContext references
Refactored GameContext: It's now only responsible for item management. As such it's now called ItemManager
GlobalData is gone, relevant settings are distributed amongst specialized settings classes
Entities are no longer database entries, references to them are now direct - Zone is reponsible for storing them in ZonePacks
Controller subtypes are now generic classes, class argument is task type
Inventory is now a 2D grid instead of a list
Entity temperature is now a 2D grid instead of a number
Item sizes are now arbitrary shapes instead of a number
Hardpoints are now arbitrary shapes instead
Equipped items have their own temperatures
Map view now displays sunlight colors
Integrated Allegorithmic Substance Plugin
Imported Djinni ship and assigned Substance materials
Removed Node Editor framework (might come back later but needs work to integrate with behavior system)
This commit is contained in:
Reinier Vens 2020-12-10 23:20:38 +00:00
commit f643f6cc8a
330 changed files with 24242 additions and 2830 deletions

View file

@ -1,10 +1,93 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using JsonKnownTypes;
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using int2 = Unity.Mathematics.int2;
public class Shape
{
[JsonProperty("name"), Key(0)] public bool[,] Cells;
private bool _dirty = true;
public Shape(int width, int height)
{
Cells = new bool[width, height];
}
public int Width => Cells.GetLength(0);
public int Height => Cells.GetLength(1);
private static int mod(int x, int m) {
int r = x%m;
return r<0 ? r+m : r;
}
public int2 Rotate(int2 position, int rotation)
{
switch (mod(rotation, 4))
{
case 1:
return int2(position.y, Width - 1 - position.x);
case 2:
return int2(Width - 1 - position.x, Height - 1 - position.y);
case 3:
return int2(Height - 1 - position.y, position.x);
default:
return int2(position.x, position.y);
}
}
private int2[] _cachedShapeCoordinates;
[IgnoreMember]
public int2[] Coordinates
{
get
{
if (_dirty) _cachedShapeCoordinates = EnumerateShapeCoordinates().ToArray();
return _cachedShapeCoordinates;
}
}
private IEnumerable<int2> EnumerateShapeCoordinates()
{
for(int x = 0; x < Cells.GetLength(0); x++)
{
for (int y = 0; y < Cells.GetLength(0); y++)
{
if(Cells[x,y]) yield return int2(x, y);
}
}
}
public bool this[int2 pos] {
get { return pos.x >= 0 && pos.y >= 0 && pos.x < Cells.GetLength(0) && pos.y < Cells.GetLength(1) && Cells[pos.x, pos.y]; }
set
{
_dirty = true;
Cells[pos.x, pos.y] = value;
}
}
public Shape Shrink()
{
var shape = new Shape(Width, Height);
foreach(var shapeCoord in Coordinates)
shape[shapeCoord] = (
this[shapeCoord + int2(-1,-1)] && this[shapeCoord + int2(0,-1)] && this[shapeCoord + int2(1,-1)] &&
this[shapeCoord + int2(-1,0)] && this[shapeCoord + int2(1,0)] &&
this[shapeCoord + int2(-1,1)] && this[shapeCoord + int2(0,1)] && this[shapeCoord + int2(1,1)]
);
return shape;
}
}
[MessagePackObject,
Union(0, typeof(SimpleCommodityData)),
@ -23,8 +106,8 @@ public abstract class ItemData : DatabaseEntry, INamedEntry
[InspectableField, JsonProperty("mass"), Key(3)]
public float Mass;
[InspectableField, JsonProperty("size"), Key(4)]
public float Size;
[InspectableField, JsonProperty("shape"), Key(4)]
public Shape Shape;
// Heat needed to change temperature of 1 gram by 1 degree
[InspectableField, JsonProperty("specificHeat"), Key(5)]
@ -35,36 +118,32 @@ public abstract class ItemData : DatabaseEntry, INamedEntry
get => Name;
set => Name = value;
}
}
[RethinkTable("Items"), Inspectable, MessagePackObject]
public class SimpleCommodityData : ItemData
{
// Types of body where this resource can be found
[InspectableField, JsonProperty("resourceBodyType"), Key(6)]
public BodyType ResourceBodyType;
// // Types of body where this resource can be found
// [InspectableField, JsonProperty("resourceBodyType"), Key(6)]
// public BodyType ResourceBodyType;
//
// // Link to map(s) controlling density of resource, multiplied together when more than one
// [InspectableDatabaseLink(typeof(GalaxyMapLayerData)), JsonProperty("resourceDensity"), Key(7)]
// public List<Guid> ResourceDensity = new List<Guid>();
//
// // Controls the lowest value in the resource distribution curve
// [InspectableField, JsonProperty("distribution"), Key(8)]
// public ExponentialLerp Distribution;
//
// // Minimum amount of resources needed for presence to register
// [InspectableField, JsonProperty("floor"), Key(11)]
// public float Floor = 5f;
// Link to map(s) controlling density of resource, multiplied together when more than one
[InspectableDatabaseLink(typeof(GalaxyMapLayerData)), JsonProperty("resourceDensity"), Key(7)]
public List<Guid> ResourceDensity = new List<Guid>();
[InspectableField, JsonProperty("maxStackSize"), Key(6)]
public int MaxStack;
// Controls the lowest value in the resource distribution curve
[InspectableField, JsonProperty("minimum"), Key(8)]
public float Minimum = 1;
// Controls the highest value in the resource distribution curve
[InspectableField, JsonProperty("maximum"), Key(9)]
public float Maximum = 100;
// Controls the shape of the resource distribution curve
[InspectableField, JsonProperty("exponent"), Key(10)]
public float Exponent = -.75f;
// Minimum amount of resources needed for presence to register
[InspectableField, JsonProperty("floor"), Key(11)]
public float Floor = 5f;
[InspectableField, JsonProperty("category"), Key(12)]
[InspectableField, JsonProperty("category"), Key(7)]
public SimpleCommodityCategory Category;
}
@ -83,10 +162,10 @@ public abstract class CraftedItemData : ItemData
[RethinkTable("Items"), Inspectable, MessagePackObject]
public class CompoundCommodityData : CraftedItemData
{
[InspectableDatabaseLink(typeof(PersonalityAttribute)), JsonProperty("demandProfile"), Key(7)]
[InspectableDatabaseLink(typeof(PersonalityAttribute)), JsonProperty("demandProfile"), Key(7)]
public Dictionary<Guid, float> DemandProfile = new Dictionary<Guid, float>();
[InspectableField, JsonProperty("category"), Key(8)]
[InspectableField, JsonProperty("category"), Key(8)]
public CompoundCommodityCategory Category;
}
@ -95,26 +174,20 @@ public class CompoundCommodityData : CraftedItemData
JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter<EquippableItemData>))]
public abstract class EquippableItemData : CraftedItemData
{
[InspectableAnimationCurve, JsonProperty("performanceCurve"), Key(7)]
public float4[] HeatPerformanceCurve;
[InspectableField, JsonProperty("behaviors"), Key(7)]
public List<BehaviorData> Behaviors = new List<BehaviorData>();
[TemperatureInspectable, JsonProperty("minTemp"), Key(8)]
[InspectableField, JsonProperty("durability"), Key(8)]
public float Durability;
[TemperatureInspectable, JsonProperty("minTemp"), Key(9)]
public float MinimumTemperature;
[TemperatureInspectable, JsonProperty("maxTemp"), Key(9)]
[TemperatureInspectable, JsonProperty("maxTemp"), Key(10)]
public float MaximumTemperature;
[InspectableField, JsonProperty("durabilityStat"), Key(10), SimplePerformanceStat]
public PerformanceStat Durability = new PerformanceStat();
[InspectableField, JsonProperty("durabilityExponent"), Key(11), SimplePerformanceStat]
public PerformanceStat DurabilityExponent = new PerformanceStat();
[InspectableField, JsonProperty("heatExponent"), Key(12), SimplePerformanceStat]
public PerformanceStat HeatExponent = new PerformanceStat();
[InspectableField, JsonProperty("behaviors"), Key(13)]
public List<BehaviorData> Behaviors = new List<BehaviorData>();
[IgnoreMember]
public abstract HardpointType HardpointType { get; }
@ -122,63 +195,63 @@ public abstract class EquippableItemData : CraftedItemData
[IgnoreMember] private const int STEPS = 64;
[IgnoreMember] private float? _optimum;
[IgnoreMember]
public float OptimalTemperature
{
get
{
if (_optimum==null)
{
var samples = Enumerable.Range(0, STEPS).Select(i => (float) i / STEPS).ToArray();
float max = 0;
_optimum = 0;
foreach (var f in samples)
{
var p = HeatPerformanceCurve?.Evaluate(f)??0;
if (p > max)
{
max = p;
_optimum = f;
}
}
}
return (float) (MinimumTemperature + _optimum * (MaximumTemperature - MinimumTemperature));
}
}
}
[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class GearData : EquippableItemData
{
[InspectableField, JsonProperty("hardpointType"), Key(14)]
[InspectableField, JsonProperty("hardpointType"), Key(12)]
public HardpointType Hardpoint;
[IgnoreMember] public override HardpointType HardpointType => Hardpoint;
}
[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class CargoBayData : EquippableItemData
{
[InspectableField, JsonProperty("interiorShape"), Key(12)]
public Shape InteriorShape;
[IgnoreMember] public override HardpointType HardpointType => HardpointType.Tool;
}
[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class HullData : EquippableItemData
{
[InspectableField, JsonProperty("hullCapacity"), Key(14)]
public PerformanceStat Capacity = new PerformanceStat();
[InspectableField, JsonProperty("hardpoints"), Key(15)]
[InspectableField, JsonProperty("hardpoints"), Key(12)]
public List<HardpointData> Hardpoints = new List<HardpointData>();
[InspectablePrefab, JsonProperty("prefab"), Key(16)]
[InspectablePrefab, JsonProperty("prefab"), Key(13)]
public string Prefab;
[InspectableField, JsonProperty("hullType"), Key(17)]
[InspectableField, JsonProperty("hullType"), Key(14)]
public HullType HullType;
[IgnoreMember]
public Shape InteriorCells
{
get
{
if (_interiorCells == null)
{
_interiorCells = Shape.Shrink();
}
return _interiorCells;
}
}
private Shape _interiorCells;
[IgnoreMember] public override HardpointType HardpointType => HardpointType.Hull;
}
[RethinkTable("Items"), InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class HardpointData
{
[InspectableField, JsonProperty("type"), Key(0)] public HardpointType Type;
[InspectableField, JsonProperty("type"), Key(0)] public HardpointType Type;
[InspectableField, JsonProperty("position"), Key(1)] public int2 Position;
[InspectableField, JsonProperty("shape"), Key(2)] public Shape Shape;
[InspectableField, JsonProperty("transform"), Key(3)] public string Transform;
}
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
@ -191,10 +264,10 @@ public class PerformanceStat
[JsonProperty("durabilityDependent"), Key(2)]
public bool DurabilityDependent;
[JsonProperty("heatDependent"), Key(3)]
public bool HeatDependent;
// [JsonProperty("heatDependent"), Key(3)]
// public bool HeatDependent;
[JsonProperty("qualityExponent"), Key(4)]
[JsonProperty("qualityExponent"), Key(3)]
public float QualityExponent;
//[JsonProperty("id"), Key(5)] public Guid ID = Guid.NewGuid();
@ -206,11 +279,11 @@ public class PerformanceStat
[IgnoreMember]
private Dictionary<Entity, Dictionary<IBehavior, float>> ScaleModifiers =>
_scaleModifiers ?? (_scaleModifiers = new Dictionary<Entity, Dictionary<IBehavior, float>>());
_scaleModifiers = _scaleModifiers ?? new Dictionary<Entity, Dictionary<IBehavior, float>>();
[IgnoreMember]
private Dictionary<Entity, Dictionary<IBehavior, float>> ConstantModifiers =>
_constantModifiers ?? (_constantModifiers = new Dictionary<Entity, Dictionary<IBehavior, float>>());
_constantModifiers = _constantModifiers ?? new Dictionary<Entity, Dictionary<IBehavior, float>>();
public Dictionary<IBehavior, float> GetScaleModifiers(Entity entity)
{