TechbloxModdingAPI/GamecraftModdingAPI/Tests/GamecraftModdingAPIPluginTest.cs

126 lines
6.1 KiB
C#
Raw Normal View History

2019-12-13 05:00:11 +00:00
using System;
using System.Reflection;
2019-12-14 18:52:24 +00:00
using Harmony;
// test
using Svelto.ECS;
using RobocraftX.Blocks;
using RobocraftX.Common;
using RobocraftX.SimulationModeState;
2019-12-15 07:20:20 +00:00
using GamecraftModdingAPI.Commands;
2019-12-14 18:52:24 +00:00
using GamecraftModdingAPI.Events;
using GamecraftModdingAPI.Utility;
2019-12-13 05:00:11 +00:00
2019-12-14 04:42:55 +00:00
namespace GamecraftModdingAPI.Tests
2019-12-13 05:00:11 +00:00
{
// unused by design
2019-12-15 07:20:20 +00:00
/// <summary>
/// Modding API implemented as a standalone IPA Plugin.
/// Ideally, GamecraftModdingAPI should be loaded by another mod; not itself
/// </summary>
2019-12-14 18:52:24 +00:00
public class GamecraftModdingAPIPluginTest
#if DEBUG
: IllusionPlugin.IEnhancedPlugin
#endif
2019-12-13 05:00:11 +00:00
{
2019-12-17 01:55:52 +00:00
private static HarmonyInstance harmony { get; set; }
2019-12-13 05:00:11 +00:00
public string[] Filter { get; } = new string[] { "Gamecraft" };
2019-12-14 18:52:24 +00:00
public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name;
2019-12-13 05:00:11 +00:00
2019-12-14 18:52:24 +00:00
public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();
2019-12-13 05:00:11 +00:00
public string HarmonyID { get; } = "org.git.exmods.modtainers.gamecraftmoddingapi";
public void OnApplicationQuit()
{
2019-12-14 04:42:55 +00:00
GamecraftModdingAPI.Main.Shutdown();
2019-12-13 05:00:11 +00:00
}
public void OnApplicationStart()
{
2019-12-14 04:42:55 +00:00
GamecraftModdingAPI.Main.Init();
2019-12-14 18:52:24 +00:00
// in case Steam is not installed/running
// this will crash the game slightly later during startup
//SteamInitPatch.ForcePassSteamCheck = true;
// in case running in a VM
//MinimumSpecsCheckPatch.ForcePassMinimumSpecCheck = true;
2019-12-17 02:31:03 +00:00
// disable background music
AudioTools.SetVolume(0.0f, "Music");
2019-12-14 18:52:24 +00:00
/*if (!FMODUnity.RuntimeManager.HasBankLoaded("Modded"))
{
FMODUnity.RuntimeManager.LoadBank("Modded", true);
}
FMODUnity.RuntimeManager.PlayOneShot("event:/ModEvents/KillDashNine3D");*/
2019-12-14 18:52:24 +00:00
// debug/test handlers
2019-12-15 07:20:20 +00:00
EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("App Inited event!"); }, () => { },
2019-12-14 18:52:24 +00:00
EventType.ApplicationInitialized, "appinit API debug"));
2019-12-15 07:20:20 +00:00
EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Menu Activated event!"); },
2019-12-14 18:52:24 +00:00
() => { Logging.Log("Menu Destroyed event!"); },
EventType.Menu, "menuact API debug"));
2019-12-15 07:20:20 +00:00
EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Menu Switched To event!"); }, () => { },
2019-12-14 18:52:24 +00:00
EventType.MenuSwitchedTo, "menuswitch API debug"));
2019-12-15 07:20:20 +00:00
EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Activated event!"); },
2019-12-14 18:52:24 +00:00
() => { Logging.Log("Game Destroyed event!"); },
EventType.Game, "gameact API debug"));
2019-12-15 07:20:20 +00:00
EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Reloaded event!"); }, () => { },
2019-12-14 18:52:24 +00:00
EventType.GameReloaded, "gamerel API debug"));
2019-12-15 07:20:20 +00:00
EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Switched To event!"); }, () => { },
2019-12-14 18:52:24 +00:00
EventType.GameSwitchedTo, "gameswitch API debug"));
2019-12-15 07:20:20 +00:00
// debug/test commands
CommandManager.AddCommand(new SimpleCustomCommandEngine(() => { UnityEngine.Application.Quit(); },
"Exit", "Close Gamecraft without any prompts"));
CommandManager.AddCommand(new SimpleCustomCommandEngine<float>((float d) => { UnityEngine.Camera.main.fieldOfView = d; },
"SetFOV", "Set the player camera's field of view"));
2019-12-17 01:55:52 +00:00
CommandManager.AddCommand(new SimpleCustomCommandEngine<float, float, float>(
(x,y,z) => {
bool success = GamecraftModdingAPI.Blocks.Movement.MoveConnectedBlocks(
GamecraftModdingAPI.Blocks.BlockIdentifiers.LatestBlockID,
new Unity.Mathematics.float3(x, y, z));
if (!success)
{
GamecraftModdingAPI.Utility.Logging.CommandLogError("Blocks can only be moved in Build mode!");
}
}, "MoveLastBlock", "Move the most-recently-placed block, and any connected blocks by the given offset"));
/*CommandManager.AddCommand(new SimpleCustomCommandEngine(() => { FMODUnity.RuntimeManager.PlayOneShot("event:/ModEvents/KillDashNine2D"); },
"Monzy", "Rap"));*/
2019-12-13 05:00:11 +00:00
}
public void OnFixedUpdate() { }
public void OnLateUpdate() { }
public void OnLevelWasInitialized(int level) { }
public void OnLevelWasLoaded(int level) { }
public void OnUpdate()
{
/*
if (db != null && signalStrength != 0.0f && db.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP).simulationMode == SimulationMode.Simulation)
{
//GamecraftModdingAPI.Utility.Logging.MetaDebugLog("Simulation frame update");
foreach (ref ElectricityEntityStruct powah in db.QueryEntities<ElectricityEntityStruct>(CommonExclusiveGroups.FUNCTIONAL_CUBES_IN_BOTH_SIM_AND_BUILD))
{
ref ConductiveClusterID clusterId = ref db.QueryEntity<ConductiveClusterIdStruct>(powah.ID).clusterId;
GamecraftModdingAPI.Utility.Logging.MetaDebugLog($"ID {powah.ID.entityID} unmodded values: Power* {powah.powerMultiplier} Conductivity* {powah.conductivityMultiplier} Output* {powah.outputSignalMultiplier}");
uint operatingChannel = db.QueryEntity<SignalOperatingChannelStruct>(powah.ID).operatingChannel;
if (operatingChannel != 0)
{
EGID eGID = new EGID(operatingChannel, CommonExclusiveGroups.CHANNEL_OUTPUT_SIGNAL_GROUPS + clusterId.ID);
if (db.Exists<ChannelOutputSignalDataStruct>(eGID))
{
db.QueryEntity<ChannelOutputSignalDataStruct>(eGID).outputSignal = signalStrength;
}
}
}
}*/
}
2019-12-13 05:00:11 +00:00
}
}