Skip to content

Commit

Permalink
Overhaul asset location and packaging
Browse files Browse the repository at this point in the history
R2modman installs should now be fixed.  Hopefully also works in
Thunderstore and Vortex, which I cannot yet test.

Closes #1
  • Loading branch information
joeyparrish committed Jun 16, 2022
1 parent 041b310 commit fb7b878
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 38 deletions.
16 changes: 8 additions & 8 deletions Pokeheim/BallItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ private struct BallConfig {

private static Dictionary<string, BallConfig> BallConfigs = new Dictionary<string, BallConfig> {
{ "Pokeball", new BallConfig {
TexturePath = "Pokeheim/Assets/Monster ball texture.png",
TexturePath = "Monster ball texture.png",
BallFactor = 1.0f,
ItemConfig = new ItemConfig {
Name = "$item_pokeball",
Description = "$item_pokeball_description",
Icons = new []{ AssetUtils.LoadSpriteFromFile("Pokeheim/Assets/Monster ball.png") },
Icons = new []{ Utils.LoadSprite("Monster ball.png") },
Amount = 10,
Requirements = new[] {
new RequirementConfig {
Expand All @@ -68,12 +68,12 @@ private struct BallConfig {
},
} },
{ "Greatball", new BallConfig {
TexturePath = "Pokeheim/Assets/Super monster ball texture.png",
TexturePath = "Super monster ball texture.png",
BallFactor = 1.5f,
ItemConfig = new ItemConfig {
Name = "$item_greatball",
Description = "$item_greatball_description",
Icons = new []{ AssetUtils.LoadSpriteFromFile("Pokeheim/Assets/Super monster ball.png") },
Icons = new []{ Utils.LoadSprite("Super monster ball.png") },
Amount = 10,
Requirements = new[] {
new RequirementConfig {
Expand All @@ -88,12 +88,12 @@ private struct BallConfig {
},
} },
{ "Ultraball", new BallConfig {
TexturePath = "Pokeheim/Assets/Ultra monster ball texture.png",
TexturePath = "Ultra monster ball texture.png",
BallFactor = 2.0f,
ItemConfig = new ItemConfig {
Name = "$item_ultraball",
Description = "$item_ultraball_description",
Icons = new []{ AssetUtils.LoadSpriteFromFile("Pokeheim/Assets/Ultra monster ball.png") },
Icons = new []{ Utils.LoadSprite("Ultra monster ball.png") },
Amount = 10,
Requirements = new[] {
new RequirementConfig {
Expand Down Expand Up @@ -156,7 +156,7 @@ private static void AddBalls() {
Identifier = "training",
Name = "$skill_monster_training",
Description = "$skill_monster_training_description",
Icon = AssetUtils.LoadSpriteFromFile("Pokeheim/Assets/Skill icon.png"),
Icon = Utils.LoadSprite("Skill icon.png"),
IncreaseStep = 1f,
});

Expand Down Expand Up @@ -202,7 +202,7 @@ private static void ApplyBallStyle(GameObject prefab, string texturePath) {
ReplaceMesh(prefab, BallMesh, scale, rotation, translation);

// Replace the texture, as well.
var newTexture = AssetUtils.LoadTexture(texturePath);
var newTexture = Utils.LoadTexture(texturePath);
ReplaceTexture(prefab, newTexture);
}

Expand Down
4 changes: 2 additions & 2 deletions Pokeheim/InventoryMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace Pokeheim {
public class InventoryMods {
private const string SortIconPath = "Pokeheim/Assets/Sort icon.png";
private const string SortIconPath = "Sort icon.png";

[HarmonyPatch(typeof(Humanoid), nameof(Humanoid.Awake))]
class LargeInventory_Patch {
Expand Down Expand Up @@ -125,7 +125,7 @@ static void Postfix(InventoryGui __instance) {
armorText.gameObject.SetActive(false);

// Replace the icon.
armorIcon.sprite = AssetUtils.LoadSpriteFromFile(SortIconPath);
armorIcon.sprite = Utils.LoadSprite(SortIconPath);

// Center the icon.
armorIcon.rectTransform.anchoredPosition = new Vector2(0.5f, 0.5f);
Expand Down
12 changes: 5 additions & 7 deletions Pokeheim/MonsterMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,8 @@ public static class MonsterMetadata {

private static Dictionary<string, Metadata> MonsterMap;

private static readonly string OverlayPath =
"Pokeheim/Assets/Inhabited-overlay.png";
private static readonly string PremadeIconPrefix =
"Pokeheim/Assets/PremadeIcon-";
private static readonly string OverlayPath = "Inhabited-overlay.png";
private static readonly string PremadeIconPrefix = "PremadeIcon-";

private static Sprite Overlay;
private const float OverlayAlpha = 0.6f;
Expand All @@ -214,7 +212,7 @@ public static class MonsterMetadata {

[PokeheimInit]
public static void Init() {
Overlay = AssetUtils.LoadSpriteFromFile(OverlayPath, centerPivot);
Overlay = Utils.LoadSprite(OverlayPath, centerPivot);

#if DEBUG
CommandManager.Instance.AddConsoleCommand(new SpawnAll());
Expand Down Expand Up @@ -443,11 +441,11 @@ public void Load() {
if (this.trophyName == null) {
// Load a premade icon from disk.
var path = $"{PremadeIconPrefix}{this.prefabName}.png";
this.trophyIcon = AssetUtils.LoadSpriteFromFile(path, centerPivot);
this.trophyIcon = Utils.LoadSprite(path, centerPivot);

if (trophyIcon == null) {
path = $"{PremadeIconPrefix}fallback.png";
this.trophyIcon = AssetUtils.LoadSpriteFromFile(path, centerPivot);
this.trophyIcon = Utils.LoadSprite(path, centerPivot);
}

if (this.prefabCharacter != null && this.trophyIcon != null) {
Expand Down
4 changes: 2 additions & 2 deletions Pokeheim/MusicMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
namespace Pokeheim {
public static class MusicMods {
private static readonly Dictionary<string, string> OverrideMusic = new Dictionary<string, string> {
{"menu", "Pokeheim/Assets/Main-Menu.mp3"},
{"menu", "Main-Menu.mp3"},
// TODO: morning music
//{"morning", ""},
};
Expand All @@ -43,7 +43,7 @@ public static void Init() {
}

static AudioClip LoadAudioClip(string relativePath) {
var absolutePath = Path.Combine(BepInEx.Paths.PluginPath, relativePath);
var absolutePath = Utils.GetAssetPath(relativePath);
var pathUrl = "file:///" + absolutePath.Replace("\\", "/");
var request = UnityWebRequestMultimedia.GetAudioClip(
pathUrl, AudioType.MPEG);
Expand Down
4 changes: 2 additions & 2 deletions Pokeheim/PlayerMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
namespace Pokeheim {
public static class PlayerMods {
private const string PokedexFakeStationPrefix = "com.pokeheim.pokedex.";
private const string PokedexIconPath = "Pokeheim/Assets/Pokedex icon.png";
private const string PokedexIconPath = "Pokedex icon.png";

[PokeheimInit]
public static void Init() {
Expand Down Expand Up @@ -192,7 +192,7 @@ static void FindPokedexComponents(InventoryGui __instance) {
if (component.name == "Trophies") {
foreach (var child in component.GetComponentsInChildren<Image>()) {
if (child.name == "Image") {
child.sprite = AssetUtils.LoadSpriteFromFile(PokedexIconPath);
child.sprite = Utils.LoadSprite(PokedexIconPath);
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions Pokeheim/Pokeheim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ static void Postfix(FejdStartup __instance) {
var logo = startup.m_mainMenu.transform.Find("LOGO").gameObject;
var hh = startup.m_mainMenu.transform.Find("H&H").gameObject;

logo.GetComponent<Image>().sprite =
AssetUtils.LoadSpriteFromFile("Pokeheim/Assets/Logo.png");
logo.GetComponent<Image>().sprite = Utils.LoadSprite("Logo.png");
hh.GetComponent<Image>().enabled = false;
}
}
Expand Down Expand Up @@ -135,8 +134,7 @@ static void Postfix(Hud __instance) {

// Update the logo.
var image = __instance.m_loadingProgress.transform.Find("text_darken/Logotype");
image.GetComponent<Image>().sprite =
AssetUtils.LoadSpriteFromFile("Pokeheim/Assets/Logo.png");
image.GetComponent<Image>().sprite = Utils.LoadSprite("Logo.png");
}
}

Expand Down
31 changes: 31 additions & 0 deletions Pokeheim/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

using HarmonyLib;
using Jotunn.Managers;
using Jotunn.Utils;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEngine.UI;

Expand Down Expand Up @@ -346,5 +349,33 @@ public static GameObject GetSpawnedLocationOrPrefab(string name) {
Logger.LogDebug($"Found no existing instances of location {name}.");
return zoneLocation.m_prefab;
}

private static string cachedAssetRootPath = null;

private static void FindAssetRootPath() {
if (cachedAssetRootPath == null) {
string assemblyFolder = System.IO.Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location);
cachedAssetRootPath = Path.Combine(
assemblyFolder, "Pokeheim", "Assets");
}
}

public static string GetAssetPath(string asset) {
FindAssetRootPath();
return Path.Combine(cachedAssetRootPath, asset);
}

public static Sprite LoadSprite(string asset) {
return LoadSprite(asset, Vector2.zero);
}

public static Sprite LoadSprite(string asset, Vector2 pivot) {
return AssetUtils.LoadSpriteFromFile(GetAssetPath(asset), pivot);
}

public static Texture2D LoadTexture(string asset) {
return AssetUtils.LoadTexture(GetAssetPath(asset));
}
}
}
4 changes: 3 additions & 1 deletion docs/Install.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ experienced Linux user).
5. Move `Jotunn.dll` to the `BepInEx/plugins/` folder inside the Valheim
install folder.
6. Unpack the MountUp zip into the `BepInEx/plugins/` folder.
7. Unpack the Pokéheim zip into the `BepInEx/plugins/` folder.
7. Unpack the Pokéheim zip and move the contents of the zip's `plugins` folder
into the `BepInEx/plugins/` folder.
8. _(If **not using** Steam)_ Run `start_game_bepinex.sh` to launch Pokéheim.
9. _(If **using** Steam)_
See [Steam.md](https://github.com/joeyparrish/pokeheim/blob/main/docs/Steam.md)
Expand All @@ -84,6 +85,7 @@ experienced Linux user).
1. _(Linux only)_ Remove the mods:
```sh
rm ~/.local/share/Steam/steamapps/common/Valheim/BepInEx/plugins/Pokeheim.dll
rm -rf ~/.local/share/Steam/steamapps/common/Valheim/BepInEx/plugins/Pokeheim/
rm ~/.local/share/Steam/steamapps/common/Valheim/BepInEx/plugins/MountUp.dll
rm ~/.local/share/Steam/steamapps/common/Valheim/BepInEx/plugins/Jotunn.dll
Expand Down
4 changes: 3 additions & 1 deletion scripts/build-and-launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ cd "$(dirname "$0")"/..
./scripts/install-mod.sh "$BUILD_TYPE"

cd ~/.local/share/Steam/steamapps/common/Valheim
./start_game_bepinex.sh ~/.local/share/Steam/steamapps/common/Valheim/valheim.x86_64 -force-glcore -console
./start_game_bepinex.sh \
~/.local/share/Steam/steamapps/common/Valheim/valheim.x86_64 \
-force-glcore -console
17 changes: 12 additions & 5 deletions scripts/install-mod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ PLUGINS_PATH=~/.local/share/Steam/steamapps/common/"$GAME_NAME"/BepInEx/plugins

cd "$(dirname "$0")"/..

# Old location (<= v1.0.3)
rm -rf "$PLUGINS_PATH"/Pokeheim/
mkdir -p "$PLUGINS_PATH"/Pokeheim/Assets/

# New location (>= v1.0.4), simulates r2modman install pattern
POKEHEIM_FOLDER="$PLUGINS_PATH"/Pokeheim-Pokeheim
POKEHEIM_ASSETS="$PLUGINS_PATH"/Pokeheim-Pokeheim/Pokeheim/Assets
rm -rf "$POKEHEIM_FOLDER"
mkdir -p "$POKEHEIM_ASSETS"

# NOTE: What nuget downloads is always a Debug build of Jotunn.
# To install a true Release build, we need to fetch that from some place like
Expand All @@ -33,9 +39,10 @@ if [ "$BUILD_TYPE" == "Release" ]; then
else
cp Pokeheim/bin/$BUILD_TYPE/Jotunn.dll "$PLUGINS_PATH"/
fi
cp Pokeheim/bin/$BUILD_TYPE/Pokeheim.dll "$PLUGINS_PATH"/Pokeheim/
cp Pokeheim/Assets/*.png "$PLUGINS_PATH"/Pokeheim/Assets/
cp Pokeheim/Assets/*.mp3 "$PLUGINS_PATH"/Pokeheim/Assets/
cp -a Pokeheim/Assets/Translations "$PLUGINS_PATH"/Pokeheim/Assets/

cp Pokeheim/bin/$BUILD_TYPE/Pokeheim.dll "$POKEHEIM_FOLDER"/
cp Pokeheim/Assets/*.png "$POKEHEIM_ASSETS"/
cp Pokeheim/Assets/*.mp3 "$POKEHEIM_ASSETS"/
cp -a Pokeheim/Assets/Translations "$POKEHEIM_ASSETS"/

echo "Installed $BUILD_TYPE build."
12 changes: 6 additions & 6 deletions scripts/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ rm -rf Pokeheim/bin/

# Make a generic zip.
rm -rf staging Pokeheim.zip
mkdir -p staging/Pokeheim/Assets
mkdir -p staging/plugins/Pokeheim/Assets
# Stage mod & assets.
cp Pokeheim/bin/Release/Pokeheim.dll staging/Pokeheim/
cp Pokeheim/Assets/*.png staging/Pokeheim/Assets/
cp Pokeheim/Assets/*.mp3 staging/Pokeheim/Assets/
cp -a Pokeheim/Assets/Translations staging/Pokeheim/Assets/
cp Pokeheim/bin/Release/Pokeheim.dll staging/plugins/
cp Pokeheim/Assets/*.png staging/plugins/Pokeheim/Assets/
cp Pokeheim/Assets/*.mp3 staging/plugins/Pokeheim/Assets/
cp -a Pokeheim/Assets/Translations staging/plugins/Pokeheim/Assets/
# Stage mod metadata.
cp publish/icon.png staging/
cp README.md staging/
Expand All @@ -41,7 +41,7 @@ set +x

# Double-check versioning.
manifest_version=$(cat staging/manifest.json | jq -r .version_number)
dll_version=$(monodis --assembly staging/Pokeheim/Pokeheim.dll \
dll_version=$(monodis --assembly staging/plugins/Pokeheim.dll \
| grep Version | cut -f 2 -d : | tr -d ' ')
if [[ "$manifest_version.0" != "$dll_version" ]]; then
echo "Version mismatch!"
Expand Down

0 comments on commit fb7b878

Please sign in to comment.