feat: add view models for all entities

This commit is contained in:
k0t9i
2023-01-29 20:44:24 +04:00
parent 16630de6a4
commit 8b27c84a9e
4413 changed files with 1150 additions and 122 deletions

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace Client.Domain.Common
{
public class NotifyPropertyChanged : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string prop = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(prop));
}
}
}
}

View File

@@ -1,24 +1,32 @@
using Client.Domain.ValueObjects;
using Client.Domain.Common;
using Client.Domain.ValueObjects;
namespace Client.Domain.Entities
{
public class Drop : EntityInterface
public class Drop : NotifyPropertyChanged, EntityInterface
{
public uint Id { get; set; }
public Transform Transform { get; set; }
public uint ItemId { get; set; }
public uint Amount { get; set; }
public string Name { get; set; }
public string IconName { get; set; }
private uint id;
private Transform transform;
private uint itemId;
private uint amount;
private string name;
private string iconName;
public uint Id { get => id; set => id = value; }
public Transform Transform { get => transform; set { if (value != transform) { transform = value; OnPropertyChanged("Transform"); } } }
public uint ItemId { get => itemId; set { if (value != itemId) { itemId = value; OnPropertyChanged("ItemId"); } } }
public uint Amount { get => amount; set { if (value != amount) { amount = value; OnPropertyChanged("Amount"); } } }
public string Name { get => name; set { if (value != name) { name = value; OnPropertyChanged("Name"); } } }
public string IconName { get => iconName; set { if (value != iconName) { iconName = value; OnPropertyChanged("IconName"); } } }
public Drop(uint id, Transform transform, uint itemId, uint amount, string name, string iconName)
{
Id = id;
Transform = transform;
ItemId = itemId;
Amount = amount;
Name = name;
IconName = iconName;
this.id = id;
this.transform = transform;
this.itemId = itemId;
this.amount = amount;
this.name = name;
this.iconName = iconName;
}
}
}

View File

@@ -3,6 +3,7 @@ using Client.Domain.ValueObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;
@@ -28,5 +29,10 @@ namespace Client.Domain.Entities
FullName = fullName;
VitalStats = vitalStats;
}
public bool IsDead()
{
return VitalStats.MaxHp > 0 && VitalStats.Hp <= 0;
}
}
}

View File

@@ -8,6 +8,7 @@ using Client.Domain.Entities;
using Client.Domain.Enums;
using Client.Domain.Factories;
using Client.Domain.ValueObjects;
using Client.Domain.ViewModels;
namespace Client.Domain.Service
{
@@ -23,15 +24,18 @@ namespace Client.Domain.Service
throw new ArgumentNullException(nameof(message));
}
messages.Add(message);
mainViewModel.AddChatMessage(message);
}
}
public ChatMessageHandler(EntityFactoryInterface<ChatMessage> factory)
public ChatMessageHandler(EntityFactoryInterface<ChatMessage> factory, MainViewModelInterface mainViewModel)
{
this.factory = factory;
this.mainViewModel = mainViewModel;
}
private readonly EntityFactoryInterface<ChatMessage> factory;
private readonly MainViewModelInterface mainViewModel;
private List<ChatMessage> messages = new List<ChatMessage>();
}
}

View File

@@ -0,0 +1,30 @@
using Client.Domain.Entities;
using Client.Domain.Factories;
using Client.Domain.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Client.Domain.Service
{
public class PlayerHandler : EntityHandler<Player>
{
public override void OnCreate(Player entity)
{
mainViewModel.AddPlayer(entity);
}
public override void OnDelete(Player entity)
{
mainViewModel.RemovePlayer(entity);
}
public PlayerHandler(EntityFactoryInterface<Player> factory, MainViewModelInterface mainViewModel) : base(factory)
{
this.mainViewModel = mainViewModel;
}
private readonly MainViewModelInterface mainViewModel;
}
}

View File

@@ -23,13 +23,14 @@ namespace Client.Domain.Service
}
entities[entity.Id] = entity;
OnCreate(entity);
}
else if (operation == MessageOperationEnum.Update)
{
if (entity != null && entities.ContainsKey(entity.Id))
{
factory.Update(entities[entity.Id], content);
OnUpdate(entity);
}
}
else if (operation == MessageOperationEnum.Delete)
@@ -37,10 +38,26 @@ namespace Client.Domain.Service
if (entity != null)
{
entities.Remove(entity.Id);
OnDelete(entity);
}
}
}
public virtual void OnCreate(T entity)
{
}
public virtual void OnUpdate(T entity)
{
}
public virtual void OnDelete(T entity)
{
}
public EntityHandler(EntityFactoryInterface<T> factory)
{
this.factory = factory;

View File

@@ -0,0 +1,30 @@
using Client.Domain.Entities;
using Client.Domain.Factories;
using Client.Domain.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Client.Domain.Service
{
public class HeroHandler : EntityHandler<Hero>
{
public override void OnCreate(Hero entity)
{
mainViewModel.CreateHero(entity);
}
public override void OnDelete(Hero entity)
{
mainViewModel.DeleteHero();
}
public HeroHandler(EntityFactoryInterface<Hero> factory, MainViewModelInterface mainViewModel) : base(factory)
{
this.mainViewModel = mainViewModel;
}
private readonly MainViewModelInterface mainViewModel;
}
}

View File

@@ -0,0 +1,30 @@
using Client.Domain.Entities;
using Client.Domain.Factories;
using Client.Domain.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Client.Domain.Service
{
public class NpcHandler : EntityHandler<NPC>
{
public override void OnCreate(NPC entity)
{
mainViewModel.AddNpc(entity);
}
public override void OnDelete(NPC entity)
{
mainViewModel.RemoveNpc(entity);
}
public NpcHandler(EntityFactoryInterface<NPC> factory, MainViewModelInterface mainViewModel) : base(factory)
{
this.mainViewModel = mainViewModel;
}
private readonly MainViewModelInterface mainViewModel;
}
}

View File

@@ -0,0 +1,30 @@
using Client.Domain.Entities;
using Client.Domain.Factories;
using Client.Domain.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Client.Domain.Service
{
public class DropHandler : EntityHandler<Drop>
{
public override void OnCreate(Drop entity)
{
mainViewModel.AddDrop(entity);
}
public override void OnDelete(Drop entity)
{
mainViewModel.RemoveDrop(entity);
}
public DropHandler(EntityFactoryInterface<Drop> factory, MainViewModelInterface mainViewModel) : base(factory)
{
this.mainViewModel = mainViewModel;
}
private readonly MainViewModelInterface mainViewModel;
}
}

View File

@@ -1,16 +1,28 @@
namespace Client.Domain.ValueObjects
using Client.Domain.Common;
namespace Client.Domain.ValueObjects
{
public class ExperienceInfo
public class ExperienceInfo : NotifyPropertyChanged
{
public uint Level { get; set; }
public uint Exp { get; set; }
public uint Sp { get; set; }
private uint level;
private uint exp;
private uint sp;
public uint Level { get => level; set { if (value != level) { level = value; OnPropertyChanged("Level"); OnPropertyChanged("ExpToLevel"); } } }
public uint Exp { get => exp; set { if (value != exp) { exp = value; OnPropertyChanged("Exp"); } } }
public uint Sp { get => sp; set { if (value != sp) { sp = value; OnPropertyChanged("Sp"); } } }
public uint ExpToLevel {
get
{
return level * 200;
}
}
public ExperienceInfo(uint level, uint exp, uint sp)
{
Level = level;
Exp = exp;
Sp = sp;
this.level = level;
this.exp = exp;
this.sp = sp;
}
}
}

View File

@@ -1,14 +1,19 @@
namespace Client.Domain.ValueObjects
using Client.Domain.Common;
namespace Client.Domain.ValueObjects
{
public class FullName
public class FullName : NotifyPropertyChanged
{
public string Nickname { get; set; }
public string Title { get; set; }
private string nickname;
private string title;
public string Nickname { get => nickname; set { if (value != nickname) { nickname = value; OnPropertyChanged("Nickname"); } } }
public string Title { get => title; set { if (value != title) { title = value; OnPropertyChanged("Title"); } } }
public FullName(string nickname, string title)
{
Nickname = nickname;
Title = title;
this.nickname = nickname;
this.title = title;
}
}
}

View File

@@ -1,20 +1,26 @@
using Client.Domain.Enums;
using Client.Domain.Common;
using Client.Domain.Enums;
namespace Client.Domain.ValueObjects
{
public class Phenotype
public class Phenotype : NotifyPropertyChanged
{
public RaceEnum Race { get; set; }
public bool IsMale { get; set; }
public ClassEnum Class { get; set; }
public ClassEnum ActiveClass { get; set; }
private RaceEnum race;
private bool isMale;
private ClassEnum @class;
private ClassEnum activeClass;
public RaceEnum Race { get => race; set { if (value != race) { race = value; OnPropertyChanged("Race"); } } }
public bool IsMale { get => isMale; set { if (value != isMale) { isMale = value; OnPropertyChanged("IsMale"); } } }
public ClassEnum Class { get => @class; set { if (value != @class) { @class = value; OnPropertyChanged("Class"); } } }
public ClassEnum ActiveClass { get => activeClass; set { if (value != activeClass) { activeClass = value; OnPropertyChanged("ActiveClass"); } } }
public Phenotype(RaceEnum race, bool isMale, ClassEnum @class, ClassEnum activeClass)
{
Race = race;
IsMale = isMale;
Class = @class;
ActiveClass = activeClass;
this.race = race;
this.isMale = isMale;
this.@class = @class;
this.activeClass = activeClass;
}
}
}

View File

@@ -1,18 +1,25 @@
namespace Client.Domain.ValueObjects
using Client.Domain.Common;
namespace Client.Domain.ValueObjects
{
public class Transform
public class Transform : NotifyPropertyChanged
{
public Vector3 Position { get; set; }
public Vector3 Rotation { get; set; }
public Vector3 Velocity { get; set; }
public Vector3 Acceleration { get; set; }
private Vector3 position;
private Vector3 rotation;
private Vector3 velocity;
private Vector3 acceleration;
public Vector3 Position { get => position; set { if (value != position) { position = value; OnPropertyChanged("Position"); } } }
public Vector3 Rotation { get => rotation; set { if (value != rotation) { rotation = value; OnPropertyChanged("Rotation"); } } }
public Vector3 Velocity { get => velocity; set { if (value != velocity) { velocity = value; OnPropertyChanged("Velocity"); } } }
public Vector3 Acceleration { get => acceleration; set { if (value != acceleration) { acceleration = value; OnPropertyChanged("Acceleration"); } } }
public Transform(Vector3 position, Vector3 rotation, Vector3 velocity, Vector3 acceleration)
{
Position = position;
Rotation = rotation;
Velocity = velocity;
Acceleration = acceleration;
this.position = position;
this.rotation = rotation;
this.velocity = velocity;
this.acceleration = acceleration;
}
}
}

View File

@@ -1,16 +1,33 @@
namespace Client.Domain.ValueObjects
using Client.Domain.Common;
using System;
namespace Client.Domain.ValueObjects
{
public class Vector3
public class Vector3 : NotifyPropertyChanged
{
public float X { get; set; }
public float Y { get; set; }
public float Z { get; set; }
private float x;
private float y;
private float z;
public float X { get => x; set { if (value != x) { x = value; OnPropertyChanged("X"); } } }
public float Y { get => y; set { if (value != y) { y = value; OnPropertyChanged("Y"); } } }
public float Z { get => z; set { if (value != z) { z = value; OnPropertyChanged("X"); } } }
public Vector3(float x, float y, float z)
{
X = x;
Y = y;
Z = z;
this.x = x;
this.y = y;
this.z = z;
}
public float HorizontalSqrDistance(Vector3 other)
{
return MathF.Pow(x - other.x, 2) + MathF.Pow(y - other.y, 2);
}
public float HorizontalDistance(Vector3 other)
{
return MathF.Sqrt(HorizontalSqrDistance(other));
}
}
}

View File

@@ -1,22 +1,31 @@
namespace Client.Domain.ValueObjects
using Client.Domain.Common;
namespace Client.Domain.ValueObjects
{
public class VitalStats
public class VitalStats : NotifyPropertyChanged
{
public uint Hp { get; set; }
public uint MaxHp { get; set; }
public uint Mp { get; set; }
public uint MaxMp { get; set; }
public uint Cp { get; set; }
public uint MaxCp { get; set; }
private uint hp;
private uint maxHp;
private uint mp;
private uint maxMp;
private uint cp;
private uint maxCp;
public uint Hp { get => hp; set { if (value != hp) { hp = value; OnPropertyChanged("Hp"); } } }
public uint MaxHp { get => maxHp; set { if (value != maxHp) { maxHp = value; OnPropertyChanged("MaxHp"); } } }
public uint Mp { get => mp; set { if (value != mp) { mp = value; OnPropertyChanged("Mp"); } } }
public uint MaxMp { get => maxMp; set { if (value != maxMp) { maxMp = value; OnPropertyChanged("MaxMp"); } } }
public uint Cp { get => cp; set { if (value != cp) { cp = value; OnPropertyChanged("Cp"); } } }
public uint MaxCp { get => maxCp; set { if (value != maxCp) { maxCp = value; OnPropertyChanged("MaxCp"); } } }
public VitalStats(uint hp, uint maxHp, uint mp, uint maxMp, uint cp, uint maxCp)
{
Hp = hp;
MaxHp = maxHp;
Mp = mp;
MaxMp = maxMp;
Cp = cp;
MaxCp = maxCp;
this.hp = hp;
this.maxHp = maxHp;
this.mp = mp;
this.maxMp = maxMp;
this.cp = cp;
this.maxCp = maxCp;
}
}
}

View File

@@ -0,0 +1,24 @@
using Client.Application.ViewModels;
using Client.Domain.Entities;
using Client.Domain.ValueObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Client.Domain.ViewModels
{
public interface MainViewModelInterface
{
void AddChatMessage(ChatMessage chatMessage);
void CreateHero(Hero hero);
void DeleteHero();
void AddNpc(NPC npc);
void RemoveNpc(NPC npc);
void AddPlayer(Player player);
void RemovePlayer(Player player);
void AddDrop(Drop drop);
void RemoveDrop(Drop drop);
}
}