Skip to content

Commit

Permalink
Fix AssetBundle
Browse files Browse the repository at this point in the history
- Switch back to older model, most people think it's way better anyway
- Switched some references of "IComputerView" to "ComputerView" because I thought it would fix and error but turns out the error was caused by something else but whatever
- Updated position and such for monitor
- Fixed removing monitor for Stump
  • Loading branch information
developer9998 committed Sep 11, 2023
1 parent 5d713c0 commit b56000e
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
14 changes: 9 additions & 5 deletions ComputerInterface/AssetsLoader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
Expand All @@ -14,14 +15,15 @@ internal class AssetsLoader : IDisposable
private AssetBundle _loadedBundle;
private Task _loadingTask;

private readonly Dictionary<string, Object> _loadedObjects = new Dictionary<string, Object>();

public async Task<T> GetAsset<T>(string name) where T : Object
{
if (_loadedObjects.TryGetValue(name, out var cachedObject)) return (T)cachedObject;

if (!IsLoaded)
{
if (_loadingTask == null)
{
_loadingTask = LoadBundleAsyncInternal();
}
_loadingTask ??= LoadBundleAsyncInternal();

await _loadingTask;
}
Expand All @@ -41,7 +43,9 @@ public async Task<T> GetAsset<T>(string name) where T : Object
completionSource.SetResult((T)assetBundleRequest.asset);
};

return await completionSource.Task;
var completedTask = await completionSource.Task;
_loadedObjects.Add(name, completedTask);
return completedTask;
}

private async Task LoadBundleAsyncInternal()
Expand Down
2 changes: 1 addition & 1 deletion ComputerInterface/ComputerInterface.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

Expand Down
27 changes: 16 additions & 11 deletions ComputerInterface/CustomComputer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace ComputerInterface
{
public class CustomComputer : MonoBehaviour, IInitializable
{
public static CustomComputer Instance => GorillaComputer.instance.GetComponent<CustomComputer>();
private bool _initialized;

private GorillaComputer _gorillaComputer;
Expand Down Expand Up @@ -296,7 +297,7 @@ private async Task ReplaceKeys(GameObject computer)
_keyboardAudios.Add(audioSource);

if (_keyboard.GetComponent<MeshRenderer>() is MeshRenderer renderer) {
renderer.material.color = new Color(0.3f, 0.3f, 0.3f);
//renderer.material.color = new Color(0.3f, 0.3f, 0.3f);
}

var enterKey = _keys.Last(x => x.KeyboardKey == EKeyboardKey.Enter);
Expand Down Expand Up @@ -416,39 +417,37 @@ private CustomKeyboardKey CreateKey(GameObject prefab, string goName, Vector3 of
{
RemoveMonitor(computer, location);

var tmpSettings = await _assetsLoader.GetAsset<TMP_Settings>("TMP Settings");
// Might need this later, but who knows
/* var tmpSettings = await _assetsLoader.GetAsset<TMP_Settings>("TMP Settings");
typeof(TMP_Settings).GetField(
"s_Instance",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)?
.SetValue(null, tmpSettings);
.SetValue(null, tmpSettings); */

var monitorAsset = await _assetsLoader.GetAsset<GameObject>("Monitor");

var newMonitor = Instantiate(monitorAsset);
newMonitor.name = $"{location} Custom Monitor";
newMonitor.transform.SetParent(computer.transform.Find("monitor") ?? computer.transform.Find("monitor (1)"), false);
newMonitor.transform.localPosition = new Vector3(2.28f, -0.72f, 0.0f);
newMonitor.transform.localEulerAngles = new Vector3(0.0f, 270.0f, 270.02f);
newMonitor.transform.localPosition = new Vector3(-0.0787f, -0.21f, 0.5344f);
newMonitor.transform.localEulerAngles = new Vector3(90f, 0f, 0f);
newMonitor.transform.SetParent(computer.transform.parent, true);

foreach (RectTransform rect in newMonitor.GetComponentsInChildren<RectTransform>()) rect.gameObject.layer = 9;
newMonitor.GetComponentInChildren<ReflectionProbe>().enabled = false;

var info = new CustomScreenInfo
{
Transform = newMonitor.transform,
TextMeshProUgui = newMonitor.GetComponentInChildren<TextMeshProUGUI>(),
Renderer = newMonitor.GetComponentsInChildren<MeshRenderer>().First(x => x.name == "Main Monitor"),
RawImage = newMonitor.GetComponentInChildren<RawImage>()
};
info.RawImage.color = new Color(0.05f, 0.05f, 0.05f);
info.Renderer.gameObject.AddComponent<GorillaSurfaceOverride>();
info.Materials = info.Renderer.materials;
info.Color = new Color(0.05f, 0.05f, 0.05f);

return info;
}

private void RemoveMonitor(GameObject computer, MonitorLocation monitorIndex)
private void RemoveMonitor(GameObject computer, MonitorLocation computerLocation)
{
GameObject monitor = null;
foreach (Transform child in computer.transform)
Expand All @@ -474,6 +473,12 @@ private void RemoveMonitor(GameObject computer, MonitorLocation monitorIndex)
terminal.myScreenText?.gameObject?.SetActive(false);
}

if (computerLocation == MonitorLocation.Treehouse)
{
var monitorTransform = computer.transform.parent.parent?.Find("Static/monitor") ?? null;
monitorTransform?.gameObject?.SetActive(false);
}

try
{
// Some monitors were baked into the scene, so we need to do all this jank to get rid of them
Expand All @@ -487,7 +492,7 @@ private void RemoveMonitor(GameObject computer, MonitorLocation monitorIndex)
ZoneData FindZoneData(GTZone zone)
=> (ZoneData)AccessTools.Method(typeof(ZoneManagement), "GetZoneData").Invoke(zoneManager, new object[] { zone });

GameObject combinedScene = monitorIndex switch
GameObject combinedScene = computerLocation switch
{
MonitorLocation.Treehouse => FindZoneData(GTZone.forest).rootGameObjects[1].transform.Find("Terrain/Uncover ForestCombined/").GetComponentInChildren<MeshRenderer>(true).gameObject,
MonitorLocation.Mountains => FindZoneData(GTZone.mountain).rootGameObjects[0].transform.Find("Mountain Texture Baker/Uncover Mountain Lit/").GetComponentInChildren<MeshRenderer>(true).gameObject,
Expand Down
4 changes: 2 additions & 2 deletions ComputerInterface/CustomScreenInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class CustomScreenInfo

public Color Color
{
get => RawImage.material.color;
set => RawImage.material.color = value;
get => RawImage.color;
set => RawImage.color = value;
}

public string Text
Expand Down
2 changes: 1 addition & 1 deletion ComputerInterface/MainInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class MainInstaller : Installer
public override void InstallBindings()
{
Container
.BindFactory<Type, IComputerView, ComputerViewPlaceholderFactory>()
.BindFactory<Type, ComputerView, ComputerViewPlaceholderFactory>()
.FromFactory<ComputerViewFactory>();

Container.BindInterfacesAndSelfTo<CustomComputer>().FromNewComponentOn(ComputerGetter).AsSingle();
Expand Down
Binary file modified ComputerInterface/Resources/assets
Binary file not shown.
2 changes: 1 addition & 1 deletion ComputerInterface/ViewLib/ComputerView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ComputerView : IComputerView
/// <summary>
/// How many characters fit in the x axis of the screen
/// </summary>
public static int SCREEN_WIDTH = 41;
public static int SCREEN_WIDTH = 47;

/// <summary>
/// How many characters fit in the y axis of the screen
Expand Down
6 changes: 3 additions & 3 deletions ComputerInterface/ViewLib/ComputerViewFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ComputerInterface.ViewLib
{
public class ComputerViewFactory : IFactory<Type, IComputerView>
public class ComputerViewFactory : IFactory<Type, ComputerView>
{
private readonly DiContainer _container;

Expand All @@ -13,9 +13,9 @@ public ComputerViewFactory(DiContainer container)
_container = container;
}

public IComputerView Create(Type viewType)
public ComputerView Create(Type viewType)
{
return (IComputerView) _container.Instantiate(viewType);
return (ComputerView) _container.Instantiate(viewType);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

namespace ComputerInterface.ViewLib
{
public class ComputerViewPlaceholderFactory : PlaceholderFactory<Type, IComputerView> { }
public class ComputerViewPlaceholderFactory : PlaceholderFactory<Type, ComputerView> { }
}

0 comments on commit b56000e

Please sign in to comment.