2023-08-13 21:03:01 +00:00
using System ;
using System.IO ;
using System.Reflection ;
using HarmonyLib ;
using UnityModManagerNet ;
using UnityEngine ;
2023-09-01 00:24:32 +00:00
using System.Diagnostics.CodeAnalysis ;
2023-08-13 21:03:01 +00:00
namespace dumb282tweaks ;
public static class Main {
// Variables
2023-11-23 12:04:06 +00:00
public static UnityModManager . ModEntry Instance { get ; private set ; }
public static dumb282tweaksSettings Settings { get ; private set ; }
2023-08-13 21:03:01 +00:00
2023-11-23 12:04:06 +00:00
// public static readonly string[] cabTypeTexts = new[] {
// "Default",
// "German"
// };
2023-09-01 00:24:32 +00:00
public static readonly string [ ] smokeDeflectorTypeTexts = new [ ] {
2023-08-22 00:03:27 +00:00
"None" ,
"Witte" ,
"Wagner"
} ;
2023-09-01 00:24:32 +00:00
public static readonly string [ ] boilerTypeTexts = new [ ] {
2023-08-13 21:03:01 +00:00
"Default" ,
2023-08-22 00:03:27 +00:00
"Streamlined"
2023-08-13 21:03:01 +00:00
} ;
2023-11-12 18:47:12 +00:00
// public static readonly string[] smokeStackTypeTexts = new[] {
// "Default",
// "Short",
// };
2023-08-13 21:03:01 +00:00
2023-11-23 12:04:06 +00:00
public static GameObject wagnerSmokeDeflectorsLoad ;
public static GameObject witteSmokeDeflectorsLoad ;
public static GameObject streamlinedBoilerLoad ;
2023-08-15 00:42:40 +00:00
2023-08-13 21:03:01 +00:00
// Load
private static bool Load ( UnityModManager . ModEntry modEntry ) {
Harmony ? harmony = null ;
try {
Instance = modEntry ;
Settings = UnityModManager . ModSettings . Load < dumb282tweaksSettings > ( Instance ) ;
Instance . OnGUI = OnGUI ;
Instance . OnSaveGUI = OnSaveGUI ;
harmony = new Harmony ( Instance . Info . Id ) ;
harmony . PatchAll ( Assembly . GetExecutingAssembly ( ) ) ;
2023-08-22 00:03:27 +00:00
2023-11-12 18:47:12 +00:00
string assetPath = Path . Combine ( Instance . Path , "assets\\" ) ;
wagnerSmokeDeflectorsLoad = AssetBundle . LoadFromFile ( Path . Combine ( assetPath , "wagnersmokedeflectors" ) ) . LoadAsset < GameObject > ( "Assets/WagnerSmokeDeflectors.prefab" ) ;
witteSmokeDeflectorsLoad = AssetBundle . LoadFromFile ( Path . Combine ( assetPath , "wittesmokedeflectors" ) ) . LoadAsset < GameObject > ( "Assets/WitteSmokeDeflectors.prefab" ) ;
streamlinedBoilerLoad = AssetBundle . LoadFromFile ( Path . Combine ( assetPath , "streamline" ) ) . LoadAsset < GameObject > ( "Assets/Streamline.prefab" ) ;
2023-08-22 00:03:27 +00:00
} catch ( Exception ex ) {
2023-08-13 21:03:01 +00:00
Instance . Logger . LogException ( $"Failed to load {Instance.Info.DisplayName}:" , ex ) ;
harmony ? . UnpatchAll ( Instance . Info . Id ) ;
return false ;
}
return true ;
}
// GUI Rendering
static void OnGUI ( UnityModManager . ModEntry modEntry ) {
GUILayout . BeginVertical ( ) ;
2023-08-22 00:03:27 +00:00
GUILayout . Label ( "These settings are applied on train spawn, meaning rejoining the game will refresh all 282 locos to the settings specified here, but if you don't unload the train it will keep whatever settings were there previously. This is a temporary solution until I have a proper GUI implemented." ) ;
2023-09-01 00:24:32 +00:00
GUILayout . Label ( "Also, reloading a save will currently break things and the tweaks won't load. This isn't good." ) ;
2023-08-22 00:03:27 +00:00
2023-11-12 18:47:12 +00:00
GUILayout . Space ( 2f ) ;
//todo this is not implemented
// GUILayout.Label("Cab Type");
// Settings.cabType = (Settings.CabType) GUILayout.SelectionGrid((int) Settings.cabType, cabTypeTexts, 1, "toggle");
2023-08-13 21:03:01 +00:00
GUILayout . Label ( "Smoke Deflector Type" ) ;
2023-09-01 00:24:32 +00:00
Settings . smokeDeflectorType = ( Settings . SmokeDeflectorType ) GUILayout . SelectionGrid ( ( int ) Settings . smokeDeflectorType , smokeDeflectorTypeTexts , 1 , "toggle" ) ;
2023-11-12 18:47:12 +00:00
GUILayout . Label ( "Boiler Type" ) ;
Settings . boilerType = ( Settings . BoilerType ) GUILayout . SelectionGrid ( ( int ) Settings . boilerType , boilerTypeTexts , 1 , "toggle" ) ;
2023-08-22 00:03:27 +00:00
2023-08-13 21:03:01 +00:00
GUILayout . EndVertical ( ) ;
}
static void OnSaveGUI ( UnityModManager . ModEntry modEntry ) {
Settings . Save ( modEntry ) ;
}
2023-08-17 01:19:48 +00:00
// Logger Commands
public static void Log ( string message ) {
Instance . Logger . Log ( message ) ;
}
public static void Warning ( string message ) {
Instance . Logger . Warning ( message ) ;
}
public static void Error ( string message ) {
Instance . Logger . Error ( message ) ;
}
2023-08-13 21:03:01 +00:00
}