Skip to content

Commit

Permalink
extracted a game hosting component
Browse files Browse the repository at this point in the history
  • Loading branch information
lastunicorn committed Jan 15, 2024
1 parent f0500ca commit 7b7b753
Show file tree
Hide file tree
Showing 48 changed files with 893 additions and 466 deletions.
4 changes: 2 additions & 2 deletions sources/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<Authors>Dust in the Wind</Authors>
<Company>Dust in the Wind</Company>
<Copyright>Copyright © 2020 Dust in the wind</Copyright>
<Version>1.0.0.0</Version>
<Copyright>Copyright © 2020-2024 Dust in the wind</Copyright>
<Version>2.0.0.0</Version>
<Product>Dot</Product>
</PropertyGroup>

Expand Down
1 change: 1 addition & 0 deletions sources/Dot.Application/Dot.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ItemGroup>
<ProjectReference Include="..\Dot.AdventureGame\Dot.AdventureGame.csproj" PrivateAssets="All" />
<ProjectReference Include="..\Dot.Domain\Dot.Domain.csproj" PrivateAssets="All" />
<ProjectReference Include="..\Dot.GameHosting\Dot.GameHosting.csproj" PrivateAssets="All" />
<ProjectReference Include="..\Dot.Ports.SaveAccess\Dot.Ports.GameSavesAccess.csproj" PrivateAssets="All" />
</ItemGroup>

Expand Down
71 changes: 43 additions & 28 deletions sources/Dot.Application/GameHostActions/ExitAction.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,61 @@
// Dot
// Copyright (C) 2020-2024 Dust in the Wind
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Dot.GameHosting;
using DustInTheWind.Dot.AdventureGame.ActionModel;
using DustInTheWind.Dot.Domain;

namespace DustInTheWind.Dot.Application.GameHostActions
namespace DustInTheWind.Dot.Application.GameHostActions;

public class ExitAction : ActionBase
{
public class ExitAction : ActionBase
{
private readonly IGameApplication gameApplication;
private readonly IModuleHost moduleHost;

public ExitAction(IGameApplication gameApplication)
: base("exit", "quit", "x")
{
this.gameApplication = gameApplication ?? throw new ArgumentNullException(nameof(gameApplication));
}
public ExitAction(IModuleHost moduleHost)
: base("exit", "quit", "x")
{
this.moduleHost = moduleHost ?? throw new ArgumentNullException(nameof(moduleHost));
}

public override string Description => "Exits the game.";
public override string Description => "Exits the game.";

public override List<string> Usage => new List<string> { "<<:exit>>", "<<:quit>>", "<<:x>>" };
public override List<string> Usage => new() { "<<:exit>>", "<<:quit>>", "<<:x>>" };

public override ActionType ActionType => ActionType.EnvironmentCommand;
public override ActionType ActionType => ActionType.EnvironmentCommand;

protected override List<Regex> CreateMatchers()
protected override List<Regex> CreateMatchers()
{
return new List<Regex>
{
return new List<Regex>
{
new Regex(@"^\s*(:exit|:quit|:x)\s*$", RegexOptions.IgnoreCase | RegexOptions.Singleline)
};
}
new(@"^\s*(:exit|:quit|:x)\s*$", RegexOptions.IgnoreCase | RegexOptions.Singleline)
};
}

protected override string[] ExtractParameters(Match match)
{
return new string[0];
}
protected override string[] ExtractParameters(Match match)
{
return Array.Empty<string>();
}

public override IEnumerable Execute(params object[] parameters)
{
gameApplication.Close();
public override IEnumerable Execute(params object[] parameters)
{
moduleHost.Close();

yield break;
}
yield break;
}
}
71 changes: 43 additions & 28 deletions sources/Dot.Application/GameHostActions/LoadGameAction.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,62 @@
// Dot
// Copyright (C) 2020-2024 Dust in the Wind
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using DustInTheWind.Dot.AdventureGame.ActionModel;
using DustInTheWind.Dot.Application.UseCases.LoadGame;

namespace DustInTheWind.Dot.Application.GameHostActions
namespace DustInTheWind.Dot.Application.GameHostActions;

public class LoadGameAction : ActionBase
{
public class LoadGameAction : ActionBase
{
private readonly IUseCaseFactory useCaseFactory;
private readonly IUseCaseFactory useCaseFactory;

public LoadGameAction(IUseCaseFactory useCaseFactory)
: base("load")
{
this.useCaseFactory = useCaseFactory ?? throw new ArgumentNullException(nameof(useCaseFactory));
}
public LoadGameAction(IUseCaseFactory useCaseFactory)
: base("load")
{
this.useCaseFactory = useCaseFactory ?? throw new ArgumentNullException(nameof(useCaseFactory));
}

public override string Description => "Loads a previously saved game.";
public override string Description => "Loads a previously saved game.";

public override List<string> Usage => new List<string> { "<<:load>>" };
public override List<string> Usage => new() { "<<:load>>" };

public override ActionType ActionType => ActionType.EnvironmentCommand;
public override ActionType ActionType => ActionType.EnvironmentCommand;

protected override List<Regex> CreateMatchers()
protected override List<Regex> CreateMatchers()
{
return new List<Regex>
{
return new List<Regex>
{
new Regex(@"^\s*:load\s*$", RegexOptions.IgnoreCase | RegexOptions.Singleline)
};
}
new(@"^\s*:load\s*$", RegexOptions.IgnoreCase | RegexOptions.Singleline)
};
}

protected override string[] ExtractParameters(Match match)
{
return new string[0];
}
protected override string[] ExtractParameters(Match match)
{
return Array.Empty<string>();
}

public override IEnumerable Execute(params object[] parameters)
{
LoadGameUseCase useCase = useCaseFactory.Create<LoadGameUseCase>();
useCase.Execute();
public override IEnumerable Execute(params object[] parameters)
{
LoadGameUseCase useCase = useCaseFactory.Create<LoadGameUseCase>();
useCase.Execute();

yield break;
}
yield break;
}
}
71 changes: 43 additions & 28 deletions sources/Dot.Application/GameHostActions/MainMenuAction.cs
Original file line number Diff line number Diff line change
@@ -1,46 +1,61 @@
// Dot
// Copyright (C) 2020-2024 Dust in the Wind
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Dot.GameHosting;
using DustInTheWind.Dot.AdventureGame.ActionModel;
using DustInTheWind.Dot.Domain.ModuleModel;

namespace DustInTheWind.Dot.Application.GameHostActions
namespace DustInTheWind.Dot.Application.GameHostActions;

public class MainMenuAction : ActionBase
{
public class MainMenuAction : ActionBase
{
private readonly ModuleEngine moduleEngine;
private readonly ModuleEngine moduleEngine;

public MainMenuAction(ModuleEngine moduleEngine)
: base("menu", "m")
{
this.moduleEngine = moduleEngine ?? throw new ArgumentNullException(nameof(moduleEngine));
}
public MainMenuAction(ModuleEngine moduleEngine)
: base("menu", "m")
{
this.moduleEngine = moduleEngine ?? throw new ArgumentNullException(nameof(moduleEngine));
}

public override string Description => "Displays the main menu of the game.";
public override string Description => "Displays the main menu of the game.";

public override List<string> Usage => new List<string> { "<<:menu>>", "<<:m>>" };
public override List<string> Usage => new() { "<<:menu>>", "<<:m>>" };

public override ActionType ActionType => ActionType.EnvironmentCommand;
public override ActionType ActionType => ActionType.EnvironmentCommand;

protected override List<Regex> CreateMatchers()
protected override List<Regex> CreateMatchers()
{
return new List<Regex>
{
return new List<Regex>
{
new Regex(@"^\s*(:menu|:m)\s*$", RegexOptions.IgnoreCase | RegexOptions.Singleline)
};
}
new(@"^\s*(:menu|:m)\s*$", RegexOptions.IgnoreCase | RegexOptions.Singleline)
};
}

protected override string[] ExtractParameters(Match match)
{
return new string[0];
}
protected override string[] ExtractParameters(Match match)
{
return Array.Empty<string>();
}

public override IEnumerable Execute(params object[] parameters)
{
moduleEngine.RequestToChangeModule("main-menu");
public override IEnumerable Execute(params object[] parameters)
{
moduleEngine.RequestToChangeModule("main-menu");

yield break;
}
yield break;
}
}
71 changes: 43 additions & 28 deletions sources/Dot.Application/GameHostActions/NewGameAction.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,62 @@
// Dot
// Copyright (C) 2020-2024 Dust in the Wind
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using DustInTheWind.Dot.AdventureGame.ActionModel;
using DustInTheWind.Dot.Application.UseCases.NewGame;

namespace DustInTheWind.Dot.Application.GameHostActions
namespace DustInTheWind.Dot.Application.GameHostActions;

public class NewGameAction : ActionBase
{
public class NewGameAction : ActionBase
{
private readonly IUseCaseFactory useCaseFactory;
private readonly IUseCaseFactory useCaseFactory;

public NewGameAction(IUseCaseFactory useCaseFactory)
: base("new")
{
this.useCaseFactory = useCaseFactory ?? throw new ArgumentNullException(nameof(useCaseFactory));
}
public NewGameAction(IUseCaseFactory useCaseFactory)
: base("new")
{
this.useCaseFactory = useCaseFactory ?? throw new ArgumentNullException(nameof(useCaseFactory));
}

public override string Description => "Starts a new game.";
public override string Description => "Starts a new game.";

public override List<string> Usage => new List<string> { "<<:new>>" };
public override List<string> Usage => new() { "<<:new>>" };

public override ActionType ActionType => ActionType.EnvironmentCommand;
public override ActionType ActionType => ActionType.EnvironmentCommand;

protected override List<Regex> CreateMatchers()
protected override List<Regex> CreateMatchers()
{
return new List<Regex>
{
return new List<Regex>
{
new Regex(@"^\s*:new\s*$", RegexOptions.IgnoreCase | RegexOptions.Singleline)
};
}
new(@"^\s*:new\s*$", RegexOptions.IgnoreCase | RegexOptions.Singleline)
};
}

protected override string[] ExtractParameters(Match match)
{
return new string[0];
}
protected override string[] ExtractParameters(Match match)
{
return Array.Empty<string>();
}

public override IEnumerable Execute(params object[] parameters)
{
CreateNewGameUseCase useCase = useCaseFactory.Create<CreateNewGameUseCase>();
useCase.Execute();
public override IEnumerable Execute(params object[] parameters)
{
CreateNewGameUseCase useCase = useCaseFactory.Create<CreateNewGameUseCase>();
useCase.Execute();

yield break;
}
yield break;
}
}
Loading

0 comments on commit 7b7b753

Please sign in to comment.