Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DungeonManager by Kory, Warp fixes #434

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
22b24cb
feat: added PieceManager AddPieceCategory and RemovePieceCategory wit…
MSchmoecker Jun 23, 2024
69ec162
docs: updated asset creation guide dll copy instructions
MSchmoecker Jun 23, 2024
a23ddc6
docs: updated Unity version of Valheim to 2022.3.17
MSchmoecker Jun 23, 2024
866f2ab
docs: removed table param from docstring
MSchmoecker Jun 24, 2024
4e5a121
chore: simplified GUIManager asset loading
MSchmoecker Jul 13, 2024
d01542b
docs: added SynchronizationManager events to flow
MSchmoecker Jul 17, 2024
c2a56c7
fix: allow editing of new admin-only configs in the main menu
MSchmoecker Jul 17, 2024
aef1124
docs: changelog
MSchmoecker Jul 17, 2024
4031862
docs: changelog
MSchmoecker Jul 17, 2024
9215dd8
feat: added ConfigManagerUtils
MSchmoecker Jul 17, 2024
7b36835
fix: GameVersions.NetworkVersion was evaluated at compile time
MSchmoecker Jul 17, 2024
91c2183
feat: added GameVersions to the API
MSchmoecker Jul 17, 2024
3c2202f
Initial checkin of (kory) DungeonManager - kory commit
jneb802 Jul 17, 2024
e28aeb7
derp - kory commit
jneb802 Jul 17, 2024
5991d77
Fix typo in summary
jneb802 Jul 17, 2024
366b7ab
Remove MusicPrefab from RoomConfig and CustomRoom
jneb802 Jul 17, 2024
5fb11c6
Remove constructor that is missing fixReference
jneb802 Jul 17, 2024
d218a4d
Move ApplyConfig method to RoomConfig class and refactor CustomRoom c…
jneb802 Jul 17, 2024
9338dc9
Refactor DungeonManager prefab loading and instantiation
jneb802 Jul 17, 2024
611bdfd
Add OnRoomsRegistered event, invoke in InvokeOnVanillaRoomsAvailable …
jneb802 Jul 17, 2024
f515abe
Remove RegisterPrefab method. Devs should use PrefabManager.Instance.…
jneb802 Jul 17, 2024
7c88287
Add InvokeOnRoomsRegistered method. Invoke as the last statement in O…
jneb802 Jul 18, 2024
2d3bb46
Add null check for room retrieval in OnDungeonDBGetRoom method
jneb802 Jul 18, 2024
19fad19
Removing obsolete code related to adding prefabs
jneb802 Jul 18, 2024
9890548
Add doc string to OnRoomsRegistered
jneb802 Jul 18, 2024
5084fd2
Remove Room.Theme Theme. Mirror GetInternalName approach as used in P…
jneb802 Jul 18, 2024
0bc84b4
Remove OnVanillaRoomsAvailable from InvokeRoomsRegistered
jneb802 Jul 18, 2024
6f261f6
Refactor ThemeName and associated methods. ThemeName set constructor …
jneb802 Jul 18, 2024
0f39537
Remove RoomPrefabData, sub-class was removed in valheimAssembly v0.21…
jneb802 Jul 18, 2024
52951f2
Remove IsVanillaRoom function, not used
jneb802 Jul 18, 2024
7d618e6
Add constructor for RoomConfig class
jneb802 Jul 19, 2024
10b3bc2
Remove Room.Theme Theme from RoomConfig. Dev must use ThemeName inste…
jneb802 Jul 19, 2024
b2faaa2
docs: improved OnRoomsRegistered
MSchmoecker Jul 19, 2024
c0d348f
fix: always invoke OnRoomsRegistered, even if no rooms are added
MSchmoecker Jul 19, 2024
4d4ae9a
Add logging statements to OnDungeonGeneratorSetupAvailableRooms.
jneb802 Jul 20, 2024
07ec6e4
Merge branch 'dungeon_warp' of https://github.com/jneb802/Jotunn into…
jneb802 Jul 20, 2024
f554df8
Refactor of ThemeName and Room.Theme in CustomRoom, RoomConfig, and D…
jneb802 Jul 20, 2024
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## Version 2.21.0
* Added GameVersions utility to check for specific game versions
* Added ConfigManagerUtils for soft access to common ConfigurationManager functionality
* Added PieceManager.AddPieceCategory(string name) and PieceManager.RemovePieceCategory(string name)
* Deprecated PieceManager.AddPieceCategory(string table, string name) and PieceManager.RemovePieceCategory(string table, string name), use the new overloads without the table parameter
* Changed GUIManager asset loading to use the prefab cache and not hard crash on missing assets
* Fixed adding admin-only configs between loading to the main menu and before loading the game being locked for local editing
* Fixed network version in the disconnect window was always 27 duo to being a constant value

## Version 2.20.1
* Fixed an error when cloning an item with an existing ExtEquipment
* Changed prebuild to reference Mono.Cecil from the BepInEx folder to avoid version conflicts
Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Configs/PieceConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void Apply(GameObject prefab)

if (!string.IsNullOrEmpty(Category))
{
piece.m_category = PieceManager.Instance.AddPieceCategory(PieceTable, Category);
piece.m_category = PieceManager.Instance.AddPieceCategory(Category);
}
}

Expand Down
106 changes: 106 additions & 0 deletions JotunnLib/Configs/RoomConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System;
using Jotunn.Entities;
using UnityEngine;

namespace Jotunn.Configs
{
/// <summary>
/// Configuration class for adding custom rooms.<br />
/// Use this in a constructor of <see cref="CustomRoom"/>
/// </summary>
public class RoomConfig
{
/// <summary>
/// Theme name of this room.
/// </summary>
public string ThemeName { get; set; }

/// <summary>
/// <see cref="Room.Theme"/> of this room.
/// </summary>
public Room.Theme Theme { get; set; }

/// <summary>
/// If set to false, room will not be added to <see cref="DungeonGenerator.m_availableRooms"/>, thus
/// won't be used during generation.
/// </summary>
public bool? Enabled { get; set; }

/// <summary>
/// Flag indicating if this room is a dungeon entrance.
/// </summary>
public bool? Entrance { get; set; }

/// <summary>
/// Flag indicating if this room is an endcap.
/// </summary>
public bool? Endcap { get; set; }

/// <summary>
/// Flag indicating if this room is a divider.
/// </summary>
public bool? Divider { get; set; }

/// <summary>
/// A rank value to prioritize this endcap over others during generation.
/// </summary>
public int? EndcapPrio { get; set; }

/// <summary>
/// Exclude this room if the adjoining connection's <see cref="RoomConnection.m_placeOrder"/> is less than this value.
/// </summary>
public int? MinPlaceOrder { get; set; }

/// <summary>
/// A weight value used to sort available rooms during some modes of generation. Defaults to 1f.
/// </summary>
public float? Weight { get; set; }

/// <summary>
/// Flag to orient this room towards the center. Used only for generating camps (draugr/fuling villages).
/// </summary>
public bool? FaceCenter { get; set; }

/// <summary>
/// Flag to ensure this room is only placed around the perimeter of a camp. Used only for generating camps (draugr/fuling villages).
/// </summary>
public bool? Perimeter { get; set; }

/// <summary>
/// Create a config with a <see cref="Room.Theme"/>.
/// </summary>
/// <param name="theme"></param>
public RoomConfig(Room.Theme theme)
{
Theme = theme;
ThemeName = string.Empty;
}

/// <summary>
/// Create a config with a theme name.
/// </summary>
/// <param name="themeName"></param>
public RoomConfig(string themeName)
{
Theme = 0;
ThemeName = themeName;
}

/// <summary>
/// Create a new <see cref="RoomConfig"/>
/// </summary>
public RoomConfig() { }


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;
}
}
}
8 changes: 8 additions & 0 deletions JotunnLib/Documentation/flow.puml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ box Jotunn
participant ZoneManager
participant GUIManager
participant MinimapManager
participant SynchronizationManager
end box

group For each mod
Expand Down Expand Up @@ -83,6 +84,13 @@ Valheim -> Valheim++: Minimap.LoadMapData
hnote over MinimapManager: OnVanillaMapDataLoaded
deactivate Valheim

group client (only if connecting to a server)
Valheim -> Valheim++: ZRoutedRpc.HandleRoutedRPC
hnote over SynchronizationManager: OnAdminStatusChanged
hnote over SynchronizationManager: OnSyncingConfiguration
hnote over SynchronizationManager: OnConfigurationSynchronized
deactivate Valheim
end group

note over Valheim #lightblue: Game interactable

Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Documentation/images/data/eventFlow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 22 additions & 5 deletions JotunnLib/Documentation/tutorials/asset-creation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ New Assets can be created with Unity and imported into Valheim using Jötunn. In

Creation Tools
* [Visual Studio](https://visualstudio.microsoft.com/de/downloads/) - Editor for our plugin code
* [Unity 2022.3.12](https://unity3d.com/unity/whats-new/2022.3.12) - Game engine that Valheim runs in
* [Unity 2022.3.17](https://unity3d.com/unity/whats-new/2022.3.17) - Game engine that Valheim runs in

Game Mods (install these into your game as our mod has dependencies on them)
* [Jötunn, the Valheim Library](https://thunderstore.io/c/valheim/p/ValheimModding/Jotunn/) - Mod with convenience methods we will use
Expand All @@ -22,7 +22,7 @@ To add an item to the game, a mod maker will have to:

## Unity Editor Setup

Valheim uses Unity Version **2022.3.12**
Valheim uses Unity Version **2022.3.17**

If you don't have Unity already installed, download [UnityHub](https://public-cdn.cloud.unity3d.com/hub/prod/UnityHubSetup.exe) from their website or install it with the Visual Studio Installer via `Individual Components` -> `Visual Studio Tools for Unity`. You will need an Unity account to register your PC and get a free licence. [Create the account](https://id.unity.com/account/new), login with it in UnityHub and get your licence via `Settings` -> `Licence Management`.

Expand All @@ -35,11 +35,28 @@ After ripping the project you can open this as a reference on the vanilla prefab

### Mod Stub Project

Jötunn provides you with a barebone project stub which also includes a Unity project. You can get [that project in its entirety](https://github.com/Valheim-Modding/JotunnModStub) from our github. If you don't have already setup your dev environment, see our [step-by-step guide](../guides/guide.md) on how to do that.
Jötunn provides you with a barebone project stub that also includes a Unity project.
You can get [this project in its entirety](https://github.com/Valheim-Modding/JotunnModStub) from our github.
If you haven't already setup your dev environment, see our [step-by-step guide](../guides/guide.md) on how to do this.

Before opening the Unity project, copy all files starting with `assembly_` and `ConnectedStorage.dll`, `PlayFab.dll`, `PlayFabParty.dll` from your ripped Valheim project at `<RippedValheimProject>\AuxiliaryFiles\GameAssemblies` into your stub project's `<JotunnModStub>\JotunnModUnity\Assets\Assemblies` folder (create that if necessary). This enables us to exchange prefabs between the two projects without losing the references to the added Components.
Before opening the Unity project, copy the following files (especially the .meta files) from your ripped Valheim project at `<RippedValheimProject>\Assets\Plugins` folder into your stub project's `<JotunnModStub>\JotunnModUnity\Assets\Assemblies` folder (create that if necessary).\
If you are using the ModStub, you can compile the C# project instead, which will copy the necessary files for you.
See the [CopyToUnity Task](https://github.com/Valheim-Modding/JotunnModStub/blob/d8d48e6337bf842d57f0728d277c28543d016514/JotunnModStub/JotunnModStub.csproj#L83-L108)

**Copy the files to the new project directly via the filesystem - don't import the assemblies via Unity**.
- all assembly_*.dll files
- PlayFab.dll
- PlayFabParty.dll
- PlatformTools.Core.dll
- PlatformTools.Common.dll
- ConnectedStorage.dll
- gui_framework.dll
- com.rlabrecque.steamworks.net.dll
- SoftReferenceableAssets.dll

This allows us to exchange prefabs between the two projects without losing the references to the added components.\
You can also copy the dll files from your game folder `<ValheimInstall>/valheim_Data/Managed` and recover the missing references using e.g. the NG Missing Script Recovery tool.

**Copy the files directly to the new project via the file system - don't import the assemblies via Unity**.

After you copied the files, open UnityHub, add the JotunnModUnity project and open it.

Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Entities/CustomPiece.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public string Category

if (Piece && !string.IsNullOrEmpty(category))
{
Piece.m_category = PieceManager.Instance.AddPieceCategory(PieceTable, category);
Piece.m_category = PieceManager.Instance.AddPieceCategory(category);
}
}
}
Expand Down
183 changes: 183 additions & 0 deletions JotunnLib/Entities/CustomRoom.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Jotunn.Configs;
using Jotunn.Managers;
using SoftReferenceableAssets;
using UnityEngine;

namespace Jotunn.Entities
{
/// <summary>
/// Main interface for adding custom dungeon rooms to the game.<br />
/// All custom rooms have to be wrapped inside this class to add it to Jötunns <see cref="DungeonManager"/>.
/// </summary>
public class CustomRoom : CustomEntity
{
/// <summary>
/// The prefab for this custom room.
/// </summary>
public GameObject Prefab { get; }

/// <summary>
/// The <see cref="global::Room"/> component for this custom room as a shortcut.
/// </summary>
public Room Room { get; }

/// <summary>
/// The name of this custom room as a shortcut.
/// </summary>
public string Name { get; }

/// <summary>
/// Indicator if references from <see cref="Entities.Mock{T}"/>s will be replaced at runtime.
/// </summary>
public bool FixReference { get; set; }

/// <summary>
/// Theme name of this room.
/// </summary>
public string ThemeName { get; set; }

/// <summary>
/// <see cref="Room.Theme"/> of this room.
/// </summary>
public Room.Theme Theme { get; set; }

/// <summary>
/// Associated <see cref="DungeonDB.RoomData"/> holding data used during generation.
/// </summary>
public DungeonDB.RoomData RoomData { get; private set; }

/// <summary>
/// Custom room from a prefab loaded from an <see cref="AssetBundle"/> with a <see cref="global::Room"/> made from a <see cref="RoomConfig"/>.<br />
/// Can fix references for <see cref="Entities.Mock{T}"/>s.
/// </summary>
/// <param name="assetBundle">A preloaded <see cref="AssetBundle"/></param>
/// <param name="assetName">Name of the prefab in the bundle.</param>
/// <param name="fixReference">If true references for <see cref="Entities.Mock{T}"/> objects get resolved at runtime by Jötunn.</param>
/// <param name="roomConfig">The config for this custom room.</param>
public CustomRoom(AssetBundle assetBundle, string assetName, bool fixReference, RoomConfig roomConfig) : base(Assembly.GetCallingAssembly())
{
Prefab = assetBundle.LoadAsset<GameObject>(assetName);
Name = Prefab.name;

ThemeName = roomConfig.ThemeName;
Theme = roomConfig.Theme;

if (Prefab != null && Prefab.TryGetComponent<Room>(out var room))
{
var existingRoom = room;
Room = ApplyConfig(roomConfig, existingRoom);
}
else
{
var newRoom = Prefab.AddComponent<Room>();
Room = ApplyConfig(roomConfig, newRoom);
}

FixReference = fixReference;

// DungeonGenerator.PlaceRoom*() utilize soft references directly, thus registering the assets here.
RoomData = new DungeonDB.RoomData()
{
m_prefab = new SoftReference<GameObject>(AssetManager.Instance.AddAsset(Prefab)),
m_loadedRoom = Room,
m_enabled = Room.m_enabled,
m_theme = roomConfig.Theme
};
}


/// <summary>
/// Custom room from a prefab with a <see cref="global::Room"/> made from a <see cref="RoomConfig"/>.
/// </summary>
/// <param name="prefab">The prefab for this custom room.</param>
/// <param name="roomConfig">The config for this custom room.</param>
public CustomRoom(GameObject prefab, RoomConfig roomConfig)
: this(prefab, false, roomConfig) { }


/// <summary>
/// Custom room from a prefab loaded from an <see cref="AssetBundle"/> with a <see cref="global::Room"/> made from a <see cref="RoomConfig"/>.<br />
/// Can fix references for <see cref="Entities.Mock{T}"/>s.
/// </summary>
/// <param name="prefab">The prefab for this custom room.</param>
/// <param name="fixReference">If true references for <see cref="Entities.Mock{T}"/> objects get resolved at runtime by Jötunn.</param>
/// <param name="roomConfig">The config for this custom room.</param>
public CustomRoom(GameObject prefab, bool fixReference, RoomConfig roomConfig) : base(Assembly.GetCallingAssembly())
{
Prefab = prefab;
Name = prefab.name;

ThemeName = roomConfig.ThemeName;
Theme = roomConfig.Theme;

if (prefab != null && prefab.TryGetComponent<Room>(out var room))
{
var existingRoom = room;
Room = ApplyConfig(roomConfig, existingRoom);
}
else
{
var newRoom = prefab.AddComponent<Room>();
Room = ApplyConfig(roomConfig, newRoom);
}

FixReference = fixReference;

// DungeonGenerator.PlaceRoom*() utilize soft references directly, thus registering the assets here.
RoomData = new DungeonDB.RoomData()
{
m_prefab = new SoftReference<GameObject>(AssetManager.Instance.AddAsset(Prefab)),
m_loadedRoom = Room,
m_enabled = Room.m_enabled,
m_theme = roomConfig.Theme
};
}

/// <summary>
/// Converts the RoomConfig to a Valheim style <see cref="Room"/>.
/// </summary>
public Room ApplyConfig(RoomConfig roomConfig, Room room)
{
// Ensure Room values are overwritten only when a value's present.
if (roomConfig.Enabled != null) room.m_enabled = roomConfig.Enabled.Value;
if (roomConfig.Entrance != null) room.m_entrance = roomConfig.Entrance.Value;
if (roomConfig.Endcap != null) room.m_endCap = roomConfig.Endcap.Value;
if (roomConfig.Divider != null) room.m_divider = roomConfig.Divider.Value;
if (roomConfig.EndcapPrio != null) room.m_endCapPrio = roomConfig.EndcapPrio.Value;
if (roomConfig.MinPlaceOrder != null) room.m_minPlaceOrder = roomConfig.MinPlaceOrder.Value;
if (roomConfig.Weight != null) room.m_weight = roomConfig.Weight.Value;
if (roomConfig.FaceCenter != null) room.m_faceCenter = roomConfig.FaceCenter.Value;
if (roomConfig.Perimeter != null) room.m_perimeter = roomConfig.Perimeter.Value;

return room;
}

/// <summary>
/// Helper method to determine if a prefab with a given name is a custom room created with Jötunn.
/// </summary>
/// <param name="prefabName">Name of the prefab to test.</param>
/// <returns>true if the prefab is added as a custom item to the <see cref="DungeonManager"/>.</returns>
public static bool IsCustomRoom(string prefabName)
{
return DungeonManager.Instance.Rooms.ContainsKey(prefabName);
}

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;
}

}
}
Loading
Loading