Skip to content

Commit

Permalink
Remove Room.Theme Theme from RoomConfig. Dev must use ThemeName inste…
Browse files Browse the repository at this point in the history
…ad. Add IsCustomTheme flag. Combine GetCustomRoomTheme and GetVanillaRoomTheme functions.
  • Loading branch information
jneb802 authored and probablykory committed Sep 21, 2024
1 parent ec54671 commit 74212f5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
29 changes: 18 additions & 11 deletions JotunnLib/Configs/RoomConfig.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Jotunn.Entities;

namespace Jotunn.Configs
Expand All @@ -12,11 +13,11 @@ public class RoomConfig
/// Theme name of this room.
/// </summary>
public string ThemeName { get; set; }

/// <summary>
/// <see cref="Room.Theme"/> of this room.
/// Flag indicated if this room uses a custom theme
/// </summary>
public Room.Theme Theme { get; set; }
public bool IsCustomTheme { get; set; }

/// <summary>
/// If set to false, room will not be added to <see cref="DungeonGenerator.m_availableRooms"/>, thus
Expand Down Expand Up @@ -70,7 +71,6 @@ public class RoomConfig
/// <param name="theme"></param>
public RoomConfig(Room.Theme theme)
{
Theme = theme;
ThemeName = string.Empty;
}

Expand All @@ -80,7 +80,6 @@ public RoomConfig(Room.Theme theme)
/// <param name="themeName"></param>
public RoomConfig(string themeName)
{
Theme = 0;
ThemeName = themeName;
}

Expand Down Expand Up @@ -109,19 +108,27 @@ public Room ApplyConfig(RoomConfig roomConfig)
if (roomConfig.FaceCenter != null) room.m_faceCenter = roomConfig.FaceCenter.Value;
if (roomConfig.Perimeter != null) room.m_perimeter = roomConfig.Perimeter.Value;

// Room can be matched by either a Room.Theme flag, or a ThemeName string.
if (roomConfig.Theme == 0)
if (roomConfig.IsCustomTheme)
{
ThemeName = roomConfig.ThemeName;
Theme = 0;
if (roomConfig.ThemeName != null) room.m_theme = GetRoomTheme(roomConfig.ThemeName);
}
else
{
Theme = roomConfig.Theme;
ThemeName = string.Empty;
if (roomConfig.ThemeName != null) room.m_theme = GetRoomTheme(roomConfig.ThemeName);
}

return room;
}

public Room.Theme GetRoomTheme(string roomTheme)
{
if (Enum.TryParse(roomTheme, false, out Room.Theme theme))
{
Logger.LogDebug($"Found Room Theme with name {roomTheme}");
return theme;
}
Logger.LogError($"Failed to find Room Theme with name {roomTheme}");
return Room.Theme.None;
}
}
}
21 changes: 5 additions & 16 deletions JotunnLib/Entities/CustomRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public CustomRoom(AssetBundle assetBundle, string assetName, bool fixReference,
m_prefab = new SoftReference<GameObject>(AssetManager.Instance.AddAsset(Prefab)),
m_loadedRoom = Room,
m_enabled = Room.m_enabled,
m_theme = GetCustomRoomTheme(roomConfig.ThemeName)
m_theme = GetRoomTheme(roomConfig.ThemeName)
};
}

Expand Down Expand Up @@ -146,7 +146,7 @@ public CustomRoom(GameObject prefab, bool fixReference, RoomConfig roomConfig) :
m_prefab = new SoftReference<GameObject>(AssetManager.Instance.AddAsset(Prefab)),
m_loadedRoom = Room,
m_enabled = Room.m_enabled,
m_theme = GetCustomRoomTheme(roomConfig.ThemeName)
m_theme = GetRoomTheme(roomConfig.ThemeName)
};
}

Expand All @@ -160,25 +160,14 @@ public static bool IsCustomRoom(string prefabName)
return DungeonManager.Instance.Rooms.ContainsKey(prefabName);
}

public Room.Theme GetVanillaRoomTheme(string roomTheme)
public Room.Theme GetRoomTheme(string roomTheme)
{
if (Enum.TryParse(roomTheme, false, out Room.Theme theme))
{
Logger.LogDebug($"Found vanilla Room Theme with name {roomTheme}");
Logger.LogDebug($"Found Room Theme with name {roomTheme}");
return theme;
}
Logger.LogError($"Failed to find vanilla Room Theme with name {roomTheme}");
return Room.Theme.None;
}

public Room.Theme GetCustomRoomTheme(string roomTheme)
{
if (Enum.TryParse(roomTheme, false, out Room.Theme theme))
{
Logger.LogDebug($"Found custom Room Theme with name {roomTheme}");
return theme;
}
Logger.LogError($"Failed to find custom Room Theme with name {roomTheme}");
Logger.LogError($"Failed to find Room Theme with name {roomTheme}");
return Room.Theme.None;
}

Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Managers/DungeonManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private void OnDungeonGeneratorSetupAvailableRooms(DungeonGenerator self)

DungeonGenerator.m_availableRooms.AddRange(Rooms.Values
.Where(r => r.Room.m_enabled)
.Where(r => self.m_themes.HasFlag(r.GetVanillaRoomTheme(r.ThemeName)))
.Where(r => self.m_themes.HasFlag(r.GetRoomTheme(r.ThemeName)))
.Select(r => r.RoomData));
}

Expand Down

0 comments on commit 74212f5

Please sign in to comment.