From adf1d1f3ce7fc7259ab712206eb57c244b80b5e9 Mon Sep 17 00:00:00 2001 From: Cole Garien Date: Wed, 14 Aug 2024 11:45:39 -0500 Subject: [PATCH] create new Model project and transfer over Grynt code generator --- Ozzyria.Game/Ozzyria.Game.csproj | 1 + Ozzyria.Grynt/Ozzyria.Grynt.csproj | 14 + Ozzyria.Grynt/Program.cs | 54 ++ .../Definitions/ComponentDefinition.cs | 24 + .../CodeGen/Definitions/FieldDefinition.cs | 20 + .../CodeGen/Definitions/PrefabDefinition.cs | 21 + .../CodeGen/Definitions/TypeDefinition.cs | 31 + .../CodeGen/Files/component_defs.json | 561 ++++++++++++++++++ Ozzyria.Model/CodeGen/Files/prefab_defs.json | 2 + Ozzyria.Model/CodeGen/Files/type_defs.json | 72 +++ .../CodeGen/Generators/ClassGenerator.cs | 95 +++ .../CodeGen/Generators/ComponentGenerator.cs | 42 ++ .../Generators/Decorators/FieldsDecorator.cs | 32 + .../Decorators/GrecsComponentDecorator.cs | 26 + .../GrecsPooledComponentDecorator.cs | 26 + .../Decorators/HydrateableDecorator.cs | 103 ++++ .../Generators/Decorators/IClassDecorator.cs | 13 + .../Decorators/SerializableDecorator.cs | 155 +++++ .../Generators/Fields/FieldsGenerator.cs | 133 +++++ .../Generators/Fields/GrecsFieldGenerator.cs | 18 + .../Generators/Fields/IFieldGenerator.cs | 11 + .../CodeGen/Generators/TypeGenerator.cs | 57 ++ .../Specifications/PrefabSpecification.cs | 10 + Ozzyria.Model/Components/Animator.cs | 137 +++++ Ozzyria.Model/Components/AreaChange.cs | 84 +++ Ozzyria.Model/Components/Armor.cs | 42 ++ Ozzyria.Model/Components/AttackIntent.cs | 126 ++++ Ozzyria.Model/Components/Bag.cs | 63 ++ Ozzyria.Model/Components/Body.cs | 42 ++ Ozzyria.Model/Components/Dead.cs | 27 + Ozzyria.Model/Components/Door.cs | 84 +++ Ozzyria.Model/Components/ExperienceBoost.cs | 63 ++ .../Components/ExperienceOrbThought.cs | 27 + Ozzyria.Model/Components/Hat.cs | 42 ++ Ozzyria.Model/Components/Item.cs | 147 +++++ Ozzyria.Model/Components/Location.cs | 42 ++ Ozzyria.Model/Components/Mask.cs | 42 ++ Ozzyria.Model/Components/Movement.cs | 273 +++++++++ Ozzyria.Model/Components/MovementIntent.cs | 105 ++++ Ozzyria.Model/Components/Player.cs | 42 ++ Ozzyria.Model/Components/PlayerThought.cs | 27 + Ozzyria.Model/Components/Skeleton.cs | 424 +++++++++++++ Ozzyria.Model/Components/SlimeSpawner.cs | 119 ++++ Ozzyria.Model/Components/SlimeThought.cs | 73 +++ Ozzyria.Model/Components/Stats.cs | 105 ++++ Ozzyria.Model/Components/Weapon.cs | 126 ++++ Ozzyria.Model/Ozzyria.Model.csproj | 35 ++ Ozzyria.Model/Types/ClipType.cs | 9 + Ozzyria.Model/Types/Delay.cs | 89 +++ Ozzyria.Model/Types/Direction.cs | 11 + Ozzyria.Model/Types/IHydrateable.cs | 7 + Ozzyria.Model/Types/ISerializable.cs | 8 + Ozzyria.Model/Types/SkeletonPose.cs | 9 + Ozzyria.Model/Types/SkeletonType.cs | 9 + Ozzyria.Model/Types/ValuePacket.cs | 46 ++ Ozzyria.Model/Types/WeaponType.cs | 8 + Ozzyria.sln | 12 + 57 files changed, 4026 insertions(+) create mode 100644 Ozzyria.Grynt/Ozzyria.Grynt.csproj create mode 100644 Ozzyria.Grynt/Program.cs create mode 100644 Ozzyria.Model/CodeGen/Definitions/ComponentDefinition.cs create mode 100644 Ozzyria.Model/CodeGen/Definitions/FieldDefinition.cs create mode 100644 Ozzyria.Model/CodeGen/Definitions/PrefabDefinition.cs create mode 100644 Ozzyria.Model/CodeGen/Definitions/TypeDefinition.cs create mode 100644 Ozzyria.Model/CodeGen/Files/component_defs.json create mode 100644 Ozzyria.Model/CodeGen/Files/prefab_defs.json create mode 100644 Ozzyria.Model/CodeGen/Files/type_defs.json create mode 100644 Ozzyria.Model/CodeGen/Generators/ClassGenerator.cs create mode 100644 Ozzyria.Model/CodeGen/Generators/ComponentGenerator.cs create mode 100644 Ozzyria.Model/CodeGen/Generators/Decorators/FieldsDecorator.cs create mode 100644 Ozzyria.Model/CodeGen/Generators/Decorators/GrecsComponentDecorator.cs create mode 100644 Ozzyria.Model/CodeGen/Generators/Decorators/GrecsPooledComponentDecorator.cs create mode 100644 Ozzyria.Model/CodeGen/Generators/Decorators/HydrateableDecorator.cs create mode 100644 Ozzyria.Model/CodeGen/Generators/Decorators/IClassDecorator.cs create mode 100644 Ozzyria.Model/CodeGen/Generators/Decorators/SerializableDecorator.cs create mode 100644 Ozzyria.Model/CodeGen/Generators/Fields/FieldsGenerator.cs create mode 100644 Ozzyria.Model/CodeGen/Generators/Fields/GrecsFieldGenerator.cs create mode 100644 Ozzyria.Model/CodeGen/Generators/Fields/IFieldGenerator.cs create mode 100644 Ozzyria.Model/CodeGen/Generators/TypeGenerator.cs create mode 100644 Ozzyria.Model/CodeGen/Specifications/PrefabSpecification.cs create mode 100644 Ozzyria.Model/Components/Animator.cs create mode 100644 Ozzyria.Model/Components/AreaChange.cs create mode 100644 Ozzyria.Model/Components/Armor.cs create mode 100644 Ozzyria.Model/Components/AttackIntent.cs create mode 100644 Ozzyria.Model/Components/Bag.cs create mode 100644 Ozzyria.Model/Components/Body.cs create mode 100644 Ozzyria.Model/Components/Dead.cs create mode 100644 Ozzyria.Model/Components/Door.cs create mode 100644 Ozzyria.Model/Components/ExperienceBoost.cs create mode 100644 Ozzyria.Model/Components/ExperienceOrbThought.cs create mode 100644 Ozzyria.Model/Components/Hat.cs create mode 100644 Ozzyria.Model/Components/Item.cs create mode 100644 Ozzyria.Model/Components/Location.cs create mode 100644 Ozzyria.Model/Components/Mask.cs create mode 100644 Ozzyria.Model/Components/Movement.cs create mode 100644 Ozzyria.Model/Components/MovementIntent.cs create mode 100644 Ozzyria.Model/Components/Player.cs create mode 100644 Ozzyria.Model/Components/PlayerThought.cs create mode 100644 Ozzyria.Model/Components/Skeleton.cs create mode 100644 Ozzyria.Model/Components/SlimeSpawner.cs create mode 100644 Ozzyria.Model/Components/SlimeThought.cs create mode 100644 Ozzyria.Model/Components/Stats.cs create mode 100644 Ozzyria.Model/Components/Weapon.cs create mode 100644 Ozzyria.Model/Ozzyria.Model.csproj create mode 100644 Ozzyria.Model/Types/ClipType.cs create mode 100644 Ozzyria.Model/Types/Delay.cs create mode 100644 Ozzyria.Model/Types/Direction.cs create mode 100644 Ozzyria.Model/Types/IHydrateable.cs create mode 100644 Ozzyria.Model/Types/ISerializable.cs create mode 100644 Ozzyria.Model/Types/SkeletonPose.cs create mode 100644 Ozzyria.Model/Types/SkeletonType.cs create mode 100644 Ozzyria.Model/Types/ValuePacket.cs create mode 100644 Ozzyria.Model/Types/WeaponType.cs diff --git a/Ozzyria.Game/Ozzyria.Game.csproj b/Ozzyria.Game/Ozzyria.Game.csproj index 0a1d791..c75add5 100644 --- a/Ozzyria.Game/Ozzyria.Game.csproj +++ b/Ozzyria.Game/Ozzyria.Game.csproj @@ -10,6 +10,7 @@ + diff --git a/Ozzyria.Grynt/Ozzyria.Grynt.csproj b/Ozzyria.Grynt/Ozzyria.Grynt.csproj new file mode 100644 index 0000000..724d729 --- /dev/null +++ b/Ozzyria.Grynt/Ozzyria.Grynt.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + diff --git a/Ozzyria.Grynt/Program.cs b/Ozzyria.Grynt/Program.cs new file mode 100644 index 0000000..e7c8f56 --- /dev/null +++ b/Ozzyria.Grynt/Program.cs @@ -0,0 +1,54 @@ +using Grynt.Generators.Decorators; +using Grynt.Generators.Fields; +using Grynt.Generators; +using Grynt.Model.Packages; +using Grynt.Model.Definitions; + +namespace Ozzyria.Grynt +{ + internal class Program + { + public static string OzzyriaModelRoot() + { + return Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName, "Ozzyria.Model"); + } + + static void Main(string[] args) + { + var targetNamespace = "Ozzyria.Model"; + var modelRoot = OzzyriaModelRoot(); + + System.Console.WriteLine("---- TYPES ----"); + + var typePackage = TypePackage.Load(Path.Combine(modelRoot, "CodeGen", "Files", "type_defs.json")); + var basicFieldGenerator = new FieldsGenerator(typePackage); + var typeClassGenerator = new ClassGenerator(targetNamespace, "Types", [ + new FieldsDecorator(basicFieldGenerator), + new SerializableDecorator(typePackage), + new HydrateableDecorator(typePackage) + ]); + var typeGenerator = new TypeGenerator(targetNamespace, typePackage, typeClassGenerator); + foreach (var type in typePackage.Definitions.Values) + { + var code = typeGenerator.Generate(type); + System.Console.WriteLine(code); + if (type.Type != TypeDefinition.TYPE_ASSUMED) + { + File.WriteAllText(Path.Combine(modelRoot, "Types", type.Name + ".cs"), code); + } + } + + + System.Console.WriteLine("---- COMPONENTS ----"); + + var componentPackage = ComponentPackage.Load(Path.Combine(modelRoot, "CodeGen", "Files", "component_defs.json")); + var componentClassGenerator = new ComponentGenerator(targetNamespace, typePackage); + foreach (var component in componentPackage.Definitions.Values) + { + var code = componentClassGenerator.Generate(component); + System.Console.WriteLine(code); + File.WriteAllText(Path.Combine(modelRoot, "Components", component.Name + ".cs"), code); + } + } + } +} diff --git a/Ozzyria.Model/CodeGen/Definitions/ComponentDefinition.cs b/Ozzyria.Model/CodeGen/Definitions/ComponentDefinition.cs new file mode 100644 index 0000000..590962a --- /dev/null +++ b/Ozzyria.Model/CodeGen/Definitions/ComponentDefinition.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; +using Ozzyria.Model.Types; + +namespace Grynt.Model.Definitions +{ + public class ComponentDefinition + { + [JsonPropertyName("id")] + public string Id { get; set; } + + [JsonPropertyName("name")] + public string Name { get; set; } + + [JsonPropertyName("is_pooled")] + public bool IsPooled { get; set; } + + [JsonPropertyName("fields")] + public Dictionary Fields { get; set; } + + [JsonPropertyName("defaults")] + public ValuePacket Defaults { get; set; } + } +} diff --git a/Ozzyria.Model/CodeGen/Definitions/FieldDefinition.cs b/Ozzyria.Model/CodeGen/Definitions/FieldDefinition.cs new file mode 100644 index 0000000..76188cd --- /dev/null +++ b/Ozzyria.Model/CodeGen/Definitions/FieldDefinition.cs @@ -0,0 +1,20 @@ +using System.Text.Json.Serialization; + +namespace Grynt.Model.Definitions +{ + public class FieldDefinition + { + [JsonPropertyName("id")] + public string Id { get; set; } + + [JsonPropertyName("name")] + public string Name { get; set; } + + [JsonPropertyName("type")] + public string TypeId { get; set; } + + [JsonPropertyName("exclude_from_serialize")] + public bool ExcludeFromSerialize { get; set; } + + } +} diff --git a/Ozzyria.Model/CodeGen/Definitions/PrefabDefinition.cs b/Ozzyria.Model/CodeGen/Definitions/PrefabDefinition.cs new file mode 100644 index 0000000..8e2165f --- /dev/null +++ b/Ozzyria.Model/CodeGen/Definitions/PrefabDefinition.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; +using Ozzyria.Model.Types; + +namespace Grynt.Model.Definitions +{ + public class PrefabDefinition + { + [JsonPropertyName("id")] + public string Id { get; set; } + + [JsonPropertyName("components")] + public List Components { get; set; } + + [JsonPropertyName("defaults")] + public ValuePacket Defaults { get; set; } + + [JsonPropertyName("exposed")] + public List Exposed { get; set; } + } +} diff --git a/Ozzyria.Model/CodeGen/Definitions/TypeDefinition.cs b/Ozzyria.Model/CodeGen/Definitions/TypeDefinition.cs new file mode 100644 index 0000000..ba5db4f --- /dev/null +++ b/Ozzyria.Model/CodeGen/Definitions/TypeDefinition.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; +using Ozzyria.Model.Types; + +namespace Grynt.Model.Definitions +{ + public class TypeDefinition + { + public const string TYPE_ASSUMED = "assumed"; + public const string TYPE_ENUM = "enum"; + public const string TYPE_CLASS = "class"; + + [JsonPropertyName("id")] + public string Id { get; set; } + + [JsonPropertyName("name")] + public string Name { get; set; } + + [JsonPropertyName("type")] + public string Type { get; set; } + + [JsonPropertyName("values")] + public List EnumValues { get; set; } + + [JsonPropertyName("fields")] + public Dictionary ClassFields { get; set; } + + [JsonPropertyName("defaults")] + public ValuePacket ClassDefaults { get; set; } + } +} diff --git a/Ozzyria.Model/CodeGen/Files/component_defs.json b/Ozzyria.Model/CodeGen/Files/component_defs.json new file mode 100644 index 0000000..95ac811 --- /dev/null +++ b/Ozzyria.Model/CodeGen/Files/component_defs.json @@ -0,0 +1,561 @@ +{ + "animator": { + "name": "Animator", + "fields": { + "currentPose": { + "name": "CurrentPose", + "type": "skeleton_pose", + "exclude_from_serialize": true + }, + "type": { + "name": "Type", + "type": "clip_type", + "exclude_from_serialize": true + }, + "frame": { + "name": "Frame", + "type": "int", + "exclude_from_serialize": true + }, + "numberOfFrames": { + "name": "NumberOfFrames", + "type": "int", + "exclude_from_serialize": true + }, + "frameTimer": { + "name": "FrameTimer", + "type": "float", + "exclude_from_serialize": true + }, + "timePerFrame": { + "name": "TimePerFrame", + "type": "float", + "exclude_from_serialize": true + } + }, + "defaults": { + "timerPerFrame": "100f" + } + }, + "area_change": { + "name": "AreaChange", + "fields": { + "newArea": { + "name": "NewArea", + "type": "string" + }, + "newX": { + "name": "NewX", + "type": "float" + }, + "newY": { + "name": "NewY", + "type": "float" + } + }, + "defaults": { + "newArea": "\"\"", + "newX": "0f", + "newY": "0f" + } + }, + "armor": { + "name": "Armor", + "fields": { + "armorId": { + "name": "ArmorId", + "type": "string" + } + } + }, + "attack_intent": { + "name": "AttackIntent", + "is_pooled": true, + "fields": { + "frame": { + "name": "Frame", + "type": "int" + }, + "decayFrame": { + "name": "DecayFrame", + "type": "int" + }, + "damageFrame": { + "name": "DamageFrame", + "type": "int" + }, + "frameTimer": { + "name": "FrameTimer", + "type": "float" + }, + "timePerFrame": { + "name": "TimePerFrame", + "type": "float" + } + }, + "defaults": { + "frame": "0", + "decayFrame": "3", + "damageFrame": "1", + "frameTimer": "0f", + "timePerFrame": "0.100f" + } + }, + "bag": { + "name": "Bag", + "fields": { + "name": { + "name": "Name", + "type": "string" + }, + "capacity": { + "name": "Capacity", + "type": "int" + } + }, + "defaults": { + "name": "\"Inventory\"", + "capacity": "25" + } + }, + "body": { + "name": "Body", + "fields": { + "bodyId": { + "name": "BodyId", + "type": "string" + } + } + }, + "dead": { + "name": "Dead", + "is_pooled": true, + "fields": {} + }, + "door": { + "name": "Door", + "fields": { + "newArea": { + "name": "NewArea", + "type": "string" + }, + "newX": { + "name": "NewX", + "type": "float" + }, + "newY": { + "name": "NewY", + "type": "float" + } + } + }, + "exp_boost": { + "name": "ExperienceBoost", + "fields": { + "experience": { + "name": "Experience", + "type": "int" + }, + "hasBeenAbsorbed": { + "name": "HasBeenAbsorbed", + "type": "bool" + } + }, + "defaults": { + "experience": "10", + "hasBeenAbsorbed": "false" + } + }, + "exp_orb_thought": { + "name": "ExperienceOrbThought", + "fields": {} + }, + "hat": { + "name": "Hat", + "fields": { + "hatId": { + "name": "HatId", + "type": "string" + } + } + }, + "item": { + "name": "Item", + "fields": { + "name": { + "name": "Name", + "type": "string" + }, + "icon": { + "name": "Icon", + "type": "string" + }, + "slot": { + "name": "Slot", + "type": "int" + }, + "itemId": { + "name": "ItemId", + "type": "string" + }, + "equipmentSlot": { + "name": "EquipmentSlot", + "type": "string" + }, + "isEquipped": { + "name": "IsEquipped", + "type": "bool" + } + }, + "defaults": { + "name": "\"\"", + "icon": "\"\"", + "slot": "0", + "itemId": "\"\"", + "equipmentSlot": "\"\"", + "isEquipped": "false" + } + }, + "location": { + "name": "Location", + "fields": { + "area": { + "name": "Area", + "type": "string" + } + }, + "defaults": { + "area": "\"\"" + } + }, + "mask": { + "name": "Mask", + "fields": { + "maskId": { + "name": "MaskId", + "type": "string" + } + } + }, + "movement": { + "name": "Movement", + "fields": { + "previousX": { + "name": "PreviousX", + "type": "float" + }, + "previousY": { + "name": "PreviousY", + "type": "float" + }, + "layer": { + "name": "Layer", + "type": "int" + }, + "x": { + "name": "X", + "type": "float" + }, + "y": { + "name": "Y", + "type": "float" + }, + "collisionOffsetY": { + "name": "CollisionOffsetY", + "type": "float" + }, + "speed": { + "name": "Speed", + "type": "float" + }, + "moveDirection": { + "name": "MoveDirection", + "type": "float" + }, + "lookDirection": { + "name": "LookDirection", + "type": "float" + }, + "acceleration": { + "name": "ACCELERATION", + "type": "float" + }, + "maxSpeed": { + "name": "MAX_SPEED", + "type": "float" + }, + "turnSpeed": { + "name": "TURN_SPEED", + "type": "float" + } + }, + "defaults": { + "previousX": "0f", + "previousY": "0f", + "layer": "1", + "x": "0f", + "y": "0f", + "collisionOffsetY": "0f", + "speed": "0f", + "moveDirection": "0f", + "lookDirection": "0f", + "ACCELERATION": "200f", + "MAX_SPEED": "100f", + "TURN_SPEED": "5f" + } + }, + "movement_intent": { + "name": "MovementIntent", + "is_pooled": true, + "fields": { + "moveRight": { + "name": "MoveRight", + "type": "bool" + }, + "moveLeft": { + "name": "MoveLeft", + "type": "bool" + }, + "moveDown": { + "name": "MoveDown", + "type": "bool" + }, + "moveUp": { + "name": "MoveUp", + "type": "bool" + } + }, + "defaults": { + "moveRight": "false", + "moveLeft": "false", + "moveDown": "false", + "moveUp": "false" + } + }, + "player": { + "name": "Player", + "fields": { + "playerId": { + "name": "PlayerId", + "type": "int" + } + }, + "defaults": { + "playerId": "-1" + } + }, + "player_thought": { + "name": "PlayerThought", + "fields": {} + }, + "skeleton": { + "name": "Skeleton", + "fields": { + "type": { + "name": "Type", + "type": "skeleton_type" + }, + "pose": { + "name": "Pose", + "type": "skeleton_pose" + }, + "frame": { + "name": "Frame", + "type": "int", + "exclude_from_serialize": true + }, + "layer": { + "name": "Layer", + "type": "int", + "exclude_from_serialize": true + }, + "subLayer": { + "name": "SubLayer", + "type": "int", + "exclude_from_serialize": true + }, + "direction": { + "name": "Direction", + "type": "direction", + "exclude_from_serialize": true + }, + "rootX": { + "name": "RootX", + "type": "int", + "exclude_from_serialize": true + }, + "rootY": { + "name": "RootY", + "type": "int", + "exclude_from_serialize": true + }, + "renderOffsetY": { + "name": "RenderOffsetY", + "type": "int", + "exclude_from_serialize": true + }, + "weaponOffsetX": { + "name": "WeaponOffsetX", + "type": "int", + "exclude_from_serialize": true + }, + "weaponOffsetY": { + "name": "WeaponOffsetY", + "type": "int", + "exclude_from_serialize": true + }, + "weaponOffsetAngle": { + "name": "WeaponOffsetAngle", + "type": "float", + "exclude_from_serialize": true + }, + "armorOffsetX": { + "name": "ArmorOffsetX", + "type": "int", + "exclude_from_serialize": true + }, + "armorOffsetY": { + "name": "ArmorOffsetY", + "type": "int", + "exclude_from_serialize": true + }, + "armorOffsetAngle": { + "name": "ArmorOffsetAngle", + "type": "float", + "exclude_from_serialize": true + }, + "maskOffsetX": { + "name": "MaskOffsetX", + "type": "int", + "exclude_from_serialize": true + }, + "maskOffsetY": { + "name": "MaskOffsetY", + "type": "int", + "exclude_from_serialize": true + }, + "maskOffsetAngle": { + "name": "MaskOffsetAngle", + "type": "float", + "exclude_from_serialize": true + }, + "hatOffsetX": { + "name": "HatOffsetX", + "type": "int", + "exclude_from_serialize": true + }, + "hatOffsetY": { + "name": "HatOffsetY", + "type": "int", + "exclude_from_serialize": true + }, + "hatOffsetAngle": { + "name": "HatOffsetAngle", + "type": "float", + "exclude_from_serialize": true + } + } + }, + "slime_spawner": { + "name": "SlimeSpawner", + "fields": { + "x": { + "name": "X", + "type": "float" + }, + "y": { + "name": "Y", + "type": "float" + }, + "SLIME_LIMIT": { + "name": "SLIME_LIMIT", + "type": "int" + }, + "thinkDelay": { + "name": "ThinkDelay", + "type": "delay" + } + }, + "defaults": { + "x": "500f", + "y": "400f", + "SLIME_LIMIT": "3", + "thinkDelay->delayInSeconds": "5f" + } + }, + "slime_thought": { + "name": "SlimeThought", + "fields": { + "thinkDelay": { + "name": "ThinkDelay", + "type": "delay", + "exclude_from_serialize": true + }, + "thinkAction": { + "name": "ThinkAction", + "type": "int", + "exclude_from_serialize": true + } + }, + "defaults": { + "thinkAction": "0" + } + }, + "stats": { + "name": "Stats", + "fields": { + "experience": { + "name": "Experience", + "type": "int" + }, + "maxExperience": { + "name": "MaxExperience", + "type": "int" + }, + "health": { + "name": "Health", + "type": "int" + }, + "maxHealth": { + "name": "MaxHealth", + "type": "int" + } + }, + "defaults": { + "experience": "0", + "maxExperience": "100", + "health": "100", + "maxHealth": "100" + } + }, + "weapon": { + "name": "Weapon", + "fields": { + "weaponType": { + "name": "WeaponType", + "type": "weapon_type" + }, + "weaponId": { + "name": "WeaponId", + "type": "string" + }, + "attackAngle": { + "name": "AttackAngle", + "type": "float" + }, + "attackRange": { + "name": "AttackRange", + "type": "float" + }, + "attackDamage": { + "name": "AttackDamage", + "type": "int" + } + }, + "defaults": { + "attackAngle": "0.78f", + "attackRange": "21f", + "attackDamage": "5" + } + } +} diff --git a/Ozzyria.Model/CodeGen/Files/prefab_defs.json b/Ozzyria.Model/CodeGen/Files/prefab_defs.json new file mode 100644 index 0000000..2c63c08 --- /dev/null +++ b/Ozzyria.Model/CodeGen/Files/prefab_defs.json @@ -0,0 +1,2 @@ +{ +} diff --git a/Ozzyria.Model/CodeGen/Files/type_defs.json b/Ozzyria.Model/CodeGen/Files/type_defs.json new file mode 100644 index 0000000..b2bc988 --- /dev/null +++ b/Ozzyria.Model/CodeGen/Files/type_defs.json @@ -0,0 +1,72 @@ +{ + "skeleton_pose": { + "name": "SkeletonPose", + "type": "enum", + "values": [ + "Idle", + "Walk", + "Attack" + ] + }, + "skeleton_type": { + "name": "SkeletonType", + "type": "enum", + "values": [ + "Humanoid", + "Slime", + "Static" + ] + }, + "direction": { + "name": "Direction", + "type": "enum", + "values": [ + "None", + "Up", + "Down", + "Left", + "Right" + ] + }, + "clip_type": { + "name": "ClipType", + "type": "enum", + "values": [ + "Decay", + "Loop", + "Stall" + ] + }, + "delay": { + "name": "Delay", + "type": "class", + "fields": { + "delayInSeconds": { + "name": "DelayInSeconds", + "type": "float" + }, + "timer": { + "name": "Timer", + "type": "float" + }, + "ready": { + "name": "Ready", + "type": "bool", + "exclude_from_serialize": true + } + }, + "defaults": { + "delayInSeconds": "0.5f", + "timer": "0.5f", + "ready": "false" + } + }, + "weapon_type": { + "name": "WeaponType", + "type": "enum", + "values": [ + "Empty", + "Sword" + ] + } +} diff --git a/Ozzyria.Model/CodeGen/Generators/ClassGenerator.cs b/Ozzyria.Model/CodeGen/Generators/ClassGenerator.cs new file mode 100644 index 0000000..5cacd2c --- /dev/null +++ b/Ozzyria.Model/CodeGen/Generators/ClassGenerator.cs @@ -0,0 +1,95 @@ +using Grynt.Generators.Decorators; +using Grynt.Model.Definitions; +using Grynt.Model.Packages; +using Ozzyria.Model.Types; +using System.Collections.Generic; + +namespace Grynt.Generators +{ + public class ClassGenerator + { + private string _ns = ""; + private string _destinationNamespace; + private ComponentPackage _componentPackage; + private IClassDecorator[] _classDecorators; + + public ClassGenerator(string ns, string destinationNamespace, IClassDecorator[] classDecorators) + { + _ns = ns; + _destinationNamespace = destinationNamespace; + _classDecorators = classDecorators; + } + + public string Generate(string className, List fields, ValuePacket defaults = null) + { + var code = @"{{NAMESPACE_PREAMBLE}} +{ + public class {{CLASS_NAME}}{{INTERFACES}} + { + {{INTERFACE_TAGS}} + } +} +"; + + string interfaces = ""; + string interfaceTags = ""; + foreach (var classDecorator in _classDecorators) + { + var interfaceName = classDecorator.InterfaceName(className); + if (interfaceName != "") + { + if (interfaces == "") + interfaces = " : "; + else + interfaces += ", "; + + interfaces += interfaceName; + } + + var interfaceTag = classDecorator.TemplateTag(); + if (interfaceTag != "") + { + interfaceTags += " " + interfaceTag + "\r\n"; + } + } + + code = ApplyNamespace(code) + .Replace("{{CLASS_NAME}}", className) + .Replace("{{INTERFACES}}", interfaces) + .Replace("{{INTERFACE_TAGS}}", interfaceTags.Trim()); + return Decorate(code, fields, defaults); + } + + private string Decorate(string code, List fields, ValuePacket defaults = null) + { + foreach (var decorator in _classDecorators) + { + code = decorator.Actualize(code, fields, defaults); + } + return code; + } + + private string ApplyNamespace(string code) + { + return code + .Replace("{{NAMESPACE_PREAMBLE}}", NamespacePreamble()) + .Replace("{{NAMESPACE}}", _ns == "" ? "" : (_ns + ".")); + } + + private string NamespacePreamble() + { + if (_destinationNamespace == "Types") + { + return "namespace {{NAMESPACE}}Types"; + } + else + { + // ensure types are imported + return @"using {{NAMESPACE}}Types; + +namespace {{NAMESPACE}}" + _destinationNamespace; + } + + } + } +} diff --git a/Ozzyria.Model/CodeGen/Generators/ComponentGenerator.cs b/Ozzyria.Model/CodeGen/Generators/ComponentGenerator.cs new file mode 100644 index 0000000..a20d459 --- /dev/null +++ b/Ozzyria.Model/CodeGen/Generators/ComponentGenerator.cs @@ -0,0 +1,42 @@ +using Grynt.Generators.Decorators; +using Grynt.Generators.Fields; +using Grynt.Model.Definitions; +using Grynt.Model.Packages; +using System.Linq; + +namespace Grynt.Generators +{ + public class ComponentGenerator + { + private readonly ClassGenerator _componentClassGenerator; + private readonly ClassGenerator _pooledComponentClassGenerator; + + public ComponentGenerator(string ns, TypePackage typePackage) + { + var grecsFieldGenerator = new GrecsFieldGenerator(typePackage); + _componentClassGenerator = new ClassGenerator(ns, "Components",new IClassDecorator[] { + new GrecsComponentDecorator(), + new FieldsDecorator(grecsFieldGenerator), + new SerializableDecorator(typePackage), + new HydrateableDecorator(typePackage) + }); + _pooledComponentClassGenerator = new ClassGenerator(ns, "Components", new IClassDecorator[] { + new GrecsPooledComponentDecorator(), + new FieldsDecorator(grecsFieldGenerator), + new SerializableDecorator(typePackage), + new HydrateableDecorator(typePackage) + }); + } + + public string Generate(ComponentDefinition componentDefinition) + { + if (componentDefinition.IsPooled) + { + return _pooledComponentClassGenerator.Generate(componentDefinition.Name, componentDefinition.Fields.Values.ToList(), componentDefinition.Defaults); + } + + return _componentClassGenerator.Generate(componentDefinition.Name, componentDefinition.Fields.Values.ToList(), componentDefinition.Defaults); + } + + } +} diff --git a/Ozzyria.Model/CodeGen/Generators/Decorators/FieldsDecorator.cs b/Ozzyria.Model/CodeGen/Generators/Decorators/FieldsDecorator.cs new file mode 100644 index 0000000..878f529 --- /dev/null +++ b/Ozzyria.Model/CodeGen/Generators/Decorators/FieldsDecorator.cs @@ -0,0 +1,32 @@ +using Grynt.Generators.Fields; +using Grynt.Model.Definitions; +using Ozzyria.Model.Types; +using System.Collections.Generic; + +namespace Grynt.Generators.Decorators +{ + public class FieldsDecorator : IClassDecorator + { + private readonly IFieldGenerator _fieldGenerator; + public FieldsDecorator(IFieldGenerator fieldGenerator) + { + _fieldGenerator = fieldGenerator; + } + + public string Actualize(string code, List fields, ValuePacket defaults = null) + { + return code.Replace(TemplateTag(), _fieldGenerator.GenerateFieldDeclarations(fields, defaults).Trim()); + } + + public string InterfaceName(string className) + { + // no additional interface needed + return ""; + } + + public string TemplateTag() + { + return "{{FIELDS}}"; + } + } +} diff --git a/Ozzyria.Model/CodeGen/Generators/Decorators/GrecsComponentDecorator.cs b/Ozzyria.Model/CodeGen/Generators/Decorators/GrecsComponentDecorator.cs new file mode 100644 index 0000000..7aedc01 --- /dev/null +++ b/Ozzyria.Model/CodeGen/Generators/Decorators/GrecsComponentDecorator.cs @@ -0,0 +1,26 @@ +using Grynt.Model.Definitions; +using Ozzyria.Model.Types; +using System.Collections.Generic; + +namespace Grynt.Generators.Decorators +{ + public class GrecsComponentDecorator : IClassDecorator + { + public string Actualize(string code, List fields, ValuePacket defaults = null) + { + // nothing to manipulate + return code; + } + + public string InterfaceName(string className) + { + return "Grecs.Component"; + } + + public string TemplateTag() + { + // nothing to inject into code, other than an interface + return ""; + } + } +} diff --git a/Ozzyria.Model/CodeGen/Generators/Decorators/GrecsPooledComponentDecorator.cs b/Ozzyria.Model/CodeGen/Generators/Decorators/GrecsPooledComponentDecorator.cs new file mode 100644 index 0000000..dd1f26d --- /dev/null +++ b/Ozzyria.Model/CodeGen/Generators/Decorators/GrecsPooledComponentDecorator.cs @@ -0,0 +1,26 @@ +using Grynt.Model.Definitions; +using Ozzyria.Model.Types; +using System.Collections.Generic; + +namespace Grynt.Generators.Decorators +{ + internal class GrecsPooledComponentDecorator : IClassDecorator + { + public string Actualize(string code, List fields, ValuePacket defaults = null) + { + // nothing to manipulate + return code; + } + + public string InterfaceName(string className) + { + return "Grecs.PooledComponent<" + className + ">"; + } + + public string TemplateTag() + { + // nothing to inject into code, other than an interface + return ""; + } + } +} diff --git a/Ozzyria.Model/CodeGen/Generators/Decorators/HydrateableDecorator.cs b/Ozzyria.Model/CodeGen/Generators/Decorators/HydrateableDecorator.cs new file mode 100644 index 0000000..ec5027a --- /dev/null +++ b/Ozzyria.Model/CodeGen/Generators/Decorators/HydrateableDecorator.cs @@ -0,0 +1,103 @@ +using Grynt.Model.Definitions; +using Grynt.Model.Packages; +using Ozzyria.Model.Types; +using System.Collections.Generic; + +namespace Grynt.Generators.Decorators +{ + public class HydrateableDecorator : IClassDecorator + { + private readonly TypePackage _typePackage; + public HydrateableDecorator(TypePackage typePackage) + { + _typePackage = typePackage; + } + + public string Actualize(string code, List fields, ValuePacket defaults = null) + { + var codeDecoration = @" + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + {{HYDRATE}} + } +"; + + var hydrateCode = ""; + foreach (var field in fields) + { + var fieldType = _typePackage.GetDefinition(field.TypeId); + if (fieldType == null) + continue; + + hydrateCode += " " + GenerateFieldHydration(field, fieldType).Trim() + "\r\n"; + } + + return code.Replace(TemplateTag(), codeDecoration.Trim()) + .Replace("{{HYDRATE}}", hydrateCode.Trim()); + } + + private string GenerateFieldHydration(FieldDefinition field, TypeDefinition type, string fieldPrefix = "", string valuesPostfix = "") + { + var valuesName = "values" + valuesPostfix; + var code = @"if ({{VALUES_PARAM}}.HasValueFor(""{{FIELD_ID}}"")) + { + {{HYDRATE_FIELD}} + }"; + + var hyrdateCode = ""; + switch (type.Type) + { + case TypeDefinition.TYPE_ASSUMED: + if (type.Id == "string") + { + hyrdateCode = fieldPrefix + field.Name + " = {{VALUES_PARAM}}[\"{{FIELD_ID}}\"].Trim('\"');"; + } + else + { + hyrdateCode = fieldPrefix + field.Name + " = " + type.Id + ".Parse({{VALUES_PARAM}}[\"{{FIELD_ID}}\"]);"; + } + break; + case TypeDefinition.TYPE_ENUM: + hyrdateCode = fieldPrefix + field.Name + " = (" + type.Name + ")Enum.Parse(typeof(" + type.Name + "), {{VALUES_PARAM}}[\"{{FIELD_ID}}\"], true);"; + break; + case TypeDefinition.TYPE_CLASS: + var fieldValuesPostFix = valuesPostfix + "_" + field.Id; + var fieldValuesName = "values" + fieldValuesPostFix; + hyrdateCode += " var " + fieldValuesName + " = " + valuesName + ".Extract(\"" + field.Id + "\");\r\n"; + foreach (var subFieldByFieldId in type.ClassFields) + { + var subField = subFieldByFieldId.Value; + var subType = _typePackage.GetDefinition(subField.TypeId); + if (subType == null || subField == null) + continue; + + var subHydrateBlock = GenerateFieldHydration(subField, subType, fieldPrefix + field.Name + ".", fieldValuesPostFix); + if (subHydrateBlock != "") + { + hyrdateCode += " " + subHydrateBlock.Trim() + "\r\n"; + } + } + break; + } + + return code.Replace("{{HYDRATE_FIELD}}", hyrdateCode.Trim()) + .Replace("{{FIELD_ID}}", field.Id) + .Replace("{{VALUES_PARAM}}", valuesName); + } + + public string InterfaceName(string className) + { + return "IHydrateable"; + } + + public string TemplateTag() + { + return "{{HYRDATEABLE}}"; + } + } +} diff --git a/Ozzyria.Model/CodeGen/Generators/Decorators/IClassDecorator.cs b/Ozzyria.Model/CodeGen/Generators/Decorators/IClassDecorator.cs new file mode 100644 index 0000000..df7bed7 --- /dev/null +++ b/Ozzyria.Model/CodeGen/Generators/Decorators/IClassDecorator.cs @@ -0,0 +1,13 @@ +using Grynt.Model.Definitions; +using Ozzyria.Model.Types; +using System.Collections.Generic; + +namespace Grynt.Generators.Decorators +{ + public interface IClassDecorator + { + public string InterfaceName(string className); + public string TemplateTag(); + public string Actualize(string code, List fields, ValuePacket defaults = null); + } +} diff --git a/Ozzyria.Model/CodeGen/Generators/Decorators/SerializableDecorator.cs b/Ozzyria.Model/CodeGen/Generators/Decorators/SerializableDecorator.cs new file mode 100644 index 0000000..bf0e37e --- /dev/null +++ b/Ozzyria.Model/CodeGen/Generators/Decorators/SerializableDecorator.cs @@ -0,0 +1,155 @@ +using Grynt.Model.Definitions; +using Grynt.Model.Packages; +using Ozzyria.Model.Types; +using Microsoft.VisualBasic.FileIO; +using System.Collections.Generic; + +namespace Grynt.Generators.Decorators +{ + public class SerializableDecorator : IClassDecorator + { + private readonly TypePackage _typePackage; + public SerializableDecorator(TypePackage typePackage) + { + _typePackage = typePackage; + } + + public string Actualize(string code, List fields, ValuePacket defaults = null) + { + var codeDecoration = @" + public void Write(System.IO.BinaryWriter w) + { + {{WRITER}} + } + + public void Read(System.IO.BinaryReader r) + { + {{READER}} + } +"; + + var writerCode = ""; + var readerCode = ""; + foreach(var field in fields) + { + var fieldType = _typePackage.GetDefinition(field.TypeId); + if (fieldType == null || field.ExcludeFromSerialize) + continue; + + writerCode += " " + GenerateFieldWriter(field, fieldType).Trim() + "\r\n"; + readerCode += " " + GenerateFieldReader(field, fieldType).Trim() + "\r\n"; + } + + return code.Replace(TemplateTag(), codeDecoration.Trim()) + .Replace("{{WRITER}}", writerCode.Trim()) + .Replace("{{READER}}", readerCode.Trim()); + } + + private string GenerateFieldWriter(FieldDefinition field, TypeDefinition type, string fieldPrefix = "") + { + var code = ""; + if (field.ExcludeFromSerialize) + return code; + + switch (type.Type) + { + case TypeDefinition.TYPE_ASSUMED: + // use raw value + return "w.Write(" + fieldPrefix + field.Name + ");"; + case TypeDefinition.TYPE_ENUM: + // enums are serialized as Int32's + return "w.Write((int)" + fieldPrefix + field.Name + ");"; + case TypeDefinition.TYPE_CLASS: + // build writer block for class + var writerBlock = ""; + + foreach (var subFieldByFieldId in type.ClassFields) + { + var subField = subFieldByFieldId.Value; + var subType = _typePackage.GetDefinition(subField.TypeId); + if (subType == null || subField == null) + continue; + + var subWriterBlock = GenerateFieldWriter(subField, subType, fieldPrefix + field.Name + "."); + if (subWriterBlock != "") + { + writerBlock += " " + subWriterBlock.Trim() + "\r\n"; + } + } + + return writerBlock; + } + + return ""; + } + + private string GenerateFieldReader(FieldDefinition field, TypeDefinition type, string fieldPrefix = "") + { + var code = ""; + if (field.ExcludeFromSerialize) + return code; + + switch (type.Type) + { + case TypeDefinition.TYPE_ASSUMED: + var readType = ""; + switch (type.Id) + { + case "uint": + readType = "UInt32"; + break; + case "int": + readType = "Int32"; + break; + case "bool": + readType = "Boolean"; + break; + case "float": + readType = "Single"; + break; + case "string": + readType = "String"; + break; + } + if (readType == "") + return ""; + + return fieldPrefix + field.Name + " = r.Read"+readType+"();"; + case TypeDefinition.TYPE_ENUM: + // enums are serialized as Int32's + return fieldPrefix + field.Name + " = ("+type.Name+")r.ReadInt32();"; + case TypeDefinition.TYPE_CLASS: + // build reader block for class + var readerBlock = ""; + + foreach (var subFieldByFieldId in type.ClassFields) + { + var subField = subFieldByFieldId.Value; + var subType = _typePackage.GetDefinition(subField.TypeId); + if (subType == null || subField == null) + continue; + + var subReaderBlock = GenerateFieldReader(subField, subType, fieldPrefix + field.Name + "."); + if (subReaderBlock != "") + { + readerBlock += " " + subReaderBlock.Trim() + "\r\n"; + } + } + + return readerBlock; + } + + return ""; + } + + public string InterfaceName(string className) + { + return "ISerializable"; + } + + public string TemplateTag() + { + return "{{SERIALIZABLE}}"; + } + } +} diff --git a/Ozzyria.Model/CodeGen/Generators/Fields/FieldsGenerator.cs b/Ozzyria.Model/CodeGen/Generators/Fields/FieldsGenerator.cs new file mode 100644 index 0000000..1b8fcae --- /dev/null +++ b/Ozzyria.Model/CodeGen/Generators/Fields/FieldsGenerator.cs @@ -0,0 +1,133 @@ +using Grynt.Model.Definitions; +using Grynt.Model.Packages; +using Ozzyria.Model.Types; +using System.Collections.Generic; + +namespace Grynt.Generators.Fields +{ + public class FieldsGenerator : IFieldGenerator + { + protected readonly TypePackage _typePackage; + + protected string _callTrigger = "TriggerChange?.Invoke();"; + + public FieldsGenerator(TypePackage typePackage) + { + _typePackage = typePackage; + } + + public string GenerateFieldDeclarations(List fields, ValuePacket defaults = null) + { + var buildTriggerPreamble = BuildTriggerPreamble(); + var code = buildTriggerPreamble ? GenerateTriggerCode() : ""; + var fieldPropagationCode = ""; + foreach (var field in fields) + { + var type = _typePackage.GetDefinition(field.TypeId); + if (type == null) + return ""; + + if(buildTriggerPreamble && type.Type == TypeDefinition.TYPE_CLASS) + { + // add trigger propagation as trigger gets changed into preamble + fieldPropagationCode += GenerateTriggerPropagation(field) + "\r\n "; + } + + code += GenerateFieldDeclaration(field, type, defaults) + "\r\n "; + } + return code.Replace("{{FIELD_PROPAGATION}}", fieldPropagationCode.Trim()); + } + + protected virtual bool BuildTriggerPreamble() + { + return true; + } + + + protected string GenerateTriggerCode() + { + return @"private System.Action? _triggerChange; + public System.Action? TriggerChange { get => _triggerChange; set + { + _triggerChange = value; + {{FIELD_PROPAGATION}} + } + } + + "; + } + + protected string GenerateTriggerPropagation(FieldDefinition field) + { + return field.Name + ".TriggerChange = TriggerChange;"; + } + + private string GenerateFieldDeclaration(FieldDefinition field, TypeDefinition type, ValuePacket defaults = null) + { + var code = @" + private {{TYPE_NAME}} _{{FIELD_ID}}{{DEFAULTS}}; + public {{TYPE_NAME}} {{FIELD_NAME}} + { + get => _{{FIELD_ID}}; set + { + if (!_{{FIELD_ID}}.Equals(value)) + { + _{{FIELD_ID}} = value; + {{FIELD_TRIGGER_PROPAGATION}} + {{TRIGGER_CHANGE_CALL}} + } + } + } +"; + return code.Replace("{{TYPE_NAME}}", type.Name) + .Replace("{{FIELD_NAME}}", field.Name) + .Replace("{{FIELD_ID}}", field.Id) + .Replace("{{DEFAULTS}}", GenerateDefaults(field, type, defaults)) + .Replace("{{FIELD_TRIGGER_PROPAGATION}}", type.Type == TypeDefinition.TYPE_CLASS ? ("if (value != null) { _"+field.Id+".TriggerChange = TriggerChange; }") : "") + .Replace("{{TRIGGER_CHANGE_CALL}}", _callTrigger); + } + + private string GenerateDefaults(FieldDefinition field, TypeDefinition type, ValuePacket defaults = null) + { + if (defaults == null || !defaults.HasValueFor(field.Id)) + { + return ""; + } + + var code = " = {{VALUE}}"; + switch (type.Type) + { + case TypeDefinition.TYPE_ASSUMED: + // use raw value + return code.Replace("{{VALUE}}", defaults[field.Id]); + case TypeDefinition.TYPE_ENUM: + // qualify value with enum Type + return code.Replace("{{VALUE}}", type.Name + "." + defaults[field.Id]); + case TypeDefinition.TYPE_CLASS: + // build class intializer syntax + var initializers = ""; + var fieldDefaults = defaults.Extract(field.Id); + if (fieldDefaults.Count <= 0) + break; + + foreach (var subFieldByFieldId in type.ClassFields) + { + var subField = subFieldByFieldId.Value; + var subType = _typePackage.GetDefinition(subField.TypeId); + if (subType == null || subField == null || !fieldDefaults.HasValueFor(subField.Id)) + continue; + + var subAssignments = GenerateDefaults(subField, subType, fieldDefaults); + if (subAssignments != "") + { + initializers += subField.Name + subAssignments + ", "; + } + } + + return code.Replace("{{VALUE}}", "new " + type.Name + "{ " + initializers + " }"); + } + + return ""; + } + } +} diff --git a/Ozzyria.Model/CodeGen/Generators/Fields/GrecsFieldGenerator.cs b/Ozzyria.Model/CodeGen/Generators/Fields/GrecsFieldGenerator.cs new file mode 100644 index 0000000..12d94d6 --- /dev/null +++ b/Ozzyria.Model/CodeGen/Generators/Fields/GrecsFieldGenerator.cs @@ -0,0 +1,18 @@ +using Grynt.Model.Packages; +namespace Grynt.Generators.Fields +{ + public class GrecsFieldGenerator : FieldsGenerator + { + public GrecsFieldGenerator(TypePackage typePackage): base(typePackage) { + _callTrigger = "TriggerChange();"; + } + + protected override bool BuildTriggerPreamble() + { + // Grecs has TriggerChange baked right in + return false; + } + + + } +} diff --git a/Ozzyria.Model/CodeGen/Generators/Fields/IFieldGenerator.cs b/Ozzyria.Model/CodeGen/Generators/Fields/IFieldGenerator.cs new file mode 100644 index 0000000..ce0ed93 --- /dev/null +++ b/Ozzyria.Model/CodeGen/Generators/Fields/IFieldGenerator.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using Grynt.Model.Definitions; +using Ozzyria.Model.Types; + +namespace Grynt.Generators.Fields +{ + public interface IFieldGenerator + { + public string GenerateFieldDeclarations(List fields, ValuePacket defaults = null); + } +} diff --git a/Ozzyria.Model/CodeGen/Generators/TypeGenerator.cs b/Ozzyria.Model/CodeGen/Generators/TypeGenerator.cs new file mode 100644 index 0000000..64af6c3 --- /dev/null +++ b/Ozzyria.Model/CodeGen/Generators/TypeGenerator.cs @@ -0,0 +1,57 @@ +using Grynt.Model.Definitions; +using Grynt.Model.Packages; +using System; +using System.Linq; + +namespace Grynt.Generators +{ + public class TypeGenerator + { + private string _ns = ""; + private TypePackage _typePackage; + private ClassGenerator _classGenerator; + + public TypeGenerator(string ns, TypePackage typePackage, ClassGenerator classGenerator) + { + _ns = ns; + _typePackage = typePackage; + _classGenerator = classGenerator; + } + + public string Generate(TypeDefinition type) { + var code = ""; + switch (type.Type) + { + case TypeDefinition.TYPE_ENUM: + code = GenerateEnum(type); + break; + case TypeDefinition.TYPE_CLASS: + code = _classGenerator.Generate(type.Name, type.ClassFields.Values.ToList(), type.ClassDefaults); + break; + } + return code; + } + + private string ApplyNamespace(string code) + { + return code.Replace("{{NAMESPACE}}", _ns == "" ? "" : (_ns + ".")); + } + + private string GenerateEnum(TypeDefinition type) + { + + var code = @"namespace {{NAMESPACE}}Types +{ + public enum {{ENUM_NAME}} + { + {{ENUM_VALUES}} + } +} +"; + + return ApplyNamespace(code) + .Replace("{{ENUM_NAME}}", type.Name) + .Replace("{{ENUM_VALUES}}", String.Join(", \r\n ", type.EnumValues).Trim()); + } + } +} diff --git a/Ozzyria.Model/CodeGen/Specifications/PrefabSpecification.cs b/Ozzyria.Model/CodeGen/Specifications/PrefabSpecification.cs new file mode 100644 index 0000000..86eee6a --- /dev/null +++ b/Ozzyria.Model/CodeGen/Specifications/PrefabSpecification.cs @@ -0,0 +1,10 @@ +using Ozzyria.Model.Types; + +namespace Grynt.Model.Specifications +{ + public class PrefabSpecification + { + public string PrefabId { get; set; } + public ValuePacket ValueOverrides { get; set; } + } +} diff --git a/Ozzyria.Model/Components/Animator.cs b/Ozzyria.Model/Components/Animator.cs new file mode 100644 index 0000000..feeb628 --- /dev/null +++ b/Ozzyria.Model/Components/Animator.cs @@ -0,0 +1,137 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class Animator : Grecs.Component, ISerializable, IHydrateable + { + private SkeletonPose _currentPose; + public SkeletonPose CurrentPose + { + get => _currentPose; set + { + if (!_currentPose.Equals(value)) + { + _currentPose = value; + + TriggerChange(); + } + } + } + + + private ClipType _type; + public ClipType Type + { + get => _type; set + { + if (!_type.Equals(value)) + { + _type = value; + + TriggerChange(); + } + } + } + + + private int _frame; + public int Frame + { + get => _frame; set + { + if (!_frame.Equals(value)) + { + _frame = value; + + TriggerChange(); + } + } + } + + + private int _numberOfFrames; + public int NumberOfFrames + { + get => _numberOfFrames; set + { + if (!_numberOfFrames.Equals(value)) + { + _numberOfFrames = value; + + TriggerChange(); + } + } + } + + + private float _frameTimer; + public float FrameTimer + { + get => _frameTimer; set + { + if (!_frameTimer.Equals(value)) + { + _frameTimer = value; + + TriggerChange(); + } + } + } + + + private float _timePerFrame; + public float TimePerFrame + { + get => _timePerFrame; set + { + if (!_timePerFrame.Equals(value)) + { + _timePerFrame = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + + } + + public void Read(System.IO.BinaryReader r) + { + + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("currentPose")) + { + CurrentPose = (SkeletonPose)Enum.Parse(typeof(SkeletonPose), values["currentPose"], true); + } + if (values.HasValueFor("type")) + { + Type = (ClipType)Enum.Parse(typeof(ClipType), values["type"], true); + } + if (values.HasValueFor("frame")) + { + Frame = int.Parse(values["frame"]); + } + if (values.HasValueFor("numberOfFrames")) + { + NumberOfFrames = int.Parse(values["numberOfFrames"]); + } + if (values.HasValueFor("frameTimer")) + { + FrameTimer = float.Parse(values["frameTimer"]); + } + if (values.HasValueFor("timePerFrame")) + { + TimePerFrame = float.Parse(values["timePerFrame"]); + } + } + } +} diff --git a/Ozzyria.Model/Components/AreaChange.cs b/Ozzyria.Model/Components/AreaChange.cs new file mode 100644 index 0000000..5668c0d --- /dev/null +++ b/Ozzyria.Model/Components/AreaChange.cs @@ -0,0 +1,84 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class AreaChange : Grecs.Component, ISerializable, IHydrateable + { + private string _newArea = ""; + public string NewArea + { + get => _newArea; set + { + if (!_newArea.Equals(value)) + { + _newArea = value; + + TriggerChange(); + } + } + } + + + private float _newX = 0f; + public float NewX + { + get => _newX; set + { + if (!_newX.Equals(value)) + { + _newX = value; + + TriggerChange(); + } + } + } + + + private float _newY = 0f; + public float NewY + { + get => _newY; set + { + if (!_newY.Equals(value)) + { + _newY = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write(NewArea); + w.Write(NewX); + w.Write(NewY); + } + + public void Read(System.IO.BinaryReader r) + { + NewArea = r.ReadString(); + NewX = r.ReadSingle(); + NewY = r.ReadSingle(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("newArea")) + { + NewArea = values["newArea"].Trim('"'); + } + if (values.HasValueFor("newX")) + { + NewX = float.Parse(values["newX"]); + } + if (values.HasValueFor("newY")) + { + NewY = float.Parse(values["newY"]); + } + } + } +} diff --git a/Ozzyria.Model/Components/Armor.cs b/Ozzyria.Model/Components/Armor.cs new file mode 100644 index 0000000..9a166e4 --- /dev/null +++ b/Ozzyria.Model/Components/Armor.cs @@ -0,0 +1,42 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class Armor : Grecs.Component, ISerializable, IHydrateable + { + private string _armorId; + public string ArmorId + { + get => _armorId; set + { + if (!_armorId.Equals(value)) + { + _armorId = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write(ArmorId); + } + + public void Read(System.IO.BinaryReader r) + { + ArmorId = r.ReadString(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("armorId")) + { + ArmorId = values["armorId"].Trim('"'); + } + } + } +} diff --git a/Ozzyria.Model/Components/AttackIntent.cs b/Ozzyria.Model/Components/AttackIntent.cs new file mode 100644 index 0000000..c344029 --- /dev/null +++ b/Ozzyria.Model/Components/AttackIntent.cs @@ -0,0 +1,126 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class AttackIntent : Grecs.PooledComponent, ISerializable, IHydrateable + { + private int _frame = 0; + public int Frame + { + get => _frame; set + { + if (!_frame.Equals(value)) + { + _frame = value; + + TriggerChange(); + } + } + } + + + private int _decayFrame = 3; + public int DecayFrame + { + get => _decayFrame; set + { + if (!_decayFrame.Equals(value)) + { + _decayFrame = value; + + TriggerChange(); + } + } + } + + + private int _damageFrame = 1; + public int DamageFrame + { + get => _damageFrame; set + { + if (!_damageFrame.Equals(value)) + { + _damageFrame = value; + + TriggerChange(); + } + } + } + + + private float _frameTimer = 0f; + public float FrameTimer + { + get => _frameTimer; set + { + if (!_frameTimer.Equals(value)) + { + _frameTimer = value; + + TriggerChange(); + } + } + } + + + private float _timePerFrame = 0.100f; + public float TimePerFrame + { + get => _timePerFrame; set + { + if (!_timePerFrame.Equals(value)) + { + _timePerFrame = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write(Frame); + w.Write(DecayFrame); + w.Write(DamageFrame); + w.Write(FrameTimer); + w.Write(TimePerFrame); + } + + public void Read(System.IO.BinaryReader r) + { + Frame = r.ReadInt32(); + DecayFrame = r.ReadInt32(); + DamageFrame = r.ReadInt32(); + FrameTimer = r.ReadSingle(); + TimePerFrame = r.ReadSingle(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("frame")) + { + Frame = int.Parse(values["frame"]); + } + if (values.HasValueFor("decayFrame")) + { + DecayFrame = int.Parse(values["decayFrame"]); + } + if (values.HasValueFor("damageFrame")) + { + DamageFrame = int.Parse(values["damageFrame"]); + } + if (values.HasValueFor("frameTimer")) + { + FrameTimer = float.Parse(values["frameTimer"]); + } + if (values.HasValueFor("timePerFrame")) + { + TimePerFrame = float.Parse(values["timePerFrame"]); + } + } + } +} diff --git a/Ozzyria.Model/Components/Bag.cs b/Ozzyria.Model/Components/Bag.cs new file mode 100644 index 0000000..b0e45c8 --- /dev/null +++ b/Ozzyria.Model/Components/Bag.cs @@ -0,0 +1,63 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class Bag : Grecs.Component, ISerializable, IHydrateable + { + private string _name = "Inventory"; + public string Name + { + get => _name; set + { + if (!_name.Equals(value)) + { + _name = value; + + TriggerChange(); + } + } + } + + + private int _capacity = 25; + public int Capacity + { + get => _capacity; set + { + if (!_capacity.Equals(value)) + { + _capacity = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write(Name); + w.Write(Capacity); + } + + public void Read(System.IO.BinaryReader r) + { + Name = r.ReadString(); + Capacity = r.ReadInt32(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("name")) + { + Name = values["name"].Trim('"'); + } + if (values.HasValueFor("capacity")) + { + Capacity = int.Parse(values["capacity"]); + } + } + } +} diff --git a/Ozzyria.Model/Components/Body.cs b/Ozzyria.Model/Components/Body.cs new file mode 100644 index 0000000..b098499 --- /dev/null +++ b/Ozzyria.Model/Components/Body.cs @@ -0,0 +1,42 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class Body : Grecs.Component, ISerializable, IHydrateable + { + private string _bodyId; + public string BodyId + { + get => _bodyId; set + { + if (!_bodyId.Equals(value)) + { + _bodyId = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write(BodyId); + } + + public void Read(System.IO.BinaryReader r) + { + BodyId = r.ReadString(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("bodyId")) + { + BodyId = values["bodyId"].Trim('"'); + } + } + } +} diff --git a/Ozzyria.Model/Components/Dead.cs b/Ozzyria.Model/Components/Dead.cs new file mode 100644 index 0000000..4093fcd --- /dev/null +++ b/Ozzyria.Model/Components/Dead.cs @@ -0,0 +1,27 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class Dead : Grecs.PooledComponent, ISerializable, IHydrateable + { + + public void Write(System.IO.BinaryWriter w) + { + + } + + public void Read(System.IO.BinaryReader r) + { + + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + + } + } +} diff --git a/Ozzyria.Model/Components/Door.cs b/Ozzyria.Model/Components/Door.cs new file mode 100644 index 0000000..a218ab6 --- /dev/null +++ b/Ozzyria.Model/Components/Door.cs @@ -0,0 +1,84 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class Door : Grecs.Component, ISerializable, IHydrateable + { + private string _newArea; + public string NewArea + { + get => _newArea; set + { + if (!_newArea.Equals(value)) + { + _newArea = value; + + TriggerChange(); + } + } + } + + + private float _newX; + public float NewX + { + get => _newX; set + { + if (!_newX.Equals(value)) + { + _newX = value; + + TriggerChange(); + } + } + } + + + private float _newY; + public float NewY + { + get => _newY; set + { + if (!_newY.Equals(value)) + { + _newY = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write(NewArea); + w.Write(NewX); + w.Write(NewY); + } + + public void Read(System.IO.BinaryReader r) + { + NewArea = r.ReadString(); + NewX = r.ReadSingle(); + NewY = r.ReadSingle(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("newArea")) + { + NewArea = values["newArea"].Trim('"'); + } + if (values.HasValueFor("newX")) + { + NewX = float.Parse(values["newX"]); + } + if (values.HasValueFor("newY")) + { + NewY = float.Parse(values["newY"]); + } + } + } +} diff --git a/Ozzyria.Model/Components/ExperienceBoost.cs b/Ozzyria.Model/Components/ExperienceBoost.cs new file mode 100644 index 0000000..7996b66 --- /dev/null +++ b/Ozzyria.Model/Components/ExperienceBoost.cs @@ -0,0 +1,63 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class ExperienceBoost : Grecs.Component, ISerializable, IHydrateable + { + private int _experience = 10; + public int Experience + { + get => _experience; set + { + if (!_experience.Equals(value)) + { + _experience = value; + + TriggerChange(); + } + } + } + + + private bool _hasBeenAbsorbed = false; + public bool HasBeenAbsorbed + { + get => _hasBeenAbsorbed; set + { + if (!_hasBeenAbsorbed.Equals(value)) + { + _hasBeenAbsorbed = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write(Experience); + w.Write(HasBeenAbsorbed); + } + + public void Read(System.IO.BinaryReader r) + { + Experience = r.ReadInt32(); + HasBeenAbsorbed = r.ReadBoolean(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("experience")) + { + Experience = int.Parse(values["experience"]); + } + if (values.HasValueFor("hasBeenAbsorbed")) + { + HasBeenAbsorbed = bool.Parse(values["hasBeenAbsorbed"]); + } + } + } +} diff --git a/Ozzyria.Model/Components/ExperienceOrbThought.cs b/Ozzyria.Model/Components/ExperienceOrbThought.cs new file mode 100644 index 0000000..0c6beec --- /dev/null +++ b/Ozzyria.Model/Components/ExperienceOrbThought.cs @@ -0,0 +1,27 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class ExperienceOrbThought : Grecs.Component, ISerializable, IHydrateable + { + + public void Write(System.IO.BinaryWriter w) + { + + } + + public void Read(System.IO.BinaryReader r) + { + + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + + } + } +} diff --git a/Ozzyria.Model/Components/Hat.cs b/Ozzyria.Model/Components/Hat.cs new file mode 100644 index 0000000..040c25f --- /dev/null +++ b/Ozzyria.Model/Components/Hat.cs @@ -0,0 +1,42 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class Hat : Grecs.Component, ISerializable, IHydrateable + { + private string _hatId; + public string HatId + { + get => _hatId; set + { + if (!_hatId.Equals(value)) + { + _hatId = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write(HatId); + } + + public void Read(System.IO.BinaryReader r) + { + HatId = r.ReadString(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("hatId")) + { + HatId = values["hatId"].Trim('"'); + } + } + } +} diff --git a/Ozzyria.Model/Components/Item.cs b/Ozzyria.Model/Components/Item.cs new file mode 100644 index 0000000..3ea08d0 --- /dev/null +++ b/Ozzyria.Model/Components/Item.cs @@ -0,0 +1,147 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class Item : Grecs.Component, ISerializable, IHydrateable + { + private string _name = ""; + public string Name + { + get => _name; set + { + if (!_name.Equals(value)) + { + _name = value; + + TriggerChange(); + } + } + } + + + private string _icon = ""; + public string Icon + { + get => _icon; set + { + if (!_icon.Equals(value)) + { + _icon = value; + + TriggerChange(); + } + } + } + + + private int _slot = 0; + public int Slot + { + get => _slot; set + { + if (!_slot.Equals(value)) + { + _slot = value; + + TriggerChange(); + } + } + } + + + private string _itemId = ""; + public string ItemId + { + get => _itemId; set + { + if (!_itemId.Equals(value)) + { + _itemId = value; + + TriggerChange(); + } + } + } + + + private string _equipmentSlot = ""; + public string EquipmentSlot + { + get => _equipmentSlot; set + { + if (!_equipmentSlot.Equals(value)) + { + _equipmentSlot = value; + + TriggerChange(); + } + } + } + + + private bool _isEquipped = false; + public bool IsEquipped + { + get => _isEquipped; set + { + if (!_isEquipped.Equals(value)) + { + _isEquipped = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write(Name); + w.Write(Icon); + w.Write(Slot); + w.Write(ItemId); + w.Write(EquipmentSlot); + w.Write(IsEquipped); + } + + public void Read(System.IO.BinaryReader r) + { + Name = r.ReadString(); + Icon = r.ReadString(); + Slot = r.ReadInt32(); + ItemId = r.ReadString(); + EquipmentSlot = r.ReadString(); + IsEquipped = r.ReadBoolean(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("name")) + { + Name = values["name"].Trim('"'); + } + if (values.HasValueFor("icon")) + { + Icon = values["icon"].Trim('"'); + } + if (values.HasValueFor("slot")) + { + Slot = int.Parse(values["slot"]); + } + if (values.HasValueFor("itemId")) + { + ItemId = values["itemId"].Trim('"'); + } + if (values.HasValueFor("equipmentSlot")) + { + EquipmentSlot = values["equipmentSlot"].Trim('"'); + } + if (values.HasValueFor("isEquipped")) + { + IsEquipped = bool.Parse(values["isEquipped"]); + } + } + } +} diff --git a/Ozzyria.Model/Components/Location.cs b/Ozzyria.Model/Components/Location.cs new file mode 100644 index 0000000..dc89463 --- /dev/null +++ b/Ozzyria.Model/Components/Location.cs @@ -0,0 +1,42 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class Location : Grecs.Component, ISerializable, IHydrateable + { + private string _area = ""; + public string Area + { + get => _area; set + { + if (!_area.Equals(value)) + { + _area = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write(Area); + } + + public void Read(System.IO.BinaryReader r) + { + Area = r.ReadString(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("area")) + { + Area = values["area"].Trim('"'); + } + } + } +} diff --git a/Ozzyria.Model/Components/Mask.cs b/Ozzyria.Model/Components/Mask.cs new file mode 100644 index 0000000..b190e4b --- /dev/null +++ b/Ozzyria.Model/Components/Mask.cs @@ -0,0 +1,42 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class Mask : Grecs.Component, ISerializable, IHydrateable + { + private string _maskId; + public string MaskId + { + get => _maskId; set + { + if (!_maskId.Equals(value)) + { + _maskId = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write(MaskId); + } + + public void Read(System.IO.BinaryReader r) + { + MaskId = r.ReadString(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("maskId")) + { + MaskId = values["maskId"].Trim('"'); + } + } + } +} diff --git a/Ozzyria.Model/Components/Movement.cs b/Ozzyria.Model/Components/Movement.cs new file mode 100644 index 0000000..b1f7ae4 --- /dev/null +++ b/Ozzyria.Model/Components/Movement.cs @@ -0,0 +1,273 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class Movement : Grecs.Component, ISerializable, IHydrateable + { + private float _previousX = 0f; + public float PreviousX + { + get => _previousX; set + { + if (!_previousX.Equals(value)) + { + _previousX = value; + + TriggerChange(); + } + } + } + + + private float _previousY = 0f; + public float PreviousY + { + get => _previousY; set + { + if (!_previousY.Equals(value)) + { + _previousY = value; + + TriggerChange(); + } + } + } + + + private int _layer = 1; + public int Layer + { + get => _layer; set + { + if (!_layer.Equals(value)) + { + _layer = value; + + TriggerChange(); + } + } + } + + + private float _x = 0f; + public float X + { + get => _x; set + { + if (!_x.Equals(value)) + { + _x = value; + + TriggerChange(); + } + } + } + + + private float _y = 0f; + public float Y + { + get => _y; set + { + if (!_y.Equals(value)) + { + _y = value; + + TriggerChange(); + } + } + } + + + private float _collisionOffsetY = 0f; + public float CollisionOffsetY + { + get => _collisionOffsetY; set + { + if (!_collisionOffsetY.Equals(value)) + { + _collisionOffsetY = value; + + TriggerChange(); + } + } + } + + + private float _speed = 0f; + public float Speed + { + get => _speed; set + { + if (!_speed.Equals(value)) + { + _speed = value; + + TriggerChange(); + } + } + } + + + private float _moveDirection = 0f; + public float MoveDirection + { + get => _moveDirection; set + { + if (!_moveDirection.Equals(value)) + { + _moveDirection = value; + + TriggerChange(); + } + } + } + + + private float _lookDirection = 0f; + public float LookDirection + { + get => _lookDirection; set + { + if (!_lookDirection.Equals(value)) + { + _lookDirection = value; + + TriggerChange(); + } + } + } + + + private float _acceleration; + public float ACCELERATION + { + get => _acceleration; set + { + if (!_acceleration.Equals(value)) + { + _acceleration = value; + + TriggerChange(); + } + } + } + + + private float _maxSpeed; + public float MAX_SPEED + { + get => _maxSpeed; set + { + if (!_maxSpeed.Equals(value)) + { + _maxSpeed = value; + + TriggerChange(); + } + } + } + + + private float _turnSpeed; + public float TURN_SPEED + { + get => _turnSpeed; set + { + if (!_turnSpeed.Equals(value)) + { + _turnSpeed = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write(PreviousX); + w.Write(PreviousY); + w.Write(Layer); + w.Write(X); + w.Write(Y); + w.Write(CollisionOffsetY); + w.Write(Speed); + w.Write(MoveDirection); + w.Write(LookDirection); + w.Write(ACCELERATION); + w.Write(MAX_SPEED); + w.Write(TURN_SPEED); + } + + public void Read(System.IO.BinaryReader r) + { + PreviousX = r.ReadSingle(); + PreviousY = r.ReadSingle(); + Layer = r.ReadInt32(); + X = r.ReadSingle(); + Y = r.ReadSingle(); + CollisionOffsetY = r.ReadSingle(); + Speed = r.ReadSingle(); + MoveDirection = r.ReadSingle(); + LookDirection = r.ReadSingle(); + ACCELERATION = r.ReadSingle(); + MAX_SPEED = r.ReadSingle(); + TURN_SPEED = r.ReadSingle(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("previousX")) + { + PreviousX = float.Parse(values["previousX"]); + } + if (values.HasValueFor("previousY")) + { + PreviousY = float.Parse(values["previousY"]); + } + if (values.HasValueFor("layer")) + { + Layer = int.Parse(values["layer"]); + } + if (values.HasValueFor("x")) + { + X = float.Parse(values["x"]); + } + if (values.HasValueFor("y")) + { + Y = float.Parse(values["y"]); + } + if (values.HasValueFor("collisionOffsetY")) + { + CollisionOffsetY = float.Parse(values["collisionOffsetY"]); + } + if (values.HasValueFor("speed")) + { + Speed = float.Parse(values["speed"]); + } + if (values.HasValueFor("moveDirection")) + { + MoveDirection = float.Parse(values["moveDirection"]); + } + if (values.HasValueFor("lookDirection")) + { + LookDirection = float.Parse(values["lookDirection"]); + } + if (values.HasValueFor("acceleration")) + { + ACCELERATION = float.Parse(values["acceleration"]); + } + if (values.HasValueFor("maxSpeed")) + { + MAX_SPEED = float.Parse(values["maxSpeed"]); + } + if (values.HasValueFor("turnSpeed")) + { + TURN_SPEED = float.Parse(values["turnSpeed"]); + } + } + } +} diff --git a/Ozzyria.Model/Components/MovementIntent.cs b/Ozzyria.Model/Components/MovementIntent.cs new file mode 100644 index 0000000..1db7101 --- /dev/null +++ b/Ozzyria.Model/Components/MovementIntent.cs @@ -0,0 +1,105 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class MovementIntent : Grecs.PooledComponent, ISerializable, IHydrateable + { + private bool _moveRight = false; + public bool MoveRight + { + get => _moveRight; set + { + if (!_moveRight.Equals(value)) + { + _moveRight = value; + + TriggerChange(); + } + } + } + + + private bool _moveLeft = false; + public bool MoveLeft + { + get => _moveLeft; set + { + if (!_moveLeft.Equals(value)) + { + _moveLeft = value; + + TriggerChange(); + } + } + } + + + private bool _moveDown = false; + public bool MoveDown + { + get => _moveDown; set + { + if (!_moveDown.Equals(value)) + { + _moveDown = value; + + TriggerChange(); + } + } + } + + + private bool _moveUp = false; + public bool MoveUp + { + get => _moveUp; set + { + if (!_moveUp.Equals(value)) + { + _moveUp = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write(MoveRight); + w.Write(MoveLeft); + w.Write(MoveDown); + w.Write(MoveUp); + } + + public void Read(System.IO.BinaryReader r) + { + MoveRight = r.ReadBoolean(); + MoveLeft = r.ReadBoolean(); + MoveDown = r.ReadBoolean(); + MoveUp = r.ReadBoolean(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("moveRight")) + { + MoveRight = bool.Parse(values["moveRight"]); + } + if (values.HasValueFor("moveLeft")) + { + MoveLeft = bool.Parse(values["moveLeft"]); + } + if (values.HasValueFor("moveDown")) + { + MoveDown = bool.Parse(values["moveDown"]); + } + if (values.HasValueFor("moveUp")) + { + MoveUp = bool.Parse(values["moveUp"]); + } + } + } +} diff --git a/Ozzyria.Model/Components/Player.cs b/Ozzyria.Model/Components/Player.cs new file mode 100644 index 0000000..0a80ebc --- /dev/null +++ b/Ozzyria.Model/Components/Player.cs @@ -0,0 +1,42 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class Player : Grecs.Component, ISerializable, IHydrateable + { + private int _playerId = -1; + public int PlayerId + { + get => _playerId; set + { + if (!_playerId.Equals(value)) + { + _playerId = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write(PlayerId); + } + + public void Read(System.IO.BinaryReader r) + { + PlayerId = r.ReadInt32(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("playerId")) + { + PlayerId = int.Parse(values["playerId"]); + } + } + } +} diff --git a/Ozzyria.Model/Components/PlayerThought.cs b/Ozzyria.Model/Components/PlayerThought.cs new file mode 100644 index 0000000..cd4a96d --- /dev/null +++ b/Ozzyria.Model/Components/PlayerThought.cs @@ -0,0 +1,27 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class PlayerThought : Grecs.Component, ISerializable, IHydrateable + { + + public void Write(System.IO.BinaryWriter w) + { + + } + + public void Read(System.IO.BinaryReader r) + { + + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + + } + } +} diff --git a/Ozzyria.Model/Components/Skeleton.cs b/Ozzyria.Model/Components/Skeleton.cs new file mode 100644 index 0000000..d80d7a0 --- /dev/null +++ b/Ozzyria.Model/Components/Skeleton.cs @@ -0,0 +1,424 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class Skeleton : Grecs.Component, ISerializable, IHydrateable + { + private SkeletonType _type; + public SkeletonType Type + { + get => _type; set + { + if (!_type.Equals(value)) + { + _type = value; + + TriggerChange(); + } + } + } + + + private SkeletonPose _pose; + public SkeletonPose Pose + { + get => _pose; set + { + if (!_pose.Equals(value)) + { + _pose = value; + + TriggerChange(); + } + } + } + + + private int _frame; + public int Frame + { + get => _frame; set + { + if (!_frame.Equals(value)) + { + _frame = value; + + TriggerChange(); + } + } + } + + + private int _layer; + public int Layer + { + get => _layer; set + { + if (!_layer.Equals(value)) + { + _layer = value; + + TriggerChange(); + } + } + } + + + private int _subLayer; + public int SubLayer + { + get => _subLayer; set + { + if (!_subLayer.Equals(value)) + { + _subLayer = value; + + TriggerChange(); + } + } + } + + + private Direction _direction; + public Direction Direction + { + get => _direction; set + { + if (!_direction.Equals(value)) + { + _direction = value; + + TriggerChange(); + } + } + } + + + private int _rootX; + public int RootX + { + get => _rootX; set + { + if (!_rootX.Equals(value)) + { + _rootX = value; + + TriggerChange(); + } + } + } + + + private int _rootY; + public int RootY + { + get => _rootY; set + { + if (!_rootY.Equals(value)) + { + _rootY = value; + + TriggerChange(); + } + } + } + + + private int _renderOffsetY; + public int RenderOffsetY + { + get => _renderOffsetY; set + { + if (!_renderOffsetY.Equals(value)) + { + _renderOffsetY = value; + + TriggerChange(); + } + } + } + + + private int _weaponOffsetX; + public int WeaponOffsetX + { + get => _weaponOffsetX; set + { + if (!_weaponOffsetX.Equals(value)) + { + _weaponOffsetX = value; + + TriggerChange(); + } + } + } + + + private int _weaponOffsetY; + public int WeaponOffsetY + { + get => _weaponOffsetY; set + { + if (!_weaponOffsetY.Equals(value)) + { + _weaponOffsetY = value; + + TriggerChange(); + } + } + } + + + private float _weaponOffsetAngle; + public float WeaponOffsetAngle + { + get => _weaponOffsetAngle; set + { + if (!_weaponOffsetAngle.Equals(value)) + { + _weaponOffsetAngle = value; + + TriggerChange(); + } + } + } + + + private int _armorOffsetX; + public int ArmorOffsetX + { + get => _armorOffsetX; set + { + if (!_armorOffsetX.Equals(value)) + { + _armorOffsetX = value; + + TriggerChange(); + } + } + } + + + private int _armorOffsetY; + public int ArmorOffsetY + { + get => _armorOffsetY; set + { + if (!_armorOffsetY.Equals(value)) + { + _armorOffsetY = value; + + TriggerChange(); + } + } + } + + + private float _armorOffsetAngle; + public float ArmorOffsetAngle + { + get => _armorOffsetAngle; set + { + if (!_armorOffsetAngle.Equals(value)) + { + _armorOffsetAngle = value; + + TriggerChange(); + } + } + } + + + private int _maskOffsetX; + public int MaskOffsetX + { + get => _maskOffsetX; set + { + if (!_maskOffsetX.Equals(value)) + { + _maskOffsetX = value; + + TriggerChange(); + } + } + } + + + private int _maskOffsetY; + public int MaskOffsetY + { + get => _maskOffsetY; set + { + if (!_maskOffsetY.Equals(value)) + { + _maskOffsetY = value; + + TriggerChange(); + } + } + } + + + private float _maskOffsetAngle; + public float MaskOffsetAngle + { + get => _maskOffsetAngle; set + { + if (!_maskOffsetAngle.Equals(value)) + { + _maskOffsetAngle = value; + + TriggerChange(); + } + } + } + + + private int _hatOffsetX; + public int HatOffsetX + { + get => _hatOffsetX; set + { + if (!_hatOffsetX.Equals(value)) + { + _hatOffsetX = value; + + TriggerChange(); + } + } + } + + + private int _hatOffsetY; + public int HatOffsetY + { + get => _hatOffsetY; set + { + if (!_hatOffsetY.Equals(value)) + { + _hatOffsetY = value; + + TriggerChange(); + } + } + } + + + private float _hatOffsetAngle; + public float HatOffsetAngle + { + get => _hatOffsetAngle; set + { + if (!_hatOffsetAngle.Equals(value)) + { + _hatOffsetAngle = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write((int)Type); + w.Write((int)Pose); + } + + public void Read(System.IO.BinaryReader r) + { + Type = (SkeletonType)r.ReadInt32(); + Pose = (SkeletonPose)r.ReadInt32(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("type")) + { + Type = (SkeletonType)Enum.Parse(typeof(SkeletonType), values["type"], true); + } + if (values.HasValueFor("pose")) + { + Pose = (SkeletonPose)Enum.Parse(typeof(SkeletonPose), values["pose"], true); + } + if (values.HasValueFor("frame")) + { + Frame = int.Parse(values["frame"]); + } + if (values.HasValueFor("layer")) + { + Layer = int.Parse(values["layer"]); + } + if (values.HasValueFor("subLayer")) + { + SubLayer = int.Parse(values["subLayer"]); + } + if (values.HasValueFor("direction")) + { + Direction = (Direction)Enum.Parse(typeof(Direction), values["direction"], true); + } + if (values.HasValueFor("rootX")) + { + RootX = int.Parse(values["rootX"]); + } + if (values.HasValueFor("rootY")) + { + RootY = int.Parse(values["rootY"]); + } + if (values.HasValueFor("renderOffsetY")) + { + RenderOffsetY = int.Parse(values["renderOffsetY"]); + } + if (values.HasValueFor("weaponOffsetX")) + { + WeaponOffsetX = int.Parse(values["weaponOffsetX"]); + } + if (values.HasValueFor("weaponOffsetY")) + { + WeaponOffsetY = int.Parse(values["weaponOffsetY"]); + } + if (values.HasValueFor("weaponOffsetAngle")) + { + WeaponOffsetAngle = float.Parse(values["weaponOffsetAngle"]); + } + if (values.HasValueFor("armorOffsetX")) + { + ArmorOffsetX = int.Parse(values["armorOffsetX"]); + } + if (values.HasValueFor("armorOffsetY")) + { + ArmorOffsetY = int.Parse(values["armorOffsetY"]); + } + if (values.HasValueFor("armorOffsetAngle")) + { + ArmorOffsetAngle = float.Parse(values["armorOffsetAngle"]); + } + if (values.HasValueFor("maskOffsetX")) + { + MaskOffsetX = int.Parse(values["maskOffsetX"]); + } + if (values.HasValueFor("maskOffsetY")) + { + MaskOffsetY = int.Parse(values["maskOffsetY"]); + } + if (values.HasValueFor("maskOffsetAngle")) + { + MaskOffsetAngle = float.Parse(values["maskOffsetAngle"]); + } + if (values.HasValueFor("hatOffsetX")) + { + HatOffsetX = int.Parse(values["hatOffsetX"]); + } + if (values.HasValueFor("hatOffsetY")) + { + HatOffsetY = int.Parse(values["hatOffsetY"]); + } + if (values.HasValueFor("hatOffsetAngle")) + { + HatOffsetAngle = float.Parse(values["hatOffsetAngle"]); + } + } + } +} diff --git a/Ozzyria.Model/Components/SlimeSpawner.cs b/Ozzyria.Model/Components/SlimeSpawner.cs new file mode 100644 index 0000000..d49ae78 --- /dev/null +++ b/Ozzyria.Model/Components/SlimeSpawner.cs @@ -0,0 +1,119 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class SlimeSpawner : Grecs.Component, ISerializable, IHydrateable + { + private float _x = 500f; + public float X + { + get => _x; set + { + if (!_x.Equals(value)) + { + _x = value; + + TriggerChange(); + } + } + } + + + private float _y = 400f; + public float Y + { + get => _y; set + { + if (!_y.Equals(value)) + { + _y = value; + + TriggerChange(); + } + } + } + + + private int _SLIME_LIMIT = 3; + public int SLIME_LIMIT + { + get => _SLIME_LIMIT; set + { + if (!_SLIME_LIMIT.Equals(value)) + { + _SLIME_LIMIT = value; + + TriggerChange(); + } + } + } + + + private Delay _thinkDelay = new Delay{ DelayInSeconds = 5f, }; + public Delay ThinkDelay + { + get => _thinkDelay; set + { + if (!_thinkDelay.Equals(value)) + { + _thinkDelay = value; + if (value != null) { _thinkDelay.TriggerChange = TriggerChange; } + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write(X); + w.Write(Y); + w.Write(SLIME_LIMIT); + w.Write(ThinkDelay.DelayInSeconds); + w.Write(ThinkDelay.Timer); + } + + public void Read(System.IO.BinaryReader r) + { + X = r.ReadSingle(); + Y = r.ReadSingle(); + SLIME_LIMIT = r.ReadInt32(); + ThinkDelay.DelayInSeconds = r.ReadSingle(); + ThinkDelay.Timer = r.ReadSingle(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("x")) + { + X = float.Parse(values["x"]); + } + if (values.HasValueFor("y")) + { + Y = float.Parse(values["y"]); + } + if (values.HasValueFor("SLIME_LIMIT")) + { + SLIME_LIMIT = int.Parse(values["SLIME_LIMIT"]); + } + if (values.HasValueFor("thinkDelay")) + { + var values_thinkDelay = values.Extract("thinkDelay"); + if (values_thinkDelay.HasValueFor("delayInSeconds")) + { + ThinkDelay.DelayInSeconds = float.Parse(values_thinkDelay["delayInSeconds"]); + } + if (values_thinkDelay.HasValueFor("timer")) + { + ThinkDelay.Timer = float.Parse(values_thinkDelay["timer"]); + } + if (values_thinkDelay.HasValueFor("ready")) + { + ThinkDelay.Ready = bool.Parse(values_thinkDelay["ready"]); + } + } + } + } +} diff --git a/Ozzyria.Model/Components/SlimeThought.cs b/Ozzyria.Model/Components/SlimeThought.cs new file mode 100644 index 0000000..38e4c46 --- /dev/null +++ b/Ozzyria.Model/Components/SlimeThought.cs @@ -0,0 +1,73 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class SlimeThought : Grecs.Component, ISerializable, IHydrateable + { + private Delay _thinkDelay; + public Delay ThinkDelay + { + get => _thinkDelay; set + { + if (!_thinkDelay.Equals(value)) + { + _thinkDelay = value; + if (value != null) { _thinkDelay.TriggerChange = TriggerChange; } + TriggerChange(); + } + } + } + + + private int _thinkAction = 0; + public int ThinkAction + { + get => _thinkAction; set + { + if (!_thinkAction.Equals(value)) + { + _thinkAction = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + + } + + public void Read(System.IO.BinaryReader r) + { + + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("thinkDelay")) + { + var values_thinkDelay = values.Extract("thinkDelay"); + if (values_thinkDelay.HasValueFor("delayInSeconds")) + { + ThinkDelay.DelayInSeconds = float.Parse(values_thinkDelay["delayInSeconds"]); + } + if (values_thinkDelay.HasValueFor("timer")) + { + ThinkDelay.Timer = float.Parse(values_thinkDelay["timer"]); + } + if (values_thinkDelay.HasValueFor("ready")) + { + ThinkDelay.Ready = bool.Parse(values_thinkDelay["ready"]); + } + } + if (values.HasValueFor("thinkAction")) + { + ThinkAction = int.Parse(values["thinkAction"]); + } + } + } +} diff --git a/Ozzyria.Model/Components/Stats.cs b/Ozzyria.Model/Components/Stats.cs new file mode 100644 index 0000000..7b8aa7c --- /dev/null +++ b/Ozzyria.Model/Components/Stats.cs @@ -0,0 +1,105 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class Stats : Grecs.Component, ISerializable, IHydrateable + { + private int _experience = 0; + public int Experience + { + get => _experience; set + { + if (!_experience.Equals(value)) + { + _experience = value; + + TriggerChange(); + } + } + } + + + private int _maxExperience = 100; + public int MaxExperience + { + get => _maxExperience; set + { + if (!_maxExperience.Equals(value)) + { + _maxExperience = value; + + TriggerChange(); + } + } + } + + + private int _health = 100; + public int Health + { + get => _health; set + { + if (!_health.Equals(value)) + { + _health = value; + + TriggerChange(); + } + } + } + + + private int _maxHealth = 100; + public int MaxHealth + { + get => _maxHealth; set + { + if (!_maxHealth.Equals(value)) + { + _maxHealth = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write(Experience); + w.Write(MaxExperience); + w.Write(Health); + w.Write(MaxHealth); + } + + public void Read(System.IO.BinaryReader r) + { + Experience = r.ReadInt32(); + MaxExperience = r.ReadInt32(); + Health = r.ReadInt32(); + MaxHealth = r.ReadInt32(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("experience")) + { + Experience = int.Parse(values["experience"]); + } + if (values.HasValueFor("maxExperience")) + { + MaxExperience = int.Parse(values["maxExperience"]); + } + if (values.HasValueFor("health")) + { + Health = int.Parse(values["health"]); + } + if (values.HasValueFor("maxHealth")) + { + MaxHealth = int.Parse(values["maxHealth"]); + } + } + } +} diff --git a/Ozzyria.Model/Components/Weapon.cs b/Ozzyria.Model/Components/Weapon.cs new file mode 100644 index 0000000..a70a3a7 --- /dev/null +++ b/Ozzyria.Model/Components/Weapon.cs @@ -0,0 +1,126 @@ +using Ozzyria.Model.Types; + +namespace Ozzyria.Model.Components +{ + public class Weapon : Grecs.Component, ISerializable, IHydrateable + { + private WeaponType _weaponType; + public WeaponType WeaponType + { + get => _weaponType; set + { + if (!_weaponType.Equals(value)) + { + _weaponType = value; + + TriggerChange(); + } + } + } + + + private string _weaponId; + public string WeaponId + { + get => _weaponId; set + { + if (!_weaponId.Equals(value)) + { + _weaponId = value; + + TriggerChange(); + } + } + } + + + private float _attackAngle = 0.78f; + public float AttackAngle + { + get => _attackAngle; set + { + if (!_attackAngle.Equals(value)) + { + _attackAngle = value; + + TriggerChange(); + } + } + } + + + private float _attackRange = 21f; + public float AttackRange + { + get => _attackRange; set + { + if (!_attackRange.Equals(value)) + { + _attackRange = value; + + TriggerChange(); + } + } + } + + + private int _attackDamage = 5; + public int AttackDamage + { + get => _attackDamage; set + { + if (!_attackDamage.Equals(value)) + { + _attackDamage = value; + + TriggerChange(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write((int)WeaponType); + w.Write(WeaponId); + w.Write(AttackAngle); + w.Write(AttackRange); + w.Write(AttackDamage); + } + + public void Read(System.IO.BinaryReader r) + { + WeaponType = (WeaponType)r.ReadInt32(); + WeaponId = r.ReadString(); + AttackAngle = r.ReadSingle(); + AttackRange = r.ReadSingle(); + AttackDamage = r.ReadInt32(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("weaponType")) + { + WeaponType = (WeaponType)Enum.Parse(typeof(WeaponType), values["weaponType"], true); + } + if (values.HasValueFor("weaponId")) + { + WeaponId = values["weaponId"].Trim('"'); + } + if (values.HasValueFor("attackAngle")) + { + AttackAngle = float.Parse(values["attackAngle"]); + } + if (values.HasValueFor("attackRange")) + { + AttackRange = float.Parse(values["attackRange"]); + } + if (values.HasValueFor("attackDamage")) + { + AttackDamage = int.Parse(values["attackDamage"]); + } + } + } +} diff --git a/Ozzyria.Model/Ozzyria.Model.csproj b/Ozzyria.Model/Ozzyria.Model.csproj new file mode 100644 index 0000000..63691c1 --- /dev/null +++ b/Ozzyria.Model/Ozzyria.Model.csproj @@ -0,0 +1,35 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + + + + + + + + + diff --git a/Ozzyria.Model/Types/ClipType.cs b/Ozzyria.Model/Types/ClipType.cs new file mode 100644 index 0000000..2cb15b8 --- /dev/null +++ b/Ozzyria.Model/Types/ClipType.cs @@ -0,0 +1,9 @@ +namespace Ozzyria.Model.Types +{ + public enum ClipType + { + Decay, + Loop, + Stall + } +} diff --git a/Ozzyria.Model/Types/Delay.cs b/Ozzyria.Model/Types/Delay.cs new file mode 100644 index 0000000..db63a82 --- /dev/null +++ b/Ozzyria.Model/Types/Delay.cs @@ -0,0 +1,89 @@ +namespace Ozzyria.Model.Types +{ + public class Delay : ISerializable, IHydrateable + { + private System.Action? _triggerChange; + public System.Action? TriggerChange { get => _triggerChange; set + { + _triggerChange = value; + + } + } + + + private float _delayInSeconds = 0.5f; + public float DelayInSeconds + { + get => _delayInSeconds; set + { + if (!_delayInSeconds.Equals(value)) + { + _delayInSeconds = value; + + TriggerChange?.Invoke(); + } + } + } + + + private float _timer = 0.5f; + public float Timer + { + get => _timer; set + { + if (!_timer.Equals(value)) + { + _timer = value; + + TriggerChange?.Invoke(); + } + } + } + + + private bool _ready = false; + public bool Ready + { + get => _ready; set + { + if (!_ready.Equals(value)) + { + _ready = value; + + TriggerChange?.Invoke(); + } + } + } + public void Write(System.IO.BinaryWriter w) + { + w.Write(DelayInSeconds); + w.Write(Timer); + } + + public void Read(System.IO.BinaryReader r) + { + DelayInSeconds = r.ReadSingle(); + Timer = r.ReadSingle(); + } + public void Hydrate(ValuePacket values) + { + if (values == null || values.Count <= 0) + { + return; + } + + if (values.HasValueFor("delayInSeconds")) + { + DelayInSeconds = float.Parse(values["delayInSeconds"]); + } + if (values.HasValueFor("timer")) + { + Timer = float.Parse(values["timer"]); + } + if (values.HasValueFor("ready")) + { + Ready = bool.Parse(values["ready"]); + } + } + } +} diff --git a/Ozzyria.Model/Types/Direction.cs b/Ozzyria.Model/Types/Direction.cs new file mode 100644 index 0000000..7ef3c2c --- /dev/null +++ b/Ozzyria.Model/Types/Direction.cs @@ -0,0 +1,11 @@ +namespace Ozzyria.Model.Types +{ + public enum Direction + { + None, + Up, + Down, + Left, + Right + } +} diff --git a/Ozzyria.Model/Types/IHydrateable.cs b/Ozzyria.Model/Types/IHydrateable.cs new file mode 100644 index 0000000..9666a4d --- /dev/null +++ b/Ozzyria.Model/Types/IHydrateable.cs @@ -0,0 +1,7 @@ +namespace Ozzyria.Model.Types +{ + public interface IHydrateable + { + public void Hydrate(ValuePacket values); + } +} diff --git a/Ozzyria.Model/Types/ISerializable.cs b/Ozzyria.Model/Types/ISerializable.cs new file mode 100644 index 0000000..e9cb703 --- /dev/null +++ b/Ozzyria.Model/Types/ISerializable.cs @@ -0,0 +1,8 @@ +namespace Ozzyria.Model.Types +{ + public interface ISerializable + { + public void Write(System.IO.BinaryWriter w); + public void Read(System.IO.BinaryReader r); + } +} diff --git a/Ozzyria.Model/Types/SkeletonPose.cs b/Ozzyria.Model/Types/SkeletonPose.cs new file mode 100644 index 0000000..91bd090 --- /dev/null +++ b/Ozzyria.Model/Types/SkeletonPose.cs @@ -0,0 +1,9 @@ +namespace Ozzyria.Model.Types +{ + public enum SkeletonPose + { + Idle, + Walk, + Attack + } +} diff --git a/Ozzyria.Model/Types/SkeletonType.cs b/Ozzyria.Model/Types/SkeletonType.cs new file mode 100644 index 0000000..d60ad2d --- /dev/null +++ b/Ozzyria.Model/Types/SkeletonType.cs @@ -0,0 +1,9 @@ +namespace Ozzyria.Model.Types +{ + public enum SkeletonType + { + Humanoid, + Slime, + Static + } +} diff --git a/Ozzyria.Model/Types/ValuePacket.cs b/Ozzyria.Model/Types/ValuePacket.cs new file mode 100644 index 0000000..9d81eae --- /dev/null +++ b/Ozzyria.Model/Types/ValuePacket.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Ozzyria.Model.Types +{ + public class ValuePacket : Dictionary + { + public const string DIG_OPERATOR = "->"; + + public ValuePacket Extract(string locator) + { + var result = new ValuePacket(); + foreach (var kv in this) + { + if (kv.Key.StartsWith(locator + DIG_OPERATOR)) + { + // +DIG_OPERATOR.Length to skip over dig-syntax + result[kv.Key.Substring(locator.Length + DIG_OPERATOR.Length)] = kv.Value; + } + } + + return result; + } + + public bool HasValueFor(string locator) + { + return this.Any(kv => kv.Key == locator || kv.Key.StartsWith(locator + DIG_OPERATOR)); + } + + public static ValuePacket Combine(params ValuePacket[] packets) + { + var result = new ValuePacket(); + var allKeys = packets.SelectMany(p => p.Keys).Distinct(); + foreach (var key in allKeys) + { + foreach (var packet in packets) + { + if (packet.ContainsKey(key)) + result[key] = packet[key]; + } + } + + return result; + } + } +} diff --git a/Ozzyria.Model/Types/WeaponType.cs b/Ozzyria.Model/Types/WeaponType.cs new file mode 100644 index 0000000..e604fb2 --- /dev/null +++ b/Ozzyria.Model/Types/WeaponType.cs @@ -0,0 +1,8 @@ +namespace Ozzyria.Model.Types +{ + public enum WeaponType + { + Empty, + Sword + } +} diff --git a/Ozzyria.sln b/Ozzyria.sln index 6348a58..b8cbea5 100644 --- a/Ozzyria.sln +++ b/Ozzyria.sln @@ -21,6 +21,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ozzyria.MonoGameClient", "O EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ozzyria.Gryp", "Ozzyria.Gryp\Ozzyria.Gryp.csproj", "{3E15F9C8-723A-4894-B3A4-0B45282AF9B4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ozzyria.Model", "Ozzyria.Model\Ozzyria.Model.csproj", "{3FCD0CF1-AAAE-49D5-ADA2-3FB22C7C392C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ozzyria.Grynt", "Ozzyria.Grynt\Ozzyria.Grynt.csproj", "{81A2B11E-1B3A-4CDD-AFC6-A6441987927C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +55,14 @@ Global {3E15F9C8-723A-4894-B3A4-0B45282AF9B4}.Debug|Any CPU.Build.0 = Debug|Any CPU {3E15F9C8-723A-4894-B3A4-0B45282AF9B4}.Release|Any CPU.ActiveCfg = Release|Any CPU {3E15F9C8-723A-4894-B3A4-0B45282AF9B4}.Release|Any CPU.Build.0 = Release|Any CPU + {3FCD0CF1-AAAE-49D5-ADA2-3FB22C7C392C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3FCD0CF1-AAAE-49D5-ADA2-3FB22C7C392C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3FCD0CF1-AAAE-49D5-ADA2-3FB22C7C392C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3FCD0CF1-AAAE-49D5-ADA2-3FB22C7C392C}.Release|Any CPU.Build.0 = Release|Any CPU + {81A2B11E-1B3A-4CDD-AFC6-A6441987927C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {81A2B11E-1B3A-4CDD-AFC6-A6441987927C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {81A2B11E-1B3A-4CDD-AFC6-A6441987927C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {81A2B11E-1B3A-4CDD-AFC6-A6441987927C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE