Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#58 battleシーンのstateつくる #61

Merged
merged 4 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
922 changes: 872 additions & 50 deletions Assets/App/Scenes/SampleScene.unity

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Assets/App/Scripts/Battle/BattleLifetimeScope.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using App.Battle.Datastores;
using App.Battle.UseCases;
using App.Battle.Presenters;
using App.Battle.Interfaces.UseCases;
using App.Battle.Interfaces.Datastores;

using UnityEngine;
using VContainer;
using VContainer.Unity;
Expand All @@ -13,5 +13,7 @@ protected override void Configure(IContainerBuilder builder)
{
builder.Register<BattleEnemyDatastore>(Lifetime.Singleton).AsImplementedInterfaces();
builder.Register<BattleEnemyUseCase>(Lifetime.Singleton).AsImplementedInterfaces();
builder.Register<BattleStateMachineUseCase>(Lifetime.Singleton).AsImplementedInterfaces();
builder.Register<BattleStateMachinePresenter>(Lifetime.Singleton).AsImplementedInterfaces();
}
}
14 changes: 14 additions & 0 deletions Assets/App/Scripts/Battle/Interfaces/IBattleState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace App.Battle.Interfaces
{
public interface IBattleState
{
public void IncreaseIndex();
public void DecreaseIndex();
public IBattleState Execute();
public IBattleState Cancel();
}
}
11 changes: 11 additions & 0 deletions Assets/App/Scripts/Battle/Interfaces/IBattleState.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace App.Battle.Interfaces.Presenters
{
public interface IBattleStateMachinePresenter
{
public void IncreaseIndex();
public void DecreaseIndex();
public void Execute();
public void Cancel();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace App.Battle.Interfaces.UseCases
{
public interface IBattleStateMachineUseCase
{
public void IncreaseIndex();
public void DecreaseIndex();
public void Execute();
public void Cancel();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions Assets/App/Scripts/Battle/Presenters/BattleStateFirstPresenter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using App.Battle.Interfaces;

namespace App.Battle.Presenters
{
public class BattleStateFirstPresenter : IBattleState
{
private int _nextStateNumber = 3;
private int _nextStateIndex = 0;

public void IncreaseIndex()
{
if(_nextStateIndex < _nextStateNumber - 1)
{
_nextStateIndex++;
}
UnityEngine.Debug.Log($"CurrentIndex: {_nextStateIndex}");
}

public void DecreaseIndex()
{
if(_nextStateIndex > 0)
{
_nextStateIndex--;
}
UnityEngine.Debug.Log($"CurrentIndex: {_nextStateIndex}");
}

public IBattleState Execute()
{
switch(_nextStateIndex)
{
case 0:
UnityEngine.Debug.Log("CurrentState: Select Skill");
return new BattleStateSkillsPresenter();
case 1:
UnityEngine.Debug.Log("CurrentState: Select Command");
return this;
case 2:
UnityEngine.Debug.Log("CurrentState: Select Item");
return new BattleStateItemsPresenter();
}
return null;
}

public IBattleState Cancel()
{
UnityEngine.Debug.Log("CurrentState: Select Command");
return this;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions Assets/App/Scripts/Battle/Presenters/BattleStateItemsPresenter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using App.Battle.Interfaces;

namespace App.Battle.Presenters
{
public class BattleStateItemsPresenter : IBattleState
{
public void IncreaseIndex()
{
UnityEngine.Debug.Log("CurrentIndex: 0");
return;
}

public void DecreaseIndex()
{
UnityEngine.Debug.Log("CurrentIndex: 0");
return;
}

public IBattleState Execute()
{
UnityEngine.Debug.Log("CurrentState: Select Target(Item)");
return new BattleStateItemsTargetPresenter();
}

public IBattleState Cancel()
{
UnityEngine.Debug.Log("CurrentState: Select Command");
return new BattleStateFirstPresenter();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using App.Battle.Interfaces;

namespace App.Battle.Presenters
{
public class BattleStateItemsTargetPresenter : IBattleState
{

public void IncreaseIndex()
{
UnityEngine.Debug.Log("CurrentIndex: 0");
return;
}

public void DecreaseIndex()
{
UnityEngine.Debug.Log("CurrentIndex: 0");
return;
}

public IBattleState Execute()
{
UnityEngine.Debug.Log("CurrentState: Select Item");
return new BattleStateItemsPresenter();
}

public IBattleState Cancel()
{
UnityEngine.Debug.Log("CurrentState: Select Item");
return new BattleStateItemsPresenter();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using App.Battle.Interfaces;
using App.Battle.Interfaces.Presenters;

namespace App.Battle.Presenters
{
public class BattleStateMachinePresenter : IBattleStateMachinePresenter
{
private IBattleState _currentState = new BattleStateFirstPresenter();

public void IncreaseIndex()
{
if(_currentState == null)
{
throw new System.Exception("CurrentState is null");
}
_currentState.IncreaseIndex();
}

public void DecreaseIndex()
{
if(_currentState == null)
{
throw new System.Exception("CurrentState is null");
}
_currentState.DecreaseIndex();
}

public void Execute()
{
if(_currentState == null)
{
throw new System.Exception("CurrentState is null");
}
_currentState = _currentState.Execute();
}

public void Cancel()
{
_currentState = _currentState.Cancel();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions Assets/App/Scripts/Battle/Presenters/BattleStateSkillsPresenter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using App.Battle.Interfaces;

namespace App.Battle.Presenters
{
public class BattleStateSkillsPresenter : IBattleState
{
public void IncreaseIndex()
{
UnityEngine.Debug.Log("CurrentIndex: 0");
return;
}

public void DecreaseIndex()
{
UnityEngine.Debug.Log("CurrentIndex: 0");
return;
}

public IBattleState Execute()
{
UnityEngine.Debug.Log("CurrentState: Select Target(Skill)");
return new BattleStateSkillsTargetPresenter();
}

public IBattleState Cancel()
{
UnityEngine.Debug.Log("CurrentState: Select Command");
return new BattleStateFirstPresenter();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using App.Battle.Interfaces;

namespace App.Battle.Presenters
{
public class BattleStateSkillsTargetPresenter : IBattleState
{
public void IncreaseIndex()
{
UnityEngine.Debug.Log("CurrentIndex: 0");
return;
}

public void DecreaseIndex()
{
UnityEngine.Debug.Log("CurrentIndex: 0");
return;
}

public IBattleState Execute()
{
UnityEngine.Debug.Log("CurrentState: Select Command");
return new BattleStateFirstPresenter();
}

public IBattleState Cancel()
{
UnityEngine.Debug.Log("CurrentState: Select Skill");
return new BattleStateSkillsPresenter();
}
}
}
Loading