Skip to content

Commit

Permalink
Unit test definition
Browse files Browse the repository at this point in the history
  • Loading branch information
Todorcevic committed May 11, 2024
1 parent efb3326 commit e8cf056
Show file tree
Hide file tree
Showing 44 changed files with 469 additions and 63 deletions.
3 changes: 2 additions & 1 deletion Assets/SRC/GameRules/Domain/Entities/Cards/Card.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using ModestTree;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
Expand All @@ -17,6 +16,7 @@ public class Card
[Inject] protected readonly ReactionablesProvider _reactionablesProvider;
[Inject] private readonly BuffsProvider _buffsProvider;
[Inject] private readonly GameActionsProvider _gameActionsProvider;
[Inject] private readonly ChaptersProvider _chaptersProvider;
private readonly List<Stat> _stats = new();
private readonly List<State> _states = new();
private readonly List<Activation> _baseActivations = new();
Expand Down Expand Up @@ -54,6 +54,7 @@ public class Card
private void Init()
{
OwnZone = _zonesProvider.Create(ZoneType.Own);
_zonesProvider.OutZone.AddCard(this);
FaceDown = CreateState(false);
Exausted = CreateState(false);
Blancked = CreateState(false, BlankState);
Expand Down
3 changes: 1 addition & 2 deletions Assets/SRC/GameRules/Domain/Entities/Scenes/Scene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract class Scene
public Zone PlotZone { get; private set; }
public Zone VictoryZone { get; private set; }
public Zone LimboZone { get; private set; }
public Zone OutZone { get; private set; }
public Zone OutZone => _zonesProvider.OutZone;
public Zone[,] PlaceZone { get; } = new Zone[3, 7];
public CardPlot CurrentPlot => PlotZone.Cards.LastOrDefault() as CardPlot;
public CardGoal CurrentGoal => GoalZone.Cards.LastOrDefault() as CardGoal;
Expand Down Expand Up @@ -54,7 +54,6 @@ private void Init()
PlotZone = _zonesProvider.Create(ZoneType.Plot);
VictoryZone = _zonesProvider.Create(ZoneType.Victory);
LimboZone = _zonesProvider.Create(ZoneType.Limbo);
OutZone = _zonesProvider.Create(ZoneType.Out);
PileAmount = new Stat(int.MaxValue, canBeNegative: false);
InitializePlaceZones();
PrepareDefaultChallengeTokens();
Expand Down
14 changes: 12 additions & 2 deletions Assets/SRC/GameRules/Providers/ZonesProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Zenject;

Expand All @@ -7,9 +8,18 @@ namespace MythosAndHorrors.GameRules
public class ZonesProvider
{
[Inject] private readonly DiContainer _diContainer;
[Inject] private readonly ChaptersProvider _chaptersProvider;
private readonly List<Zone> _zones = new();

public Zone OutZone { get; private set; }

/*******************************************************************/
[Inject]
[SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "Injected by Zenject")]
private void Init()
{
OutZone = Create(ZoneType.Out);
}

/*******************************************************************/
public Zone Create(ZoneType zoneType)
{
Expand All @@ -19,7 +29,7 @@ public Zone Create(ZoneType zoneType)
}
/*******************************************************************/

public Zone GetZoneWithThisCard(Card card) => _zones.Find(zone => zone.Cards.Contains(card));
public Zone GetZoneWithThisCard(Card card) => _zones.First(zone => zone.Cards.Contains(card));

}
}
4 changes: 1 addition & 3 deletions Assets/SRC/GameView/Components/CardViewGeneratorComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public class CardViewGeneratorComponent : MonoBehaviour
public CardView BuildCardView(Card card)
{
CardView newCardview = _diContainer.InstantiatePrefabForComponent<CardView>(GetPrefab(card), transform);
newCardview.Init(card);
newCardview.Off();
newCardview.SetInitialCurrentZoneView(_zoneViewManager.OutZone);
newCardview.Init(card, _zoneViewManager.OutZone);
_cardViewsManager.AddCardView(newCardview);
return newCardview;
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/SRC/GameView/Components/InitializerComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace MythosAndHorrors.GameView
public class InitializerComponent : MonoBehaviour
{
[InjectOptional] private readonly bool _executedByTests = true;
[Inject] private readonly PrepareGameUseCase _prepareGameUseCase;
[Inject] private readonly PrepareAllUseCase _prepareGameUseCase;
[Inject] private readonly GameActionsProvider _gameActionsProvider;
[Inject] private readonly IOActivatorComponent _ioActivatorComponent;
[Inject] private readonly MainButtonComponent _mainButtonComponent;
Expand Down
8 changes: 5 additions & 3 deletions Assets/SRC/GameView/Managers/AreaInvestigatorViewsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ namespace MythosAndHorrors.GameView
public class AreaInvestigatorViewsManager
{
[Inject] private readonly List<AreaInvestigatorView> _allAreaInvestigatorViews;
[Inject] private readonly InvestigatorsProvider _investigatorsProvider;

/*******************************************************************/
public void Init(IEnumerable<Investigator> investigators)
public void Init()
{
investigators.ForEach(investigator =>
_allAreaInvestigatorViews.OrderBy(areaInvestigatorView => areaInvestigatorView.name).First(area => area.IsFree).Init(investigator));
_investigatorsProvider.AllInvestigators.ForEach(investigator =>
_allAreaInvestigatorViews.OrderBy(areaInvestigatorView => areaInvestigatorView.name).
First(area => area.IsFree).Init(investigator));
}

/*******************************************************************/
Expand Down
17 changes: 17 additions & 0 deletions Assets/SRC/GameView/UseCases/Loaders/AvatarViewLoaderUseCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using MythosAndHorrors.GameRules;
using Zenject;

namespace MythosAndHorrors.GameView
{
public class AvatarViewLoaderUseCase
{
[Inject] private readonly AvatarViewsManager _avatarViewsManager;
[Inject] private readonly InvestigatorsProvider _investigatorsProvider;

/*******************************************************************/
public void Execute()
{
_investigatorsProvider.AllInvestigators.ForEach(investigator => _avatarViewsManager.GetVoid().Init(investigator));
}
}
}

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
Expand Up @@ -10,7 +10,6 @@ public class InvestigatorLoaderUseCase
[Inject] private readonly JsonService _jsonService;
[Inject] private readonly DataSaveUseCase _saveDataLoaderUseCase;
[Inject] private readonly InvestigatorsProvider _investigatorsProvider;
[Inject] private readonly AvatarViewsManager _avatarViewsManager;

/*******************************************************************/
public void Execute()
Expand All @@ -21,7 +20,6 @@ public void Execute()

_diContainer.Inject(newInvestigator);
_investigatorsProvider.AddInvestigator(newInvestigator);
_avatarViewsManager.GetVoid().Init(newInvestigator);
}
}
}
Expand Down
26 changes: 15 additions & 11 deletions Assets/SRC/GameView/UseCases/Loaders/SceneLoaderUseCase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using MythosAndHorrors.GameRules;
using System;
using System.Collections.Generic;
using System.Reflection;
using Zenject;

Expand All @@ -14,27 +13,32 @@ public class SceneLoaderUseCase
[Inject] private readonly DataSaveUseCase _saveDataLoaderUseCase;
[Inject] private readonly ChaptersProvider _chaptersProvider;
[Inject] private readonly ChallengeTokensProvider _challengeTokensProvider;
[Inject] private readonly CardsProvider _cardsProvider;

/*******************************************************************/
public void Execute()
{
SceneInfo sceneInfo = _jsonService.CreateDataFromFile<SceneInfo>(_filesPath.JSON_SCENE_PATH(_saveDataLoaderUseCase.DataSave.SceneSelected));
Type type = (Assembly.GetAssembly(typeof(Scene)).GetType(typeof(Scene) + sceneInfo.Code)
?? throw new InvalidOperationException("Scene not found" + sceneInfo.Code));
Scene currentScene = _diContainer.Instantiate(type, new object[] { sceneInfo }) as Scene;
Scene currentScene = (Scene)_diContainer.Instantiate(type, new object[] { sceneInfo });
_chaptersProvider.SetCurrentScene(currentScene);
List<ChallengeTokenType> challengeTokens = CreateTokens(sceneInfo);
_challengeTokensProvider.CreateTokens(challengeTokens);
CreateTokens(sceneInfo);
}

private List<ChallengeTokenType> CreateTokens(SceneInfo sceneInfo) => _chaptersProvider.CurrentDificulty switch
private void CreateTokens(SceneInfo sceneInfo)
{
Dificulty.Easy => sceneInfo.ChallengeTokensEasy,
Dificulty.Normal => sceneInfo.ChallengeTokensNormal,
Dificulty.Hard => sceneInfo.ChallengeTokensHard,
Dificulty.Expert => sceneInfo.ChallengeTokensExpert,
_ => throw new InvalidOperationException("Dificulty not found"),
};
var challengeTokens = _chaptersProvider.CurrentDificulty switch
{
Dificulty.Easy => sceneInfo.ChallengeTokensEasy,
Dificulty.Normal => sceneInfo.ChallengeTokensNormal,
Dificulty.Hard => sceneInfo.ChallengeTokensHard,
Dificulty.Expert => sceneInfo.ChallengeTokensExpert,
_ => throw new InvalidOperationException("Dificulty not found"),
};

_challengeTokensProvider.CreateTokens(challengeTokens);
}

}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
using MythosAndHorrors.GameRules;
using Zenject;
using Zenject;

namespace MythosAndHorrors.GameView
{
public class ZoneLoaderUseCase
public class ZoneViewLoaderUseCase
{
[Inject] private readonly InvestigatorsProvider _investigatorsProvider;
[Inject] private readonly AreaInvestigatorViewsManager _areaInvestigatorViewsManager;
[Inject] private readonly AreaSceneView _sceneArea;
[Inject] private readonly AreaPlacesView _placesArea;

/*******************************************************************/
public void Execute()
{
_areaInvestigatorViewsManager.Init(_investigatorsProvider.AllInvestigators);
_areaInvestigatorViewsManager.Init();
_sceneArea.Init();
_placesArea.Init();
}
Expand Down
11 changes: 11 additions & 0 deletions Assets/SRC/GameView/UseCases/Loaders/ZoneViewLoaderUseCase.cs.meta

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

17 changes: 17 additions & 0 deletions Assets/SRC/GameView/UseCases/PrepareAllUseCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Zenject;

namespace MythosAndHorrors.GameView
{
public class PrepareAllUseCase
{
[Inject] private readonly PrepareGameRulesUseCase _loadGameRulesUseCase;
[Inject] private readonly PrepareGameViewUseCase _loadGameViewUseCase;

/*******************************************************************/
public void Execute()
{
_loadGameRulesUseCase.Execute();
_loadGameViewUseCase.Execute();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
using Zenject;
using Zenject;

namespace MythosAndHorrors.GameView
{
public class PrepareGameUseCase
public class PrepareGameRulesUseCase
{
[Inject] private readonly DataSaveUseCase _dataSaveLoaderUseCase;
[Inject] private readonly TextsLoaderUseCase _textsLoaderUseCase;
[Inject] private readonly InvestigatorLoaderUseCase _investigatorLoaderUseCase;
[Inject] private readonly ChapterInfoLoaderUseCase _chapterInfoLoaderUseCase;
[Inject] private readonly SceneLoaderUseCase _sceneLoaderUseCase;
[Inject] private readonly ZoneLoaderUseCase _zoneLoaderUseCase;
[Inject] private readonly CardViewGeneratorComponent _cardGeneratorComponent;
[Inject] private readonly InvestigatorLoaderUseCase _investigatorLoaderUseCase;

/*******************************************************************/
public void Execute()
{
_dataSaveLoaderUseCase.Load();
_textsLoaderUseCase.LoadGameTexts();
_textsLoaderUseCase.LoadViewTexts();
_investigatorLoaderUseCase.Execute();
_chapterInfoLoaderUseCase.Execute();
_sceneLoaderUseCase.Execute();
_zoneLoaderUseCase.Execute();
_cardGeneratorComponent.BuildAllCardViews();
}
}
}
11 changes: 11 additions & 0 deletions Assets/SRC/GameView/UseCases/PrepareGameRulesUseCase.cs.meta

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

22 changes: 22 additions & 0 deletions Assets/SRC/GameView/UseCases/PrepareGameViewUseCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Zenject;

namespace MythosAndHorrors.GameView
{
public class PrepareGameViewUseCase
{
[Inject] private readonly TextsLoaderUseCase _textsLoaderUseCase;
[Inject] private readonly AvatarViewLoaderUseCase _avatarLoaderUseCase;
[Inject] private readonly ZoneViewLoaderUseCase _zoneLoaderUseCase;
[Inject] private readonly CardViewGeneratorComponent _cardGeneratorComponent;

/*******************************************************************/
public void Execute()
{
_textsLoaderUseCase.LoadGameTexts();
_textsLoaderUseCase.LoadViewTexts();
_avatarLoaderUseCase.Execute();
_zoneLoaderUseCase.Execute();
_cardGeneratorComponent.BuildAllCardViews();
}
}
}
11 changes: 11 additions & 0 deletions Assets/SRC/GameView/UseCases/PrepareGameViewUseCase.cs.meta

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

7 changes: 4 additions & 3 deletions Assets/SRC/GameView/Views/Cards/CardView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@ public abstract class CardView : MonoBehaviour, IPlayable
public IEnumerable<Effect> EffectsSelected => _cloneEffect != null ? new[] { _cloneEffect } : Card.PlayableEffects;

/*******************************************************************/
public void Init(Card card)
public void Init(Card card, ZoneView currentZoneView)
{
Card = card;
SetPicture();
SetCommon();
SetSpecific();
SetInitialCurrentZoneView(currentZoneView);
Off();
}

/*******************************************************************/
public void SetInitialCurrentZoneView(ZoneView zoneView)
private void SetInitialCurrentZoneView(ZoneView zoneView)
{
zoneView.Zone.AddCard(Card);
CurrentZoneView = zoneView;
transform.SetParent(zoneView.transform);
}
Expand Down
41 changes: 41 additions & 0 deletions Assets/SRC/Tests.EditMode/Injection/InjectionServiceToTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using MythosAndHorrors.GameRules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Zenject;

namespace MythosAndHorrors.EditMode.Tests
{
public class InjectionServiceToTest : Installer
{
public override void InstallBindings()
{
//Container.Bind<PrepareGameToTest>().AsSingle();
BindAllFakePresenters();
}

private void BindAllFakePresenters()
{
IEnumerable<Type> gameActionTypes = typeof(GameAction).Assembly.GetTypes()
.Where(type => type.IsClass && type.BaseType == typeof(GameAction));

foreach (Type type in gameActionTypes)
{
BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance;
FieldInfo[] campos = type.GetFields(flags);

foreach (FieldInfo campo in campos)
{
if (campo.FieldType.IsGenericType &&
campo.FieldType.GetGenericTypeDefinition() == typeof(IPresenter<>) && campo.FieldType.GetGenericArguments()[0] == type)
{
Type genericToBind = typeof(FakeMoveCardsGamePresenter<>).MakeGenericType(type);
Container.Unbind(campo.FieldType);
Container.Bind(campo.FieldType).To(genericToBind).AsCached();
}
}
}
}
}
}
Loading

0 comments on commit e8cf056

Please sign in to comment.