Skip to content

Commit

Permalink
#58 battleシーンのstateつくる (#61)
Browse files Browse the repository at this point in the history
* Executeつくった

* ログに表示する文章を修正

* ウィンドウ内での選択、前のウィンドウに戻る、の実装

各ウィンドウのState、ウィンドウ内での選択、次のウィンドウに進む、前のウィンドウに戻る、の機能の実装
デバッグ画面での正常動作確認済み

* 全状態の統合、Injectへの変更
  • Loading branch information
ujisuke authored Aug 29, 2024
1 parent 1df7968 commit 7343df3
Show file tree
Hide file tree
Showing 29 changed files with 1,450 additions and 52 deletions.
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

0 comments on commit 7343df3

Please sign in to comment.