175 lines
5.8 KiB
C#
175 lines
5.8 KiB
C#
using Code.Calendar.Constants;
|
|
using Code.Calendar.DataStructures;
|
|
using Code.Infrastructure.Audio;
|
|
using Code.Infrastructure.Configs;
|
|
using Code.Infrastructure.Input;
|
|
using Code.Infrastructure.Loadings;
|
|
using Code.Infrastructure.SceneLoader;
|
|
using Code.Infrastructure.UI;
|
|
using Reflex.Core;
|
|
using Reflex.Enums;
|
|
using Reflex.Injectors;
|
|
using UnityEngine;
|
|
using Resolution = Reflex.Enums.Resolution;
|
|
|
|
namespace Code.Infrastructure.App
|
|
{
|
|
public class PapaInstaller : MonoBehaviour, IInstaller,
|
|
ISceneConfigsLoadedHandle,
|
|
IInputServiceInitializedHandle,
|
|
IUIInitializedHandle,
|
|
IUIPanelLoaded,
|
|
IAudioSourcePoolInitializedHandle,
|
|
IAudioConfigsLoadedHandle,
|
|
ILayerMasksInitializedHandle,
|
|
ITaskServiceHandle,
|
|
IPlantsServiceInitHandle,
|
|
IConstantImagesServiceHandle
|
|
{
|
|
public void InstallBindings(ContainerBuilder containerBuilder)
|
|
{
|
|
InitLoadings();
|
|
|
|
containerBuilder.RegisterType(typeof(EventBus.EventBus), Lifetime.Singleton, Resolution.Eager);
|
|
containerBuilder.RegisterType(typeof(ConfigLocator), new[] { typeof(IConfigLocator) }, Lifetime.Singleton,
|
|
Resolution.Eager);
|
|
containerBuilder.RegisterType(typeof(SceneLoader.SceneLoader), Lifetime.Singleton, Resolution.Eager);
|
|
containerBuilder.RegisterType(typeof(InputService), new[] { typeof(IInputService) }, Lifetime.Singleton,
|
|
Resolution.Eager);
|
|
|
|
containerBuilder.OnContainerBuilt += Bootstrap;
|
|
|
|
containerBuilder.RegisterType(typeof(AppStateMachine), Lifetime.Singleton, Resolution.Lazy);
|
|
containerBuilder.RegisterType(typeof(AppStateMachineContext), Lifetime.Singleton, Resolution.Lazy);
|
|
|
|
containerBuilder.RegisterType(typeof(UIFactory), new[] { typeof(IUIFactory) }, Lifetime.Singleton,
|
|
Resolution.Eager);
|
|
containerBuilder.RegisterType(typeof(UIService), new[] { typeof(IUIService) }, Lifetime.Singleton,
|
|
Resolution.Eager);
|
|
|
|
|
|
containerBuilder.RegisterType(typeof(AudioFactory), new[] { typeof(IAudioFactory) }, Lifetime.Singleton,
|
|
Resolution.Eager);
|
|
containerBuilder.RegisterType(typeof(AudioSourcePool), new[] { typeof(IAudioSourcePool) }, Lifetime.Singleton,
|
|
Resolution.Eager);
|
|
containerBuilder.RegisterType(typeof(AudioService), new[] { typeof(IAudioService) }, Lifetime.Singleton,
|
|
Resolution.Eager);
|
|
|
|
containerBuilder.RegisterType(typeof(TaskService), new[] { typeof(ITaskService) }, Lifetime.Singleton,
|
|
Resolution.Eager);
|
|
containerBuilder.RegisterType(typeof(PlantService), new[] { typeof(IPlantService) }, Lifetime.Singleton,
|
|
Resolution.Eager);
|
|
|
|
containerBuilder.RegisterType(typeof(ConstantImagesService), Lifetime.Singleton,
|
|
Resolution.Eager);
|
|
}
|
|
|
|
private void InitLoadings()
|
|
{
|
|
// UIFactory =
|
|
// Logo
|
|
// Scene configs =
|
|
// Input service
|
|
// Audio Factory =
|
|
// Audio Pool =
|
|
// Layer masks
|
|
// Tasks =
|
|
// Plants =
|
|
// CIS =
|
|
_initialLoading = new Loading(10, () => EssentialLoadEnded(_thatRightContainer));
|
|
|
|
}
|
|
|
|
private Loading _initialLoading;
|
|
private Container _thatRightContainer;
|
|
|
|
private void Bootstrap(Container container)
|
|
{
|
|
_thatRightContainer = container;
|
|
|
|
container.Resolve<EventBus.EventBus>().Subscribe(this);
|
|
|
|
ConstructorInjector.Construct(typeof(LayerMasks), container);
|
|
|
|
}
|
|
|
|
private void EssentialLoadEnded(Container container)
|
|
{
|
|
container.Resolve<EventBus.EventBus>().Unsubscribe(this);
|
|
container.Resolve<AppStateMachine>().SwitchState(AppStates.Bootstrap);
|
|
container.Resolve<AppStateMachineContext>().StateMachine = container.Resolve<AppStateMachine>();
|
|
}
|
|
|
|
public void SceneConfigsLoaded()
|
|
{
|
|
_initialLoading.DoProgress();
|
|
}
|
|
|
|
public void InputServiceInitialized()
|
|
{
|
|
_initialLoading.DoProgress();
|
|
}
|
|
|
|
public void UIInitialized()
|
|
{
|
|
_initialLoading.DoProgress();
|
|
|
|
_thatRightContainer.Resolve<IUIService>().TryLoadPanel(UIPanelType.Logo);
|
|
_thatRightContainer.Resolve<IUIService>().TryLoadPanel(UIPanelType.Loading);
|
|
}
|
|
|
|
public void UILoaded(UIPanelType uiPanelType)
|
|
{
|
|
switch (uiPanelType)
|
|
{
|
|
case UIPanelType.Logo:
|
|
_thatRightContainer.Resolve<IUIService>().OpenPanel(UIPanelType.Logo);
|
|
|
|
_initialLoading.DoProgress();
|
|
break;
|
|
case UIPanelType.Loading:
|
|
// _thatRightContainer.Resolve<IUIService>().OpenPanel(UIPanelType.Logo);
|
|
break;
|
|
default:
|
|
Application.Quit();
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void AudioSourcePoolInitialized()
|
|
{
|
|
_initialLoading.DoProgress();
|
|
}
|
|
|
|
public void AudioConfigsLoaded()
|
|
{
|
|
_initialLoading.DoProgress();
|
|
}
|
|
|
|
public void LayerMasksInitialized()
|
|
{
|
|
_initialLoading.DoProgress();
|
|
}
|
|
|
|
public void TasksLoaded()
|
|
{
|
|
_initialLoading.DoProgress();
|
|
}
|
|
|
|
public void TasksSaved()
|
|
{ }
|
|
|
|
public void PlantsLoaded()
|
|
{
|
|
_initialLoading.DoProgress();
|
|
}
|
|
|
|
public void PlantsSaved()
|
|
{ }
|
|
|
|
public void ImagesLoaded()
|
|
{
|
|
_initialLoading.DoProgress();
|
|
}
|
|
}
|
|
} |