Spite up project, added BeltData, some asoited compoents, remvoed unused usings, and removed uneeded comment code.
This commit is contained in:
30
src/Items/Components/Tag.cs
Normal file
30
src/Items/Components/Tag.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
namespace FoodFactory.Items;
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Numerics;
|
||||
|
||||
public readonly struct Tag : IEquatable<Tag>, IEqualityOperators<Tag, Tag, bool>, IComparisonOperators<Tag, Tag, bool>,
|
||||
IComparable<Tag>
|
||||
{
|
||||
public readonly string Name => TagRegistry.GetName(this);
|
||||
internal readonly int _id;
|
||||
|
||||
internal Tag(int id)
|
||||
{
|
||||
Debug.Assert(id >= 0);
|
||||
_id = id;
|
||||
}
|
||||
public override bool Equals([NotNullWhen(true)] object? obj) => obj is Tag tag && Equals(tag);
|
||||
public bool Equals(Tag other) => _id == other._id;
|
||||
public override int GetHashCode() => _id;
|
||||
public override string ToString() => Name;
|
||||
public int CompareTo(Tag other) => _id.CompareTo(other._id);
|
||||
public static bool operator >(Tag left, Tag right) => left._id > right._id;
|
||||
public static bool operator >=(Tag left, Tag right) => left._id >= right._id;
|
||||
public static bool operator <(Tag left, Tag right) => left._id < right._id;
|
||||
public static bool operator <=(Tag left, Tag right) => left._id <= right._id;
|
||||
public static bool operator ==(Tag left, Tag right) => left._id == right._id;
|
||||
public static bool operator !=(Tag left, Tag right) => left._id != right._id;
|
||||
}
|
||||
1
src/Items/Components/Tag.cs.uid
Normal file
1
src/Items/Components/Tag.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://1o2e2wou367m
|
||||
@@ -2,13 +2,9 @@ namespace FoodFactory.Items;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Threading;
|
||||
|
||||
public readonly struct Tags : IEquatable<Tags>, IReadOnlyCollection<Tag>
|
||||
{
|
||||
@@ -178,30 +174,6 @@ public readonly struct Tags : IEquatable<Tags>, IReadOnlyCollection<Tag>
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct Tag : IEquatable<Tag>, IEqualityOperators<Tag, Tag, bool>, IComparisonOperators<Tag, Tag, bool>,
|
||||
IComparable<Tag>
|
||||
{
|
||||
public readonly string Name => TagRegistry.GetName(this);
|
||||
internal readonly int _id;
|
||||
|
||||
internal Tag(int id)
|
||||
{
|
||||
Debug.Assert(id >= 0);
|
||||
_id = id;
|
||||
}
|
||||
public override bool Equals([NotNullWhen(true)] object? obj) => obj is Tag tag && Equals(tag);
|
||||
public bool Equals(Tag other) => _id == other._id;
|
||||
public override int GetHashCode() => _id;
|
||||
public override string ToString() => Name;
|
||||
public int CompareTo(Tag other) => _id.CompareTo(other._id);
|
||||
public static bool operator >(Tag left, Tag right) => left._id > right._id;
|
||||
public static bool operator >=(Tag left, Tag right) => left._id >= right._id;
|
||||
public static bool operator <(Tag left, Tag right) => left._id < right._id;
|
||||
public static bool operator <=(Tag left, Tag right) => left._id <= right._id;
|
||||
public static bool operator ==(Tag left, Tag right) => left._id == right._id;
|
||||
public static bool operator !=(Tag left, Tag right) => left._id != right._id;
|
||||
}
|
||||
|
||||
public static class TagRegistry
|
||||
{
|
||||
private static Registry<string> _registry = new();
|
||||
|
||||
1
src/Items/Components/Tags.cs.uid
Normal file
1
src/Items/Components/Tags.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://chk03ru27wxw1
|
||||
@@ -2,8 +2,12 @@ namespace ChickenGameTest;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Linq;
|
||||
using Arch.Core;
|
||||
using Arch.Core.Extensions;
|
||||
using FoodFactory.Items;
|
||||
using Godot;
|
||||
using SJK.Functional;
|
||||
|
||||
/// <summary>
|
||||
/// Items that can be on a belt
|
||||
@@ -16,15 +20,46 @@ public interface IBeltItem : IDisposable
|
||||
delegate void ItemRemoved(IBeltItem item);
|
||||
event ItemRemoved? Disposed;
|
||||
}
|
||||
|
||||
public class TestItem() : IBeltItem
|
||||
public interface IBeltItemData<T>
|
||||
{
|
||||
T GetItem();
|
||||
}
|
||||
public class TestItem() : IBeltItem, IBeltItemData<Entity>
|
||||
{
|
||||
public float Temp { get; set; }
|
||||
public int Width { get; set; }
|
||||
|
||||
public int Height { get; set; }
|
||||
public static PackedScene PotatoScene = ResourceLoader.Load<PackedScene>("res://assets/KayKit_Restaurant_Bits_1.0_FREE/Assets/gltf/food_ingredient_potato.gltf");
|
||||
public static PackedScene OnionScene = ResourceLoader.Load<PackedScene>("res://assets/KayKit_Restaurant_Bits_1.0_FREE/Assets/gltf/food_ingredient_onion.gltf");
|
||||
public static PackedScene ChoppedOnionScene = ResourceLoader.Load<PackedScene>("res://assets/KayKit_Restaurant_Bits_1.0_FREE/Assets/gltf/food_ingredient_onion_chopped.gltf");
|
||||
public Node3D CreateItemVisual()
|
||||
{
|
||||
Node3D node;
|
||||
if (Item.Get<Tags>().Contains(TagRegistry.GetTag("potato")))
|
||||
{
|
||||
node = PotatoScene.Instantiate<Node3D>();
|
||||
}
|
||||
else if (Item.Get<Tags>().ContainsAny(new Tags("sliced")))
|
||||
{
|
||||
node = ChoppedOnionScene.Instantiate<Node3D>();
|
||||
}
|
||||
else if (Item.Get<Tags>().Contains(TagRegistry.GetTag("onion")))
|
||||
{
|
||||
node = OnionScene.Instantiate<Node3D>();
|
||||
}
|
||||
else
|
||||
{
|
||||
node = new MeshInstance3D() { Mesh = new BoxMesh() };
|
||||
}
|
||||
node.GetChildren().OfType<Node3D>().ToList().ForEach(i => i.Scale *= new Vector3(.2f, .2f, .2f));
|
||||
if (Item.TryGet<Color>(out var color))
|
||||
{
|
||||
node.GetChildren().OfType<MeshInstance3D>().FirstOrNone().IfSome(some => some.SetSurfaceOverrideMaterial(0, new StandardMaterial3D() { AlbedoColor = Item.TryGet<Color>(out var color) ? color : Colors.White }));
|
||||
}
|
||||
return node;
|
||||
// return new MeshInstance3D() { Mesh = new BoxMesh() { Size = new(.1f, .1f, .1f) }, MaterialOverride = new StandardMaterial3D() { AlbedoColor = Item.TryGet<Color>(out var color) ? color : Colors.White } };
|
||||
}
|
||||
|
||||
public Node3D CreateItemVisual() => new MeshInstance3D() { Mesh = new BoxMesh() { Size = new(.1f, .1f, .1f) } };
|
||||
private bool _disposed;
|
||||
|
||||
public event IBeltItem.ItemRemoved? Disposed;
|
||||
@@ -40,7 +75,10 @@ public class TestItem() : IBeltItem
|
||||
_disposed = true;
|
||||
Disposed?.Invoke(this);
|
||||
}
|
||||
public Dictionary<string, object> PlaceHolderData = [];
|
||||
|
||||
public Entity GetItem() => Item;
|
||||
|
||||
public Entity Item;
|
||||
}
|
||||
|
||||
public interface IFluidItem
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Arch.Core;
|
||||
using Arch.Core.Extensions;
|
||||
using Arch.LowLevel.Jagged;
|
||||
using Arch.LowLevel;
|
||||
using FoodFactory;
|
||||
using FoodFactory.Items;
|
||||
using FoodFactory.Recipes;
|
||||
@@ -21,8 +20,8 @@ public class Test
|
||||
|
||||
var bucket = new BucketStorage<List<Entity>>();
|
||||
|
||||
var pizza = world.Create(new Name("Pizza"), new Temperature(5f), new MarcoNutrients(5, 5, 10), new MicroNutrients([new Vitamin("D", 5)]));
|
||||
var turkey = world.Create(new Name("Turkey"), new Temperature(5f), new MarcoNutrients(5, 5, 10));
|
||||
var pizza = world.Create(new Name("Pizza"), new Temperature(5f), new MarcoNutrients(5, 5, new()), new MicroNutrients([new Vitamin("D", 5)]));
|
||||
var turkey = world.Create(new Name("Turkey"), new Temperature(5f), new MarcoNutrients(5, 5, new()));
|
||||
|
||||
// var componentType = new ComponentType(ComponentRegistry.Size-1, 8);
|
||||
// ComponentRegistry.Add(typeof(LayeredStack2), componentType);
|
||||
@@ -37,7 +36,7 @@ public class Test
|
||||
pizza.Get<Temperature>().Kelvin += .1f;
|
||||
}
|
||||
pizza.Add(new IngredientOf(turkey));
|
||||
var a = new List<Entity>(){pizza};
|
||||
var a = new List<Entity>() { pizza };
|
||||
|
||||
turkey.Add(new LayeredStack(bucket.Add(a)));
|
||||
turkey.Add(new LayeredStack2(a));
|
||||
@@ -70,36 +69,6 @@ public class Test
|
||||
}
|
||||
}
|
||||
);
|
||||
var recipes = new Recipes();
|
||||
|
||||
var item = recipes.TESTBlueprint.Factory(new BlueprintContext(){World = world, BluePrintId = new BlueprintId(recipes.TESTBlueprint)});//world.Create(new Name("Potato_Raw"), new Temperature(71f), new Tags("raw", "potato", "vegetable"));
|
||||
Span<Entity> items = [item];
|
||||
var context = new RecipeContext(world, items);
|
||||
var builder = new RecipeResultBuilder(stackalloc bool[10], new ItemBuilder[10]);
|
||||
// var recipe = new PotatoCookRecipe();
|
||||
var recipe = recipes.GetRecipes(new RecipeAction("cook"), 1, [item.Get<Tags>()], [])[0].Recipe;
|
||||
if (recipe.CanProcess(context))
|
||||
{
|
||||
var result = recipe.Process(context, ref builder);
|
||||
var list3 = new List<Entity>();
|
||||
for (int i = 0; i < result.CreateLength; i++)
|
||||
{
|
||||
list3.Add(result.Create[i](in context));
|
||||
}
|
||||
if (result.RemoveLength > 0)
|
||||
{
|
||||
for (int i = 0; i < result.RemoveLength; i++)
|
||||
{
|
||||
GD.Print(result.Remove[i]);
|
||||
if (result.Remove[i])
|
||||
{
|
||||
world.Destroy(items[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
GD.Print(string.Join(',',list3[0].GetAllComponents()));
|
||||
GD.Print(items[0].IsAlive());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,15 +78,64 @@ internal interface IEntityContainer
|
||||
}
|
||||
|
||||
public record struct Name(string Value);
|
||||
public record struct MarcoNutrients(float Fat, float Protein, float Carbohydrate);
|
||||
public record struct BurnableTemp(Temperature Temperature);
|
||||
public record struct BurnedItem(Temperature BurnedAt, string Description);//Info about how burnted item is
|
||||
public record struct MarcoNutrients(Weight Fat, Weight Protein, Carbohydrates Carbohydrate);
|
||||
public readonly record struct Carbohydrates(
|
||||
Weight Fiber,
|
||||
Weight Starch,
|
||||
SugarProfile Sugars
|
||||
)
|
||||
{
|
||||
public Weight TotalWeight =>
|
||||
Fiber + Starch + Sugars.TotalWeight;
|
||||
|
||||
public double Calories =>
|
||||
(Fiber.Grams * 2.0) +
|
||||
(Starch.Grams * 4.0) +
|
||||
Sugars.Calories;
|
||||
|
||||
public double Sweetness =>
|
||||
Sugars.Sweetness;
|
||||
}
|
||||
public readonly record struct SugarProfile(
|
||||
Weight Glucose,
|
||||
Weight Fructose,
|
||||
Weight Sucrose,
|
||||
Weight Lactose
|
||||
)
|
||||
{
|
||||
public Weight TotalWeight =>
|
||||
Glucose + Fructose + Sucrose + Lactose;
|
||||
|
||||
public double Calories =>
|
||||
TotalWeight.Grams * 4.0;
|
||||
|
||||
public double Sweetness =>
|
||||
(Glucose.Grams * 0.7) +
|
||||
(Fructose.Grams * 1.7) +
|
||||
(Sucrose.Grams * 1.0) +
|
||||
(Lactose.Grams * 0.2);
|
||||
|
||||
public static SugarProfile operator +(
|
||||
SugarProfile a,
|
||||
SugarProfile b) => new(
|
||||
a.Glucose + b.Glucose,
|
||||
a.Fructose + b.Fructose,
|
||||
a.Sucrose + b.Sucrose,
|
||||
a.Lactose + b.Lactose);
|
||||
}
|
||||
public record struct Mass(Weight Value);// Repsenets the apomix weight of an item, should have things like nutrients allready accounted.
|
||||
public record struct MicroNutrients(List<Vitamin> Vitamins);
|
||||
|
||||
public record struct Vitamin(string Id, float Amount);
|
||||
|
||||
public record struct Vitamin(string Id, Weight Amount);
|
||||
public record struct Scale(float Value);
|
||||
public record struct IngredientOf(Entity Source);
|
||||
public record struct LayeredStack(Handle Handle);
|
||||
public record struct LayeredStack2(List<Entity> Children);
|
||||
|
||||
public record struct Bacteria(Handle<List<BacteriaData>> Data);
|
||||
public record struct BacteriaData(string Name, double Count);
|
||||
|
||||
public record struct Handle(int Index, int Version);
|
||||
|
||||
@@ -157,7 +175,7 @@ public class BucketStorage<T>
|
||||
Version = 1,
|
||||
Occupied = true
|
||||
};
|
||||
Array.Resize(ref _slots, _slots.Length + 1);
|
||||
System.Array.Resize(ref _slots, _slots.Length + 1);
|
||||
_slots[^1] = slot;
|
||||
|
||||
return new Handle
|
||||
|
||||
1
src/Items/ItemECSTest.cs.uid
Normal file
1
src/Items/ItemECSTest.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c5ik7ke6rrlmn
|
||||
Reference in New Issue
Block a user