Развитие системы растений

This commit is contained in:
ThomasCharester committed 2026-03-02 18:25:46 +03:00
1 parent 1b578067f3
commit ba49ef5015
218 files changed
+70415 -1519

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 98b04a1dab924594a3bb3f93d863cc02
timeCreated: 1772122466
@@ -0,0 +1,18 @@
using Code.Infrastructure.Generators;
using UnityEngine;
using UnityEngine.AddressableAssets;
namespace Code.Calendar.Constants
{
[Config("Configs/ImageConfig", true)]
public class ConstantImage
{
[ToConfig] public AssetReference image;
[ToConfig] public ConstantImageType imageType;
}
public enum ConstantImageType
{
NoPhoto
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 188200b6891f44d993888cc4c68a3bea
timeCreated: 1772122627
@@ -0,0 +1,46 @@
using System.Collections.Generic;
using System.Linq;
using Code.Infrastructure.Configs;
using Code.Infrastructure.EventBus;
using Cysharp.Threading.Tasks;
using UnityEngine.AddressableAssets;
namespace Code.Calendar.Constants
{
// Написать кодрайтер, который будет находить конфиги и добавлять их сюда пока написано само
public class ConstantImagesService
{
private readonly EventBus _eventBus;
public List<ConstantImageConfig> Configs { get; private set; }
public ConstantImagesService(EventBus eventBus, IConfigLocator configLocator)
{
_eventBus = eventBus;
var label = configLocator.TryGetManyConfigAssetReferences<ConstantImageConfig>();
LoadImage(label).Forget();
}
private async UniTaskVoid LoadImage(string imagesLabel)
{
if ((await Addressables.LoadResourceLocationsAsync(imagesLabel).Task).Count != 0)
{
var images =
Addressables.LoadAssetsAsync<ConstantImageConfig>(imagesLabel, null, Addressables.MergeMode.Union);
await images.ToUniTask();
Configs = images.Result.ToList();
}
_eventBus.RaiseEvent<IConstantImagesServiceHandle>(x=> x.ImagesLoaded());
}
}
public interface IConstantImagesServiceHandle : IGlobalSubscriber
{
void ImagesLoaded();
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e08f396c88804dac9946217cd9474bfa
timeCreated: 1772122482
@@ -3,19 +3,38 @@ using System.Collections.Generic;
namespace Code.Calendar.DataStructures
{
public struct Plant
public struct Plant : IEquatable<Plant>
{
public string Name;
public string IconPath;
public int Id;
public Guid Id;
public bool Equals(Plant other) => Id == other.Id;
public override bool Equals(object obj) => obj is Plant other && Equals(other);
public override int GetHashCode() => Id.GetHashCode();
}
public struct Task
public struct Task : IEquatable<Task>
{
public Guid Id;
public bool Active;
public string Description;
public DateTime Date;
public bool IsPeriodic;
public int PeriodicInterval;
public int PlantId;
public DateTime PeriodicUntil;
public Guid PlantId;
public List<string> PhotoPaths;
public bool Equals(Task other) => Id == other.Id;
public override bool Equals(object obj) => obj is Task other && Equals(other);
public override int GetHashCode() => Id.GetHashCode();
}
}
@@ -0,0 +1,117 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Code.Infrastructure.EventBus;
using Cysharp.Threading.Tasks;
using Newtonsoft.Json;
using UnityEngine;
namespace Code.Calendar.DataStructures
{
public interface IPlantService
{
void AddPlant(Plant plant);
void DeletePlant(Plant plant);
Plant GetPlant(Guid plantId);
List<Plant> GetPlants();
void EditPlant(Guid guid, Plant newPlant);
}
public class PlantService : IDisposable, IPlantService
{
private readonly EventBus _eventBus;
private List<Plant> _plants;
public PlantService(EventBus eventBus)
{
_eventBus = eventBus;
LoadJsonTasks().Forget();
}
private async UniTaskVoid LoadJsonTasks()
{
var path = Path.Combine(Application.persistentDataPath, "Plants.json");
if (File.Exists(path))
{
using StreamReader reader = new(path);
_plants = JsonConvert.DeserializeObject<List<Plant>>(await reader.ReadToEndAsync()) ?? new List<Plant>();
}
else
{
await using (File.Create(path)) { }
}
_eventBus.RaiseEvent<IPlantsServiceInitHandle>(x=> x.PlantsLoaded());
}
private bool _inAction, _reUseRequest;
private async UniTaskVoid SaveJsonTasks()
{
if (_inAction)
{
_reUseRequest = true;
return;
}
_inAction = true;
var json = JsonConvert.SerializeObject(_plants, Formatting.Indented);
await using StreamWriter writer = new(Path.Combine(Application.persistentDataPath, "Plants.json"));
await writer.WriteAsync(json).AsUniTask();
_inAction = false;
if(!_reUseRequest) _eventBus.RaiseEvent<IPlantsServiceInitHandle>(x=> x.PlantsSaved());
else SaveJsonTasks().Forget();
}
public void AddPlant(Plant plant)
{
plant.Id = Guid.NewGuid();
_plants.Add(plant);
SaveJsonTasks().Forget();
}
public void EditPlant(Guid guid, Plant newPlant)
{
_plants[_plants.FindIndex(x => x.Id == guid)] = newPlant;
SaveJsonTasks().Forget();
}
public void DeletePlant(Plant plant)
{
_plants.Remove(plant);
SaveJsonTasks().Forget();
}
public Plant GetPlant(Guid plantId) => _plants.FirstOrDefault(x => x.Id == plantId);
public List<Plant> GetPlants() => _plants;
public void Dispose()
{
SaveJsonTasks().Forget();
}
}
public interface IPlantsServiceInitHandle : IGlobalSubscriber
{
void PlantsLoaded();
void PlantsSaved();
}
public interface IPlantsServiceHandle : IGlobalSubscriber
{
void PlantAdded();
void PlantRemoved();
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: eb3e195da68845ea872e2eff73582745
timeCreated: 1772116279
@@ -0,0 +1,129 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Code.Infrastructure.EventBus;
using Cysharp.Threading.Tasks;
using Newtonsoft.Json;
using UnityEngine;
namespace Code.Calendar.DataStructures
{
public interface ITaskService
{
void AddTask(Task task);
void DeleteTask(Task task);
List<Task> GetByPlant(Guid plantId);
List<Task> GetTasks();
List<Task> GetByDate(DateTime date);
void EditTask(Guid guid, Task newTask);
}
public class TaskService : IDisposable, ITaskService
{
private readonly EventBus _eventBus;
private List<Task> _tasks;
public TaskService(EventBus eventBus)
{
_eventBus = eventBus;
LoadJsonTasks().Forget();
}
private async UniTaskVoid LoadJsonTasks()
{
var path = Path.Combine(Application.persistentDataPath, "Tasks.json");
if (File.Exists(path))
{
using StreamReader reader = new(path);
_tasks = JsonConvert.DeserializeObject<List<Task>>(await reader.ReadToEndAsync()) ?? new List<Task>();
}
else
{
await using (File.Create(path)) { }
}
_eventBus.RaiseEvent<ITaskServiceHandle>(x => x.TasksLoaded());
}
private bool _inAction, _reUseRequest;
private async UniTaskVoid SaveJsonTasks()
{
if (_inAction)
{
_reUseRequest = true;
return;
}
_inAction = true;
var json = JsonConvert.SerializeObject(_tasks, Formatting.Indented);
await using StreamWriter writer = new(Path.Combine(Application.persistentDataPath, "Tasks.json"));
await writer.WriteAsync(json).AsUniTask();
_inAction = false;
if (!_reUseRequest) _eventBus.RaiseEvent<ITaskServiceHandle>(x => x.TasksSaved());
else SaveJsonTasks().Forget();
}
public void AddTask(Task task)
{
_tasks.Add(task);
task.Id = Guid.NewGuid();
SaveJsonTasks().Forget();
}
public void EditTask(Guid guid, Task newTask)
{
_tasks[_tasks.FindIndex(x => x.Id == guid)] = newTask;
SaveJsonTasks().Forget();
}
public void DeleteTask(Task task)
{
_tasks.Remove(task);
SaveJsonTasks().Forget();
}
public List<Task> GetByPlant(Guid plantId) => _tasks.Where(x => x.PlantId == plantId).ToList();
public List<Task> GetByDate(DateTime date)
{
var byDay = _tasks
.Where(x => x.Date.Day == date.Day)
.ToList();
var periodicOnes = _tasks
.Where(x => x.IsPeriodic && x.Date.Day + new TimeSpan(0, x.PeriodicInterval, 0).Days == date.Day)
.ToList();
byDay.AddRange(periodicOnes);
return byDay;
}
public List<Task> GetTasks() => _tasks;
public void Dispose()
{
SaveJsonTasks().Forget();
}
}
public interface ITaskServiceHandle : IGlobalSubscriber
{
void TasksLoaded();
void TasksSaved();
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e0a70b7566234451ad60128860af9517
timeCreated: 1772113905
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 073ac04536184a2b9b164161a2f41a61
timeCreated: 1772119626
@@ -0,0 +1,22 @@
using System;
using Code.Infrastructure.UI;
using PrimeTween;
using UnityEngine;
using UnityEngine.UI;
namespace Code.Calendar.Panels
{
public class LoadingPanel : UIPanel
{
[SerializeField] private Image loadingScreen;
public override void Open(Action callback = null)
{
Tween.Alpha(loadingScreen, 1f, 1f).OnComplete(target: this, _ => callback?.Invoke());
}
public override void Close(Action callback = null)
{
Tween.Alpha(loadingScreen, 0f, 1f).OnComplete(target: this, _ => callback?.Invoke());
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4466c13a031a42498f42c15baf25ec03
timeCreated: 1772123986
+22
View File
@@ -0,0 +1,22 @@
using System;
using Code.Infrastructure.UI;
using PrimeTween;
using UnityEngine;
using UnityEngine.UI;
namespace Code.Calendar.Panels
{
public class LogoPanel : UIPanel
{
[SerializeField] private Image logo;
public override void Open(Action callback = null)
{
Tween.Alpha(logo, 1f, 1f).OnComplete(target: this, _ => callback?.Invoke());
}
public override void Close(Action callback = null)
{
Tween.Alpha(logo, 0f, 1f).OnComplete(target: this, _ => callback?.Invoke());
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 03f95468478e4025944889f8b4a54798
timeCreated: 1772123906
@@ -0,0 +1,19 @@
using System;
using Code.Infrastructure.UI;
namespace Code.Calendar.Panels
{
public class PictureChooseMenu : UIPanel
{
public override void Open(Action callback = null)
{
}
public override void Close(Action callback = null)
{
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 46e10e555bb5495899af512610cde913
timeCreated: 1772119767
@@ -0,0 +1,43 @@
using System;
using Code.Calendar.Constants;
using Code.Calendar.DataStructures;
using Code.Infrastructure.UI;
using PrimeTween;
using Reflex.Attributes;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Code.Calendar.Panels
{
public class PlantAddPanel : UIPanel
{
[Inject] private IPlantService _plantService;
[SerializeField] private TMP_InputField plantName;
[SerializeField] private Image image;
public void TryGetIcon()
{
}
public void TryAddPlant()
{
Plant newPlant = new()
{
Name = plantName.text,
IconPath = null
};
_plantService.AddPlant(newPlant);
}
public override void Open(Action callback = null)
{
Tween.Alpha(image, 1f, 1f).OnComplete(target: this, _ => callback?.Invoke());
}
public override void Close(Action callback = null)
{
Tween.Alpha(image, 0f, 1f).OnComplete(target: this, _ => callback?.Invoke());
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2b11bfff50fe458c8799204f39f395ce
timeCreated: 1772119636