Skip to content
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
11 changes: 11 additions & 0 deletions Open5ETools.slnx
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<Solution>
<Configurations>
<Platform Name="Any CPU" />
<Platform Name="x64" />
<Platform Name="x86" />
</Configurations>
<Folder Name="/Docker/">
<File Path="Docker/configure-db.sh" />
<File Path="Docker/Dockerfile" />
<File Path="Docker/entrypoint.sh" />
<File Path="Docker/setup.sql" />
</Folder>
<Folder Name="/Solution Items/">
<File Path=".gitignore" />
<File Path=".github/workflows/main.yml" />
Expand Down
6 changes: 2 additions & 4 deletions src/Open5ETools.Core/Common/Configurations/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ namespace Open5ETools.Core.Common.Configurations;
public class AppConfigOptions
{
public const string AppConfig = "Config";
[Required]
public string DefaultAdminPassword { get; set; } = string.Empty;
[Required]
public string DefaultUserPassword { get; set; } = string.Empty;
[Required] public required string DefaultAdminPassword { get; set; }
[Required] public required string DefaultUserPassword { get; set; }
}
25 changes: 12 additions & 13 deletions src/Open5ETools.Core/Common/Helpers/DungeonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DungeonHelper(IAppDbContext context) : IDungeonHelper
private readonly IAppDbContext _context = context;

// encounter
private IList<Models.Json.Monster> _filteredMonsters = [];
private List<Models.Json.Monster> _filteredMonsters = [];
private int _sumXp;

private readonly int[] _difficulty =
Expand All @@ -31,20 +31,19 @@ public class DungeonHelper(IAppDbContext context) : IDungeonHelper

// door
private DungeonTile[][] DungeonTiles { get; set; } = [];
private ICollection<DungeonTile> DoorList { get; set; } = [];
private List<DungeonTile> DoorList { get; set; } = [];
private int _westCount;
private int _southCount;
private int _eastCount;
private int _northCount;

private IList<TreasureDescription> TreasureList { get; set; } = [];
private IList<Models.Json.Monster> _monsterList = [];
private List<TreasureDescription> TreasureList { get; set; } = [];

private IList<Models.Json.Monster> MonsterList
private List<Models.Json.Monster> MonsterList
{
get => _monsterList;
set => _monsterList = GetMonsters(value); // get monsters for party level
}
get;
set => field = GetMonsters(value); // get monsters for party level
} = [];

private int PartyLevel { get; set; }
private int PartySize { get; set; }
Expand Down Expand Up @@ -85,7 +84,7 @@ public static int GetRandomInt(int min, int max)
}

public void AddRoomDescription(DungeonTile[][] dungeonTiles, int x, int y,
ICollection<RoomDescription> roomDescription, ICollection<DungeonTile> currentDoors)
List<RoomDescription> roomDescription, List<DungeonTile> currentDoors)
{
dungeonTiles[x][y].Index = roomDescription.Count;
DungeonTiles = dungeonTiles;
Expand All @@ -98,7 +97,7 @@ public void AddRoomDescription(DungeonTile[][] dungeonTiles, int x, int y,
dungeonTiles[x][y].Description = Convert.ToString(roomDescription.Count);
}

public void AddTrapDescription(DungeonTile dungeonTile, ICollection<TrapDescription> trapDescription)
public void AddTrapDescription(DungeonTile dungeonTile, List<TrapDescription> trapDescription)
{
dungeonTile.Index = trapDescription.Count;
trapDescription.Add(new TrapDescription(
Expand All @@ -108,7 +107,7 @@ public void AddTrapDescription(DungeonTile dungeonTile, ICollection<TrapDescript
}

public void AddRoamingMonsterDescription(DungeonTile dungeonTile,
ICollection<RoamingMonsterDescription> roamingMonsterDescription)
List<RoamingMonsterDescription> roamingMonsterDescription)
{
dungeonTile.Index = roamingMonsterDescription.Count;
roamingMonsterDescription.Add(new RoamingMonsterDescription(
Expand All @@ -127,7 +126,7 @@ private static string GetRoomName(int x)
return "#ROOM" + x + "#";
}

public void AddNcRoomDescription(DungeonTile dungeonTile, ICollection<RoomDescription> roomDescription,
public void AddNcRoomDescription(DungeonTile dungeonTile, List<RoomDescription> roomDescription,
string doors)
{
dungeonTile.Index = roomDescription.Count;
Expand Down Expand Up @@ -480,7 +479,7 @@ public bool CheckNcDoor(DungeonTile dungeonTile)
or Texture.NoCorridorDoorTrapped;
}

public string GetNcDoorDescription(DungeonTile[][] dungeonTiles, IEnumerable<DungeonTile> closedList)
public string GetNcDoorDescription(DungeonTile[][] dungeonTiles, List<DungeonTile> closedList)
{
_westCount = 1;
_southCount = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Open5ETools.Core.Common.Interfaces.Services.DM.Generator;
public interface IDungeon
{
DungeonTile[][] DungeonTiles { get; set; }
ICollection<RoomDescription> RoomDescription { get; set; }
List<RoomDescription> RoomDescription { get; set; }
DungeonModel Generate(DungeonOptionModel model);
void AddEntryPoint();
void Init(DungeonOptionModel optionModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ namespace Open5ETools.Core.Common.Interfaces.Services.DM.Generator;

public interface IDungeonHelper
{
void AddRoomDescription(DungeonTile[][] dungeonTiles, int x, int y, ICollection<RoomDescription> roomDescription, ICollection<DungeonTile> currentDoors);
void AddTrapDescription(DungeonTile dungeonTile, ICollection<TrapDescription> trapDescription);
void AddRoamingMonsterDescription(DungeonTile dungeonTile, ICollection<RoamingMonsterDescription> roamingMonsterDescription);
void AddRoomDescription(DungeonTile[][] dungeonTiles, int x, int y, List<RoomDescription> roomDescription, List<DungeonTile> currentDoors);
void AddTrapDescription(DungeonTile dungeonTile, List<TrapDescription> trapDescription);
void AddRoamingMonsterDescription(DungeonTile dungeonTile, List<RoamingMonsterDescription> roamingMonsterDescription);
int Manhattan(int dx, int dy);
void AddNcRoomDescription(DungeonTile dungeonTile, ICollection<RoomDescription> roomDescription, string doors);
void AddNcRoomDescription(DungeonTile dungeonTile, List<RoomDescription> roomDescription, string doors);
void Init(DungeonOptionModel model);
bool CheckNcDoor(DungeonTile dungeonTile);
string GetNcDoorDescription(DungeonTile[][] dungeonTiles, IEnumerable<DungeonTile> closedList);
string GetNcDoorDescription(DungeonTile[][] dungeonTiles, List<DungeonTile> closedList);
string GetNcDoor(DungeonTile door);
string GetTreasure();
string GetMonsterDescription();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Open5ETools.Core.Common.Interfaces.Services.DM.Generator;
public interface IDungeonNoCorridor
{
DungeonTile[][] DungeonTiles { get; set; }
ICollection<RoomDescription> RoomDescription { get; set; }
IList<DungeonTile> OpenDoorList { get; set; }
List<RoomDescription> RoomDescription { get; set; }
List<DungeonTile> OpenDoorList { get; set; }
DungeonModel Generate(DungeonOptionModel model);
void AddEntryPoint();
void Init(DungeonOptionModel optionModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ namespace Open5ETools.Core.Common.Interfaces.Services.DM;

public interface IDungeonService
{
Task<IEnumerable<DungeonOptionModel>> GetAllDungeonOptionsAsync(CancellationToken cancellationToken);
Task<IEnumerable<DungeonOptionModel>> GetAllDungeonOptionsForUserAsync(int userId, CancellationToken cancellationToken);
Task<DungeonOptionModel[]> GetAllDungeonOptionsAsync(CancellationToken cancellationToken);
Task<DungeonOptionModel[]> GetAllDungeonOptionsForUserAsync(int userId, CancellationToken cancellationToken);
Task<DungeonOptionModel> GetDungeonOptionAsync(int id, CancellationToken cancellationToken);
Task<DungeonOptionModel?> GetDungeonOptionByNameAsync(string dungeonName, int userId, CancellationToken cancellationToken);
Task<DungeonModel> GetDungeonAsync(int id, CancellationToken cancellationToken);
Task<DungeonModel> CreateOrUpdateDungeonAsync(DungeonOptionModel optionModel, bool addDungeon, int level, CancellationToken cancellationToken);
Task UpdateDungeonAsync(DungeonModel model, CancellationToken cancellationToken);
Task<int> CreateDungeonOptionAsync(DungeonOptionModel dungeonOption, CancellationToken cancellationToken);
Task<IEnumerable<DungeonModel>> ListUserDungeonsAsync(int userId, CancellationToken cancellationToken);
Task<IEnumerable<DungeonModel>> ListUserDungeonsByNameAsync(string dungeonName, int userId, CancellationToken cancellationToken);
Task<DungeonModel[]> ListUserDungeonsAsync(int userId, CancellationToken cancellationToken);
Task<DungeonModel[]> ListUserDungeonsByNameAsync(string dungeonName, int userId, CancellationToken cancellationToken);
Task<int> AddDungeonAsync(DungeonModel savedDungeon, CancellationToken cancellationToken);
Task<bool> DeleteDungeonOptionAsync(int id, CancellationToken cancellationToken);
Task<bool> DeleteDungeonAsync(int id, CancellationToken cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ namespace Open5ETools.Core.Common.Interfaces.Services.DM;

public interface IOptionService
{
Task<IEnumerable<OptionModel>> ListOptionsAsync(OptionKey? filter = null, CancellationToken cancellationToken = default);
Task<OptionModel[]> ListOptionsAsync(OptionKey? filter = null, CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace Open5ETools.Core.Common.Interfaces.Services;

public interface IAuthService
{
Task<UserModel?> LoginAsync(UserModel model, CancellationToken cancellationToken);
Task<UserModel?> LoginAsync(UserModel model, CancellationToken cancellationToken = default);
}
14 changes: 7 additions & 7 deletions src/Open5ETools.Core/Common/Interfaces/Services/IUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ namespace Open5ETools.Core.Common.Interfaces.Services;

public interface IUserService
{
Task<UserModel> GetAsync(int id, CancellationToken cancellationToken);
Task UpdateAsync(UserModel model, CancellationToken cancellationToken);
Task<int> CreateAsync(UserModel model, CancellationToken cancellationToken);
Task<IEnumerable<UserModel>> ListAsync(bool? deleted = false, CancellationToken cancellationToken = default);
Task<bool> DeleteAsync(int id, CancellationToken cancellationToken);
Task<bool> RestoreAsync(int id, CancellationToken cancellationToken);
Task ChangePasswordAsync(ChangePasswordModel model, CancellationToken cancellationToken);
Task<UserModel> GetAsync(int id, CancellationToken cancellationToken = default);
Task UpdateAsync(UserModel model, CancellationToken cancellationToken = default);
Task<int> CreateAsync(UserModel model, CancellationToken cancellationToken = default);
Task<UserModel[]> ListAsync(bool? deleted = false, CancellationToken cancellationToken = default);
Task<bool> DeleteAsync(int id, CancellationToken cancellationToken = default);
Task<bool> RestoreAsync(int id, CancellationToken cancellationToken = default);
Task ChangePasswordAsync(ChangePasswordModel model, CancellationToken cancellationToken = default);
}
76 changes: 38 additions & 38 deletions src/Open5ETools.Core/ConfigureServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,49 @@ namespace Open5ETools.Core;

public static class ConfigureServices
{
public static IServiceCollection AddApplicationServices(
this IServiceCollection services
)
extension(IServiceCollection services)
{
services
.AddScoped<IUserService, UserService>()
.AddScoped<IAuthService, AuthService>()
.AddScoped<IEncounterService, EncounterService>()
.AddScoped<IDungeonHelper, DungeonHelper>()
.AddScoped<IOptionService, OptionService>()
.AddScoped<IDungeon, Dungeon>()
.AddScoped<IDungeonNoCorridor, DungeonNoCorridor>()
.AddScoped<IDungeonService, DungeonService>()
.AddScoped<ISpellService, SpellService>();

services.ConfigureMapster();
return services;
}
public IServiceCollection AddApplicationServices()
{
services
.AddScoped<IUserService, UserService>()
.AddScoped<IAuthService, AuthService>()
.AddScoped<IEncounterService, EncounterService>()
.AddScoped<IDungeonHelper, DungeonHelper>()
.AddScoped<IOptionService, OptionService>()
.AddScoped<IDungeon, Dungeon>()
.AddScoped<IDungeonNoCorridor, DungeonNoCorridor>()
.AddScoped<IDungeonService, DungeonService>()
.AddScoped<ISpellService, SpellService>();

services.ConfigureMapster();
return services;
}

private static IServiceCollection ConfigureMapster(this IServiceCollection services)
{
services.AddMapster();
TypeAdapterConfig<Spell, Open5ETools.Core.Domain.SM.Spell>
.NewConfig()
.Map(dest => dest.Concentration,
src => string.IsNullOrWhiteSpace(src.Concentration) ||
!src.Concentration.Equals("no", StringComparison.InvariantCultureIgnoreCase))
.Map(dest => dest.Ritual,
src => string.IsNullOrWhiteSpace(src.Ritual) ||
!src.Ritual.Equals("no", StringComparison.InvariantCultureIgnoreCase))
.Map(dest => dest.School,
src => Enum.Parse<School>(src.School ?? string.Empty));
private IServiceCollection ConfigureMapster()
{
services.AddMapster();
TypeAdapterConfig<Spell, Open5ETools.Core.Domain.SM.Spell>
.NewConfig()
.Map(dest => dest.Concentration,
src => string.IsNullOrWhiteSpace(src.Concentration) ||
!src.Concentration.Equals("no", StringComparison.InvariantCultureIgnoreCase))
.Map(dest => dest.Ritual,
src => string.IsNullOrWhiteSpace(src.Ritual) ||
!src.Ritual.Equals("no", StringComparison.InvariantCultureIgnoreCase))
.Map(dest => dest.School,
src => Enum.Parse<School>(src.School ?? string.Empty));

TypeAdapterConfig<Monster, JsonMonsterModel>
.NewConfig()
.Map(dest => dest.Hp, src => src.HitPoints)
.Map(dest => dest.Ac, src => src.ArmorClass);
TypeAdapterConfig<Monster, JsonMonsterModel>
.NewConfig()
.Map(dest => dest.Hp, src => src.HitPoints)
.Map(dest => dest.Ac, src => src.ArmorClass);

TypeAdapterConfig<Open5ETools.Core.Domain.EG.Monster, MonsterModel>
.NewConfig()
.Map(dest => dest.JsonMonsterModel, src => src.JsonMonster);
TypeAdapterConfig<Open5ETools.Core.Domain.EG.Monster, MonsterModel>
.NewConfig()
.Map(dest => dest.JsonMonsterModel, src => src.JsonMonster);

return services;
return services;
}
}
}
2 changes: 1 addition & 1 deletion src/Open5ETools.Core/Services/AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class AuthService(IMapper mapper, IAppDbContext context, ILogger<AuthServ
private readonly IMapper _mapper = mapper;
private readonly ILogger _logger = logger;

public async Task<UserModel?> LoginAsync(UserModel model, CancellationToken cancellationToken)
public async Task<UserModel?> LoginAsync(UserModel model, CancellationToken cancellationToken = default)
{
try
{
Expand Down
24 changes: 12 additions & 12 deletions src/Open5ETools.Core/Services/DM/DungeonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,17 @@ public async Task<DungeonModel> GenerateDungeonAsync(DungeonOptionModel model)
}
}

public async Task<IEnumerable<DungeonOptionModel>> GetAllDungeonOptionsAsync(CancellationToken cancellationToken)
public async Task<DungeonOptionModel[]> GetAllDungeonOptionsAsync(CancellationToken cancellationToken)
{
try
{
var options = await _context.DungeonOptions
.Include(d => d.Dungeons)
.AsNoTracking()
.OrderBy(d => d.Created)
.ToListAsync(cancellationToken);
.ToArrayAsync(cancellationToken);

return options.Select(_mapper.Map<DungeonOptionModel>);
return [.. options.Select(_mapper.Map<DungeonOptionModel>)];
}
catch (Exception ex)
{
Expand All @@ -192,7 +192,7 @@ public async Task<IEnumerable<DungeonOptionModel>> GetAllDungeonOptionsAsync(Can
}
}

public async Task<IEnumerable<DungeonOptionModel>> GetAllDungeonOptionsForUserAsync(int userId,
public async Task<DungeonOptionModel[]> GetAllDungeonOptionsForUserAsync(int userId,
CancellationToken cancellationToken)
{
try
Expand All @@ -202,9 +202,9 @@ public async Task<IEnumerable<DungeonOptionModel>> GetAllDungeonOptionsForUserAs
.Include(d => d.Dungeons)
.Where(d => d.UserId == userId)
.OrderBy(d => d.Created)
.ToListAsync(cancellationToken);
.ToArrayAsync(cancellationToken);

return options.Select(_mapper.Map<DungeonOptionModel>);
return [.. options.Select(_mapper.Map<DungeonOptionModel>)];
}
catch (Exception ex)
{
Expand Down Expand Up @@ -296,7 +296,7 @@ private async Task DeleteDungeonOptionIfNeededAsync(int dungeonOptionId, Cancell
}
}

public async Task<IEnumerable<DungeonModel>> ListUserDungeonsAsync(int userId, CancellationToken cancellationToken)
public async Task<DungeonModel[]> ListUserDungeonsAsync(int userId, CancellationToken cancellationToken)
{
try
{
Expand All @@ -306,8 +306,8 @@ public async Task<IEnumerable<DungeonModel>> ListUserDungeonsAsync(int userId, C
.Where(d => d.UserId == userId)
.OrderBy(d => d.Created)
.SelectMany(d => d.Dungeons)
.ToListAsync(cancellationToken);
return result.Select(_mapper.Map<DungeonModel>);
.ToArrayAsync(cancellationToken);
return [.. result.Select(_mapper.Map<DungeonModel>)];
}
catch (Exception ex)
{
Expand All @@ -316,7 +316,7 @@ public async Task<IEnumerable<DungeonModel>> ListUserDungeonsAsync(int userId, C
}
}

public async Task<IEnumerable<DungeonModel>> ListUserDungeonsByNameAsync(string dungeonName, int userId,
public async Task<DungeonModel[]> ListUserDungeonsByNameAsync(string dungeonName, int userId,
CancellationToken cancellationToken)
{
try
Expand All @@ -327,8 +327,8 @@ public async Task<IEnumerable<DungeonModel>> ListUserDungeonsByNameAsync(string
.Where(d => d.DungeonName.Equals(dungeonName) && d.UserId == userId)
.OrderBy(d => d.Created)
.SelectMany(d => d.Dungeons)
.ToListAsync(cancellationToken);
return result.Select(_mapper.Map<DungeonModel>);
.ToArrayAsync(cancellationToken);
return [.. result.Select(_mapper.Map<DungeonModel>)];
}
catch (Exception ex)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Open5ETools.Core/Services/DM/Generator/Dungeon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class Dungeon(IDungeonHelper dungeonHelper) : IDungeon
private const int Movement = 10;
internal readonly List<DungeonTile> Rooms = [];
internal List<DungeonTile> Doors = [];
public ICollection<RoomDescription> RoomDescription { get; set; } = [];
private ICollection<TrapDescription> TrapDescription { get; set; } = [];
private ICollection<RoamingMonsterDescription> RoamingMonsterDescription { get; set; } = [];
public List<RoomDescription> RoomDescription { get; set; } = [];
private List<TrapDescription> TrapDescription { get; set; } = [];
private List<RoamingMonsterDescription> RoamingMonsterDescription { get; set; } = [];
public DungeonTile[][] DungeonTiles { get; set; } = [];
private List<DungeonTile> _result = [];
private List<DungeonTile> _corridors = [];
Expand Down
Loading