-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: State Condition & Function Mapper.
- Loading branch information
1 parent
615b961
commit 0619794
Showing
12 changed files
with
117 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 1 addition & 37 deletions
38
Assets/HnSF/Samples/TDAction/Scripts/State/StateConditionMapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using HnSF.Fighters; | ||
|
||
namespace HnSF.Sample.TDAction.State | ||
{ | ||
[System.Serializable] | ||
public class StateConditionMapper | ||
public class StateConditionMapper : StateConditionMapperBase | ||
{ | ||
public Dictionary<int, Func<IFighterBase, IConditionVariables, bool>> functions = | ||
new Dictionary<int, Func<IFighterBase, IConditionVariables, bool>>(); | ||
|
||
public StateConditionMapper() | ||
{ | ||
functions.Add((int)ConditionFunctionEnum.NONE, BaseConditionFunctions.NoCondition); | ||
} | ||
|
||
public virtual bool TryRegisterCondition(int id, Func<IFighterBase, IConditionVariables, bool> condition) | ||
{ | ||
if (functions.ContainsKey(id)) return false; | ||
functions.Add(id, condition); | ||
return true; | ||
} | ||
|
||
public virtual void RegisterCondition(int id, Func<IFighterBase, IConditionVariables, bool> condition) | ||
{ | ||
functions.Add(id, condition); | ||
} | ||
|
||
public virtual bool OverrideCondition(int id, Func<IFighterBase, IConditionVariables, bool> condition) | ||
{ | ||
functions[id] = condition; | ||
return true; | ||
} | ||
|
||
public virtual void RemoveCondition(int id) | ||
{ | ||
functions.Remove(id); | ||
} | ||
|
||
public virtual bool TryCondition(int id, IFighterBase fighter, IConditionVariables variables) | ||
{ | ||
return functions[id](fighter, variables); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
Assets/HnSF/Samples/TDAction/Scripts/State/StateConditionMapper.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
35 changes: 3 additions & 32 deletions
35
Assets/HnSF/Samples/TDAction/Scripts/State/StateFunctionMapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using HnSF.Fighters; | ||
using HnSF.Sample.TDAction.State; | ||
|
||
namespace HnSF.Sample.TDAction.State | ||
namespace HnSF.Sample.TDAction | ||
{ | ||
[System.Serializable] | ||
public class StateFunctionMapper | ||
public class StateFunctionMapper : StateFunctionMapperBase | ||
{ | ||
public Dictionary<int, Action<IFighterBase, IStateVariables>> functions = | ||
new Dictionary<int, Action<IFighterBase, IStateVariables>>(); | ||
|
||
public StateFunctionMapper() | ||
{ | ||
functions.Add((int)StateFunctionEnum.CHANGE_STATE, BaseStateFunctions.ChangeState); | ||
} | ||
|
||
public virtual bool TryRegisterFunction(int id, Action<IFighterBase, IStateVariables> function) | ||
{ | ||
if (functions.ContainsKey(id)) return false; | ||
functions.Add(id, function); | ||
return true; | ||
} | ||
|
||
public virtual void RegisterFunction(int id, Action<IFighterBase, IStateVariables> function) | ||
{ | ||
functions.Add(id, function); | ||
} | ||
|
||
public virtual bool OverrideFunction(int id, Action<IFighterBase, IStateVariables> function) | ||
{ | ||
functions[id] = function; | ||
return true; | ||
} | ||
|
||
public virtual void RemoveFunction(int id) | ||
{ | ||
functions.Remove(id); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
Assets/HnSF/Samples/TDAction/Scripts/State/StateFunctionMapper.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using HnSF.Fighters; | ||
|
||
namespace HnSF | ||
{ | ||
[System.Serializable] | ||
public class StateConditionMapperBase | ||
{ | ||
public Dictionary<int, Func<IFighterBase, IConditionVariables, bool>> functions = | ||
new Dictionary<int, Func<IFighterBase, IConditionVariables, bool>>(); | ||
|
||
public virtual bool TryRegisterCondition(int id, Func<IFighterBase, IConditionVariables, bool> condition) | ||
{ | ||
if (functions.ContainsKey(id)) return false; | ||
functions.Add(id, condition); | ||
return true; | ||
} | ||
|
||
public virtual void RegisterCondition(int id, Func<IFighterBase, IConditionVariables, bool> condition) | ||
{ | ||
functions.Add(id, condition); | ||
} | ||
|
||
public virtual bool OverrideCondition(int id, Func<IFighterBase, IConditionVariables, bool> condition) | ||
{ | ||
functions[id] = condition; | ||
return true; | ||
} | ||
|
||
public virtual void RemoveCondition(int id) | ||
{ | ||
functions.Remove(id); | ||
} | ||
|
||
public virtual bool TryCondition(int id, IFighterBase fighter, IConditionVariables variables) | ||
{ | ||
return functions[id](fighter, variables); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using HnSF.Fighters; | ||
|
||
namespace HnSF | ||
{ | ||
[System.Serializable] | ||
public class StateFunctionMapperBase | ||
{ | ||
public Dictionary<int, Action<IFighterBase, IStateVariables>> functions = | ||
new Dictionary<int, Action<IFighterBase, IStateVariables>>(); | ||
|
||
public virtual bool TryRegisterFunction(int id, Action<IFighterBase, IStateVariables> function) | ||
{ | ||
if (functions.ContainsKey(id)) return false; | ||
functions.Add(id, function); | ||
return true; | ||
} | ||
|
||
public virtual void RegisterFunction(int id, Action<IFighterBase, IStateVariables> function) | ||
{ | ||
functions.Add(id, function); | ||
} | ||
|
||
public virtual bool OverrideFunction(int id, Action<IFighterBase, IStateVariables> function) | ||
{ | ||
functions[id] = function; | ||
return true; | ||
} | ||
|
||
public virtual void RemoveFunction(int id) | ||
{ | ||
functions.Remove(id); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters