This commit is contained in:
ThomasCharester committed 2026-02-26 11:21:27 +03:00
1 parent a73338916a
commit fbc1cc8d3e
207 files changed
+10327 -2

No files matched your search

@@ -0,0 +1,35 @@
using Code.Infrastructure.Audio;
using Code.Infrastructure.Camera;
using Code.Infrastructure.Input;
using Code.Infrastructure.UI;
using Reflex.Attributes;
namespace Code.Infrastructure.App
{
public enum AppStates
{
Bootstrap,
Gameplay,
MainMenu,
Platformer
}
public class AppStateMachineContext
{
[Inject] public SceneLoader.SceneLoader SceneLoader { get; set; }
[Inject] public CameraStateMachine Camera { get; set; }
[Inject] public CameraFactory CameraFactory { get; set; }
[Inject] public IUIService UIService { get; set; }
[Inject] public IAudioFactory AudioFactory { get; set; }
[Inject] public IAudioService AudioService { get; set; }
[Inject] public IInputService InputService { get; set; }
public AppStateMachine StateMachine { get; set; }
}
[Generators.StateMachine(typeof(AppStateMachineContext),typeof(AppStates))]
public partial class AppStateMachine
{
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5627248405434f028be921cb7916f823
timeCreated: 1765572329
@@ -0,0 +1,213 @@
using Code.Debug;
using Code.Infrastructure.Audio;
using Code.Infrastructure.Camera;
using Code.Infrastructure.Configs;
using Code.Infrastructure.Input;
using Code.Infrastructure.Loadings;
using Code.Infrastructure.SceneLoader;
using Code.Infrastructure.UI;
using Code.Infrastructure.Volume;
using Reflex.Core;
using Reflex.Enums;
using Reflex.Injectors;
using Unity.Cinemachine;
using UnityEngine;
using UnityEngine.Rendering.Universal;
using Resolution = Reflex.Enums.Resolution;
namespace Code.Infrastructure.App
{
public class PapaInstaller : MonoBehaviour, IInstaller,
ISceneConfigsLoadedHandle,
IInputServiceInitializedHandle,
ICameraInitializedHandle,
IUIInitializedHandle,
IUIPanelLoaded,
IVolumesInitializedHandle,
IVolumeLoaded,
IAudioSourcePoolInitializedHandle,
IAudioConfigsLoadedHandle,
ICinematicMachineHandle,
ILayerMasksInitializedHandle
{
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(CameraFactory), Lifetime.Singleton, Resolution.Lazy);
containerBuilder.RegisterType(typeof(CameraStateMachine), Lifetime.Singleton, Resolution.Lazy);
containerBuilder.RegisterType(typeof(CameraStateMachineContext), 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(VolumeService), new[] { typeof(IVolumeService) }, Lifetime.Singleton,
Resolution.Lazy);
containerBuilder.RegisterType(typeof(VolumeFactory), new[] { typeof(IVolumeFactory) }, 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);
}
private void InitLoadings()
{
// UIFactory
// Logo
// Scene configs
// Input service
// Camera
// Volume Factory
// Loading volume
// Audio Factory
// Audio Pool
// Cinemachine Camera
// Layer masks
_initialLoading = new Loading(11, () => EssentialLoadEnded(_thatRightContainer));
_ui2CamLoading = new Loading(2,
() =>
{
_thatRightContainer.Resolve<IUIService>().SetCanvasCamera(_thatRightContainer
.Resolve<CameraStateMachineContext>().cameraLoadedData.Camera);
});
}
private Loading _initialLoading;
private Loading _ui2CamLoading;
private Container _thatRightContainer;
private void Bootstrap(Container container)
{
_thatRightContainer = container;
container.Resolve<EventBus.EventBus>().Subscribe(this);
ConstructorInjector.Construct(typeof(LayerMasks), container);
var cameraFactory = container.Resolve<CameraFactory>();
cameraFactory.CreateCameraStateMachine(container.Resolve<CameraStateMachine>())
.Forget();
}
private void EssentialLoadEnded(Container container)
{
container.Resolve<EventBus.EventBus>().Unsubscribe(this);
container.Resolve<AppStateMachine>().SwitchState(AppStates.Bootstrap)
.AllowStateTransition(AppStates.Gameplay)
.AllowStateTransition(AppStates.Platformer);
container.Resolve<AppStateMachineContext>().StateMachine = container.Resolve<AppStateMachine>();
}
public void SceneConfigsLoaded()
{
_initialLoading.DoProgress();
}
public void InputServiceInitialized()
{
_initialLoading.DoProgress();
}
public void CameraInitialized(CameraStateMachineContext.CameraLoadedData data)
{
_thatRightContainer.Resolve<CameraStateMachineContext>().cameraLoadedData = data;
_thatRightContainer.Resolve<CameraStateMachine>().SwitchState(CameraMode.None)
.AllowStateTransition(CameraMode.ThirdPerson)
.AllowStateTransition(CameraMode.Platformer);
data.Camera.GetUniversalAdditionalCameraData().renderPostProcessing = true;
_ui2CamLoading.DoProgress();
_initialLoading.DoProgress();
_thatRightContainer.Resolve<CameraFactory>().LoadCinemachineCamera(CameraMode.None).Forget();
}
public void UIInitialized()
{
_ui2CamLoading.DoProgress();
_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 VolumesInitialized()
{
_initialLoading.DoProgress();
_thatRightContainer.Resolve<IVolumeService>().TryLoadVolume(VolumeId.MenuRetro);
}
public void VolumeLoaded(VolumeId volumeId)
{
switch (volumeId)
{
case VolumeId.MenuRetro:
_initialLoading.DoProgress();
break;
default:
Application.Quit();
break;
}
}
public void AudioSourcePoolInitialized()
{
_initialLoading.DoProgress();
}
public void AudioConfigsLoaded()
{
_initialLoading.DoProgress();
}
public void CinemachineLoaded(CinemachineCamera cinemachineCamera)
{
_initialLoading.DoProgress();
}
public void LayerMasksInitialized()
{
_initialLoading.DoProgress();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e62d9c9e01334727887a684e008440a6
timeCreated: 1765572590
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 778cb4118a914d9c8b1cac8bef4295a5
timeCreated: 1765572459
@@ -0,0 +1,48 @@
using System.Threading;
using Code.Debug;
using Code.Infrastructure.Audio;
using Code.Infrastructure.Generators;
using Code.Infrastructure.UI;
namespace Code.Infrastructure.App.States
{
[State(typeof(AppStates),typeof(AppStateMachineContext))]
[StateRaisingEvent]
public partial class BootstrapState : IUIPanelLoaded, IReadyToPlayHandle
{
private EventBus.EventBus _eventBus;
public BootstrapState(AppStateMachineContext context, EventBus.EventBus eventBus) : base(context,eventBus)
{
_eventBus = eventBus;
}
public override AppStates myState => AppStates.Bootstrap;
protected override void OnEnterState()
{
_eventBus.Subscribe(this);
Context.UIService.TryRemovePanel(UIPanelType.Logo);
Context.UIService.TryLoadPanel(UIPanelType.DebugSceneChooser);
Context.AudioFactory.LoadAudioClips(AudioNames.UISounds);
}
protected override void OnExitState()
{
// Context.AudioFactory.ReleaseAudios(AudioNames.UISounds);
Context.UIService.TryRemovePanel(UIPanelType.DebugSceneChooser);
_eventBus.Unsubscribe(this);
}
public void UILoaded(UIPanelType uiPanelType)
{
if (uiPanelType != UIPanelType.DebugSceneChooser) return;
Context.UIService.OpenPanel(uiPanelType);
}
public void OnReadyToPlay(AudioNames groupName)
{
Context.AudioService.PlayRepeatedly(AudioNames.UISounds,0);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 71df5370ea2e4819bfbdb9cbb8e6c0ab
timeCreated: 1765572469