Skip to content

Commit

Permalink
Remove event/bundle property in qsbcore
Browse files Browse the repository at this point in the history
  • Loading branch information
misternebula committed Oct 30, 2023
1 parent 64d83fc commit 419bb83
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
16 changes: 9 additions & 7 deletions QSB/BodyCustomization/BodyCustomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,26 @@ public class BodyCustomizer : MonoBehaviour, IAddComponentOnStart
private Dictionary<string, (Texture2D albedo, Texture2D normal)> skinMap = new();
private Dictionary<string, Texture2D> jetpackMap = new();

public AssetBundle SkinsBundle { get; private set; }

public static BodyCustomizer Instance { get; private set; }

private void Start()
{
Instance = this;
QSBCore.OnSkinsBundleLoaded += LoadAssets;
}

private void OnDestroy()
public void OnBundleLoaded(AssetBundle bundle)
{
QSBCore.OnSkinsBundleLoaded -= LoadAssets;
SkinsBundle = bundle;
LoadAssets();
}

private void LoadAssets()
{
DebugLog.DebugWrite($"Loading skin assets...", MessageType.Info);

skinMap.Add("Default", (QSBCore.SkinsBundle.LoadAsset<Texture2D>("Assets/GameAssets/Texture2D/Traveller_HEA_Player_Skin_d.png"), QSBCore.SkinsBundle.LoadAsset<Texture2D>("Assets/GameAssets/Texture2D/Traveller_HEA_Player_Skin_n.png")));
skinMap.Add("Default", (SkinsBundle.LoadAsset<Texture2D>("Assets/GameAssets/Texture2D/Traveller_HEA_Player_Skin_d.png"), SkinsBundle.LoadAsset<Texture2D>("Assets/GameAssets/Texture2D/Traveller_HEA_Player_Skin_n.png")));
skinMap.Add("Type 1", LoadSkin("Type 1"));
skinMap.Add("Type 2", LoadSkin("Type 2"));
skinMap.Add("Type 3", LoadSkin("Type 3"));
Expand All @@ -46,7 +48,7 @@ private void LoadAssets()
skinMap.Add("Type 16", LoadSkin("Type 16"));
skinMap.Add("Type 17", LoadSkin("Type 17"));

jetpackMap.Add("Orange", QSBCore.SkinsBundle.LoadAsset<Texture2D>("Assets/GameAssets/Texture2D/Props_HEA_Jetpack_d.png"));
jetpackMap.Add("Orange", SkinsBundle.LoadAsset<Texture2D>("Assets/GameAssets/Texture2D/Props_HEA_Jetpack_d.png"));
jetpackMap.Add("Yellow", LoadJetpack("yellow"));
jetpackMap.Add("Red", LoadJetpack("red"));
jetpackMap.Add("Pink", LoadJetpack("pink"));
Expand All @@ -60,12 +62,12 @@ private void LoadAssets()
private (Texture2D d, Texture2D n) LoadSkin(string skinName)
{
var number = skinName.Replace($"Type ", "");
return (QSBCore.SkinsBundle.LoadAsset<Texture2D>($"Assets/GameAssets/Texture2D/Skin Variations/{number}d.png"), QSBCore.SkinsBundle.LoadAsset<Texture2D>($"Assets/GameAssets/Texture2D/Skin Variations/{number}n.png"));
return (SkinsBundle.LoadAsset<Texture2D>($"Assets/GameAssets/Texture2D/Skin Variations/{number}d.png"), SkinsBundle.LoadAsset<Texture2D>($"Assets/GameAssets/Texture2D/Skin Variations/{number}n.png"));
}

private Texture2D LoadJetpack(string jetpackName)
{
return QSBCore.SkinsBundle.LoadAsset<Texture2D>($"Assets/GameAssets/Texture2D/Jetpack Variations/{jetpackName}.png");
return SkinsBundle.LoadAsset<Texture2D>($"Assets/GameAssets/Texture2D/Jetpack Variations/{jetpackName}.png");
}

public void CustomizeRemoteBody(GameObject REMOTE_Traveller_HEA_Player_v2, string skinType, string jetpackType)
Expand Down
8 changes: 2 additions & 6 deletions QSB/QSBCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Linq;
using System.Reflection;
using QSB.API;
using QSB.BodyCustomization;
using QSB.Player.Messages;
using UnityEngine;
using UnityEngine.InputSystem;
Expand Down Expand Up @@ -55,7 +56,6 @@ public class QSBCore : ModBehaviour
public static AssetBundle ConversationAssetBundle { get; private set; }
public static AssetBundle DebugAssetBundle { get; private set; }
public static AssetBundle HUDAssetBundle { get; private set; }
public static AssetBundle SkinsBundle { get; private set; }
public static bool IsHost => NetworkServer.active;
public static bool IsInMultiplayer;
public static string QSBVersion => Helper.Manifest.Version;
Expand Down Expand Up @@ -260,11 +260,7 @@ public void Start()
MenuApi = ModHelper.Interaction.TryGetModApi<IMenuAPI>(ModHelper.Manifest.Dependencies[0]);

LoadBundleAsync("qsb_network_big");
LoadBundleAsync("qsb_skins", request =>
{
SkinsBundle = request.assetBundle;
OnSkinsBundleLoaded?.SafeInvoke();
});
LoadBundleAsync("qsb_skins", request => BodyCustomizer.Instance.OnBundleLoaded(request.assetBundle));

NetworkAssetBundle = LoadBundle("qsb_network");
ConversationAssetBundle = LoadBundle("qsb_conversation");
Expand Down

0 comments on commit 419bb83

Please sign in to comment.