mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-03-05 07:41:10 +00:00
init: add project
This commit is contained in:
3
Assets/_Project/Develop/Runtime/Logic/Meta/Features.meta
Normal file
3
Assets/_Project/Develop/Runtime/Logic/Meta/Features.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1a85f8109aa464592f37815723aee63
|
||||
timeCreated: 1770306353
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44bb00937a784327bfbe6de590646c85
|
||||
timeCreated: 1770822778
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace _Project.Develop.Runtime.Logic.Meta.Features.Wallet
|
||||
{
|
||||
public enum CurrencyTypes
|
||||
{
|
||||
Gold,
|
||||
Diamond
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1822fc8809b486dbb88227c36bec03f
|
||||
timeCreated: 1769721690
|
||||
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using _Project.Develop.Runtime.Logic.Meta.Features.Wallet;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using Assets._Project.Develop.Runtime.Utilities.DataManagement;
|
||||
using Assets._Project.Develop.Runtime.Utilities.DataManagement.DataProviders;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Meta.Features.Wallet
|
||||
{
|
||||
public class WalletService : IDataReader<PlayerData>, IDataWriter<PlayerData>
|
||||
{
|
||||
private readonly Dictionary<CurrencyTypes, ReactiveVariable<int>> _currencies;
|
||||
|
||||
public WalletService(
|
||||
Dictionary<CurrencyTypes, ReactiveVariable<int>> currencies,
|
||||
PlayerDataProvider playerDataProvider)
|
||||
{
|
||||
_currencies = new Dictionary<CurrencyTypes, ReactiveVariable<int>>(currencies);
|
||||
playerDataProvider.RegisterWriter(this);
|
||||
playerDataProvider.RegisterReader(this);
|
||||
}
|
||||
|
||||
public List<CurrencyTypes> AvailableCurrencies => _currencies.Keys.ToList();
|
||||
|
||||
public IReadOnlyVariable<int> GetCurrency(CurrencyTypes type) => _currencies[type];
|
||||
|
||||
public bool Enough(CurrencyTypes type, int amount)
|
||||
{
|
||||
if (amount < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(amount));
|
||||
|
||||
return _currencies[type].Value >= amount;
|
||||
}
|
||||
|
||||
public void Add(CurrencyTypes type, int amount)
|
||||
{
|
||||
if (amount < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(amount));
|
||||
|
||||
_currencies[type].Value += amount;
|
||||
}
|
||||
|
||||
public void Spend(CurrencyTypes type, int amount)
|
||||
{
|
||||
if (Enough(type, amount) == false)
|
||||
throw new InvalidOperationException("Not enough: " + type.ToString());
|
||||
|
||||
if (amount < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(amount));
|
||||
|
||||
_currencies[type].Value -= amount;
|
||||
}
|
||||
|
||||
public void ReadFrom(PlayerData data)
|
||||
{
|
||||
foreach (KeyValuePair<CurrencyTypes, int> currency in data.WalletData)
|
||||
{
|
||||
if (_currencies.ContainsKey(currency.Key))
|
||||
_currencies[currency.Key].Value = currency.Value;
|
||||
else
|
||||
_currencies.Add(currency.Key, new ReactiveVariable<int>(currency.Value));
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteTo(PlayerData data)
|
||||
{
|
||||
foreach (KeyValuePair<CurrencyTypes, ReactiveVariable<int>> currency in _currencies)
|
||||
{
|
||||
if (data.WalletData.ContainsKey(currency.Key))
|
||||
data.WalletData[currency.Key] = currency.Value.Value;
|
||||
else
|
||||
data.WalletData.Add(currency.Key, currency.Value.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bac6967622d94d37886219039cead5ed
|
||||
timeCreated: 1769721675
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f5af390c397c13478837cc2cccb7cdb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
using Assets._Project.Develop.Runtime.Infrastructure;
|
||||
using Assets._Project.Develop.Runtime.Infrastructure.DI;
|
||||
using Assets._Project.Develop.Runtime.Utilities.SceneManagement;
|
||||
using System.Collections;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Meta.Infrastructure
|
||||
{
|
||||
public class MainMenuBootstrap : SceneBootstrap
|
||||
{
|
||||
private DIContainer _container;
|
||||
|
||||
public override void ProcessRegistrations(DIContainer container, IInputSceneArgs sceneArgs = null)
|
||||
{
|
||||
_container = container;
|
||||
|
||||
MainMenuContextRegistrations.Process(_container);
|
||||
}
|
||||
|
||||
public override IEnumerator Initialize()
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
public override void Run()
|
||||
{ }
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c18e030accfe8446bfca4a0bc7ebbb5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
using _Project.Develop.Runtime.UI;
|
||||
using _Project.Develop.Runtime.UI.Core;
|
||||
using _Project.Develop.Runtime.UI.Screens.MainMenu;
|
||||
using Assets._Project.Develop.Runtime.Infrastructure.DI;
|
||||
using Assets._Project.Develop.Runtime.Utilities.AssetsManagement;
|
||||
using Assets._Project.Develop.Runtime.Utilities.SceneManagement;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Meta.Infrastructure
|
||||
{
|
||||
public class MainMenuContextRegistrations
|
||||
{
|
||||
public static void Process(DIContainer container)
|
||||
{
|
||||
container.RegisterAsSingle(CreateMainMenuUIRoot).NonLazy();
|
||||
container.RegisterAsSingle(CreateMainMenuPresentersFactory);
|
||||
container.RegisterAsSingle(CreateMainMenuScreenPresenter).NonLazy();
|
||||
container.RegisterAsSingle(CreateMainMenuPopupService);
|
||||
}
|
||||
|
||||
private static MainMenuPresentersFactory CreateMainMenuPresentersFactory(DIContainer c) => new(c);
|
||||
|
||||
private static MainMenuPopupService CreateMainMenuPopupService(DIContainer c)
|
||||
{
|
||||
return new MainMenuPopupService(
|
||||
c.Resolve<ViewsFactory>(),
|
||||
c.Resolve<ProjectPresentersFactory>(),
|
||||
c.Resolve<MainMenuUIRoot>());
|
||||
}
|
||||
|
||||
private static MainMenuUIRoot CreateMainMenuUIRoot(DIContainer c)
|
||||
{
|
||||
ResourcesAssetsLoader loader = c.Resolve<ResourcesAssetsLoader>();
|
||||
MainMenuUIRoot uiRootPrefab = loader.Load<MainMenuUIRoot>(PathToResources.UI.Screens.MainMenu);
|
||||
|
||||
return Object.Instantiate(uiRootPrefab);
|
||||
}
|
||||
|
||||
private static MainMenuScreenPresenter CreateMainMenuScreenPresenter(DIContainer c)
|
||||
{
|
||||
MainMenuUIRoot uiRoot = c.Resolve<MainMenuUIRoot>();
|
||||
MainMenuScreenView view = c.Resolve<ViewsFactory>().Create<MainMenuScreenView>(uiRoot.HUDLayer);
|
||||
MainMenuScreenPresenter presenter = c.Resolve<MainMenuPresentersFactory>().CreateMainMenuScreen(view);
|
||||
|
||||
return presenter;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a75665c6d4b5574dbfa1ffa841b7348
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user