Skip to content

Commit

Permalink
theme dev
Browse files Browse the repository at this point in the history
  • Loading branch information
innominata committed Aug 31, 2021
1 parent 383249a commit 2edc8e4
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 41 deletions.
127 changes: 103 additions & 24 deletions GalacticScale2/Scripts/Bootstrap.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
using System;
using System.Collections;
using System.Collections;
using System.IO;
using System.Reflection;
using BepInEx;
using BepInEx.Logging;
using GSSerializer;
using HarmonyLib;
using UnityEngine;

namespace GalacticScale
{

public partial class GS2
{
public static int PreferencesVersion = 2104;
}


[BepInPlugin("dsp.galactic-scale.2", "Galactic Scale 2 Plug-In", VERSION)]
[BepInDependency("space.customizing.console", BepInDependency.DependencyFlags.SoftDependency)]
// [BepInDependency("nebula.api", BepInDependency.DependencyFlags.HardDependency)]
Expand All @@ -24,14 +23,14 @@ public class Bootstrap : BaseUnityPlugin
public const string VERSION = "2.1.13.0";

public new static ManualLogSource Logger;

// Internal Variables
public static Queue buffer = new Queue();
public static PlanetData TeleportPlanet;
public static StarData TeleportStar;
public static bool TeleportEnabled;
public static int timer;

internal void Awake()
{
var v = Assembly.GetExecutingAssembly().GetName().Version;
Expand Down Expand Up @@ -101,22 +100,105 @@ private void FixedUpdate()
// {
// if (GameMain.localPlanet != null && GameMain.mainPlayer != null) GS2.Warn((GameMain.localPlanet.uPosition - GameMain.mainPlayer.uPosition).magnitude + " distance");
// }
if (GS2.Config.Dev && VFInput.control && VFInput.shift && VFInput._rotate)
if (VFInput.control && VFInput.alt && VFInput.shift && VFInput._moveRight)
{
GS2.Config.EnableDevMode();
}
if (GS2.Config.Dev && VFInput.control && VFInput.shift && VFInput._rotate && GameMain.localPlanet != null)
{
if (!GameMain.isPaused && !DSPGame.IsMenuDemo)
var filename = Path.Combine(GS2.DataDir, "WorkingTheme.json");
if (!File.Exists(filename))
{

GameMain.Pause();
UIRoot.instance.uiGame.escMenu._Open();
var oldTheme = GS2.GetGSPlanet(GameMain.localPlanet).GsTheme;
var fs = new fsSerializer();
fs.TrySerialize(oldTheme, out var data);
var json = fsJsonPrinter.PrettyJson(data);
File.WriteAllText(filename, json);
GS2.ShowMessage("WorkingTheme.json has been exported. Use the same key combination to reload it");
return;
}
else if (!GameMain.isPaused)
{
GameMain.Pause();
GameMain.mainPlayer.controller.movementStateInFrame = EMovementState.Sail;
GameMain.mainPlayer.controller.actionSail.ResetSailState();
GameCamera.instance.SyncForSailMode();
// if (!GameMain.isPaused && !DSPGame.IsMenuDemo)
// {
//
// GameMain.Pause();
// UIRoot.instance.uiGame.escMenu._Open();
// }
// else if (!GameMain.isPaused)
// {
// GameMain.Pause();
//
// }
// UIRoot.instance.OpenOptionWindow();
// GS2.Warn($"********* Loading {GS2.Config.ImportFilename}");
// GS2.Config.LoadJsonGalaxy(GS2.Config.ImportFilename);
var p = GameMain.localStar.planets[GameMain.localPlanet.index];
var gsPlanet = GS2.GetGSPlanet(p);
GS2.GetGSStar(p.star).counter = p.index;
// GameMain.localPlanet.Unload();
// PlanetModelingManager.currentModelingStage = 0;
// PlanetModelingManager.currentModelingSeamNormal = 0;
// PlanetModelingManager.currentModelingPlanet = p;
var newTheme = GS2.LoadJsonTheme(filename);
GS2.Warn($"LOADED THEME {newTheme.Name} CustomGen:{newTheme.CustomGeneration} TA:{newTheme.TerrainSettings.Algorithm}");
newTheme.Process();
gsPlanet.Theme = newTheme.Name;

}
UIRoot.instance.OpenOptionWindow();
GS2.Warn($"********* Loading {GS2.Config.ImportFilename}");
GS2.Config.LoadJsonGalaxy(GS2.Config.ImportFilename);
// var t = GS2.GetGSPlanet(p).GsTheme;
// t.initialized = false;
// t.terrainMaterial.Tint = Color.red;
// t.oceanMaterial.Tint = Color.green;
// t.terrainMaterial.CopyFrom = "GasGiant.terrainMat";
// t.terrainMat = null;
// t.oceanMat = null;
// t.atmosMat = null;
// t.minimapMat = null;
// t.thumbMat = null;
//
// p.terrainMaterial = null;
// p.oceanMaterial = null;
// p.atmosMaterial = null;
// p.minimapMaterial = null;
// t.Process();
// int themeId = newTheme.UpdateThemeProtoSet();
// p.star.planets[p.index] = GS2.CreatePlanet(ref p.star, GS2.GetGSPlanet(p), new GS2.Random(p.seed));
p.Free();
p.data = null;
p.factory = null;
p.terrainMaterial = null;
p.oceanMaterial = null;
p.atmosMaterial = null;
p.minimapMaterial = null;
// p.theme = themeId;
GS2.SetPlanetTheme(p, gsPlanet);
// p.data = new PlanetRawData((int)(p.radius/4)*4);
GameMain.localStar.planets[p.index] = p;
gsPlanet.planetData = p;
PlanetModelingManager.RequestLoadPlanet(p);
GameMain.data.LeavePlanet();
// GS2.Warn(t.terrainMaterial.Tint.ToString());
// p.Unload();
// UnityEngine.Object.Destroy(p.gameObject);
// // GameMain.data.ArrivePlanet(p);
// PlanetModelingManager.RequestLoadPlanet(p);
// if (PlanetModelingManager.currentModelingPlanet != null)
// {
// try
// {
// PlanetModelingManager.ModelingPlanetMain(PlanetModelingManager.currentModelingPlanet);
// }
// catch (Exception message)
// {
// GS2.Warn(message.ToString());
// PlanetModelingManager.currentModelingPlanet.Unload();
// PlanetModelingManager.currentModelingPlanet.factoryLoaded = false;
// PlanetModelingManager.currentModelingPlanet = null;
// PlanetModelingManager.currentModelingStage = 0;
// PlanetModelingManager.currentModelingSeamNormal = 0;
// }
// }
}

timer++;
Expand All @@ -125,8 +207,7 @@ private void FixedUpdate()
//GS2.Warn("FixedUpdate");
if (!GS2.Config.CheatMode) return;
if (DSPGame.IsMenuDemo) return;
if (TeleportStar == null && TeleportPlanet == null || TeleportEnabled == false ||
!(GameMain.localStar != null && GameMain.localStar.loaded)) return;
if (TeleportStar == null && TeleportPlanet == null || TeleportEnabled == false || !(GameMain.localStar != null && GameMain.localStar.loaded)) return;
if (TeleportPlanet != null)
{
GS2.Warn($"TP to Planet {TeleportPlanet?.name} of star {TeleportPlanet?.star?.name}");
Expand All @@ -151,7 +232,7 @@ public static void Debug(object data, LogLevel logLevel, bool isActive)
while (buffer.Count > 0)
{
var o = buffer.Dequeue();
var l = ((object data, LogLevel loglevel, bool isActive)) o;
var l = ((object data, LogLevel loglevel, bool isActive))o;
if (l.isActive) Logger.Log(l.loglevel, "Q:" + l.data);
}

Expand Down Expand Up @@ -191,7 +272,5 @@ private IEnumerator Teleport(StarData star)
GameMain.mainPlayer.transform.localScale = Vector3.one;
GameCamera.instance.FrameLogic();
}


}
}
4 changes: 4 additions & 0 deletions GalacticScale2/Scripts/GalacticScale2.0/Init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ public static void Init()
Log("End");
}

public static void ShowMessage(string message, string title = "Galactic Scale", string button = "OK")
{
UIMessageBox.Show(title.Translate(), message.Translate(), button.Translate(), 0);
}
public static void OnMenuLoaded()
{
if (MenuHasLoaded) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@ public partial class PatchOnPlanetModelingManager
[HarmonyPatch(typeof(PlanetModelingManager), "Algorithm")]
public static bool Algorithm(PlanetData planet, ref PlanetAlgorithm __result)
{
//GS2.Log("Start");
// GS2.Log("Start");
if (DSPGame.IsMenuDemo) return true;

if (GS2.Vanilla) return true;
//GS2.Log("CHOOSING ALGORITHM FOR " + planet.displayName + " rawdata?"+(planet.data != null));
// GS2.Log("CHOOSING ALGORITHM FOR " + planet.displayName + " rawdata?"+(planet.data != null));
var gsPlanet = GS2.GetGSPlanet(planet);
GS2.Warn(gsPlanet.Theme);
var gsTheme = GS2.ThemeLibrary.Find(gsPlanet.Theme);
//GS2.Log("Use Custom Generation? " + gsTheme.CustomGeneration);
// GS2.Log("Use Custom Generation? " + gsTheme.CustomGeneration);
if (!GS2.ThemeLibrary.Find(gsPlanet.Theme).CustomGeneration)
//GS2.Log("CHOSE COMPLETELY VANILLA");
{
// GS2.Log("CHOSE COMPLETELY VANILLA");
return true;
//GS2.Log("USING CUSTOM GENERATION FOR PLANET " + planet.displayName);
}
// GS2.Log("USING CUSTOM GENERATION FOR PLANET " + planet.displayName);
__result = new GS2PlanetAlgorithm(gsPlanet); //new GS2PlanetAlgorithm(gsPlanet);
__result.Reset(5, planet);
//GS2.Log("PatchOnPlanetModellingManager|Algorithm|" + __result.planet.name+"|End|"+__result.seed);
// GS2.Log("PatchOnPlanetModellingManager|Algorithm|" + __result.planet.name+"|End|"+__result.seed);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public partial class PatchOnPlanetModelingManager
[HarmonyPatch(typeof(PlanetModelingManager), "ModelingPlanetCoroutine")]
public static bool ModelingPlanetCoroutine()
{
// GS2.Log("ModelingPlanetCoroutine");
Modeler.ModelingCoroutine();
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static bool UpdateUniversalPosition(ref PlanetSimulator __instance, ref S
Vector3 cameraPos)
{
if (__instance.planetData == null || __instance.planetData.loading ||
__instance.planetData.factoryLoading) return false;
__instance.planetData.factoryLoading || __instance.planetData == PlanetModelingManager.currentModelingPlanet) return false;

__instance.SetLayers();
var localPlanet = GameMain.localPlanet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private static double distanceTo(PlanetData planet)
public static bool Compute(ref ThreadFlag ___planetComputeThreadFlag,
ref ThreadFlagLock ___planetComputeThreadFlagLock, ref Thread ___planetComputeThread)
{
GS2.Log("Compute");
object obj = null;
lock (planetComputeThreadFlagLock)
{
Expand Down Expand Up @@ -94,18 +95,21 @@ public static bool Compute(ref ThreadFlag ___planetComputeThreadFlag,
var num4 = 0.0;
if (planetData.data == null)
{
GS2.Log($"Creating Planet {planetData.name}");
highStopwatch.Begin();
planetData.data = new PlanetRawData(planetData.precision);
planetData.modData = planetData.data.InitModData(planetData.modData);
planetData.data.CalcVerts();
planetData.aux = new PlanetAuxData(planetData);
GS2.Log("Generating Terrain");
planetAlgorithm.GenerateTerrain(planetData.mod_x, planetData.mod_y);
planetAlgorithm.CalcWaterPercent();
num2 = highStopwatch.duration;
}

if (planetData.factory == null)
{
GS2.Log("Creating Factory");
highStopwatch.Begin();
if (planetData.type != EPlanetType.Gas) planetAlgorithm.GenerateVegetables();
num3 = highStopwatch.duration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class GS2PlanetAlgorithm : PlanetAlgorithm

public GS2PlanetAlgorithm(GSPlanet gsPlanet)
{
//GS2.Log("GS2PlanetAlgorithm|Constructor|Begin");
//GS2.Log("GS2PlanetAlgorithm|Constructor|CREATING CUSTOM PLANET ALGORITHM FOR " + gsPlanet.Name);
GS2.Log("GS2PlanetAlgorithm|Constructor|Begin");
GS2.Log("GS2PlanetAlgorithm|Constructor|CREATING CUSTOM PLANET ALGORITHM FOR " + gsPlanet.Name);
//GS2.Log("GS2PlanetAlgorithm|Constructor|Selecting Theme " + gsPlanet.Theme);
var gSTheme = GSSettings.ThemeLibrary.Find(gsPlanet.Theme);
//GS2.Log("GS2PlanetAlgorithm|Constructor|Selected Theme");
Expand All @@ -26,16 +26,20 @@ public GS2PlanetAlgorithm(GSPlanet gsPlanet)
//GS2.Log("GS2PlanetAlgorithm|Constructor|Terrain Algo: " + gsTheme.TerrainSettings.Algorithm + " Vein Algo: " + gsTheme.VeinSettings.Algorithm + " Vege Algo: " + gsTheme.VegeSettings.Algorithm);

if (gsTheme.TerrainSettings.Algorithm == "Vanilla")
//GS2.Log("GS2PlanetAlgorithm|Constructor|Terrain Algo Being Set to Vanilla");
{
GS2.Log("GS2PlanetAlgorithm|Constructor|Terrain Algo Being Set to Vanilla");
terrainAlgo = (p, modX, modY) =>
{
//GS2.Log("GS2PlanetAlgorithm|Constructor|Vanilla Terrain Algo Running");
baseAlgorithm.GenerateTerrain(modX, modY);
};
}
else
//GS2.Log("GS2PlanetAlgorithm|Constructor|Terrain Algo Being Set to " + gsTheme.TerrainSettings.Algorithm);
{
GS2.Log("GS2PlanetAlgorithm|Constructor|Terrain Algo Being Set to " + gsTheme.TerrainSettings.Algorithm);
terrainAlgo = GS2.TerrainAlgorithmLibrary.Find(gsTheme.TerrainSettings.Algorithm);
//this.terrainAlgo = (gsTheme.TerrainSettings.Algorithm == "Vanilla") ? (GSPlanet p, double modX, double modY) => { baseAlgorithm.GenerateTerrain(modX, modY); } :
//this.}terrainAlgo = (gsTheme.TerrainSettings.Algorithm == "Vanilla") ? (GSPlanet p, double modX, double modY) => { baseAlgorithm.GenerateTerrain(modX, modY); } :
}

if (gsTheme.VeinSettings.Algorithm == "Vanilla")
veinAlgo = (p, sketchOnly) =>
Expand All @@ -49,11 +53,16 @@ public GS2PlanetAlgorithm(GSPlanet gsPlanet)
if (gsTheme.VegeSettings.Algorithm == "Vanilla")
vegeAlgo = p =>
{
//GS2.Log("GS2PlanetAlgorithm|Constructor|Vanilla Vege Algo Running");
GS2.Log("GS2PlanetAlgorithm|Constructor|Vanilla Vege Algo Running");
baseAlgorithm.GenerateVegetables();
};
else
{
GS2.Log("GS2PlanetAlgorithm|Constructor|GS Vege Algo Running");

vegeAlgo = GS2.VegeAlgorithmLibrary.Find(gsTheme.VegeSettings.Algorithm);
GS2.Warn("NonstandardVegealgo");
}

//this.vegeAlgo = (gsTheme.VegeSettings.Algorithm == "Vanilla") ? (GSPlanet p) => {
// GS2.Log("GS2.VeinAlgorithmLibrary.Find(gsTheme.VegeSettings.Algorithm);")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public bool MinifyJson
set => Preferences.Set("Minify JSON", value);
}

public void EnableDevMode()
{
Preferences.Set("Dev", true);
GS2.SavePreferences();
}

public bool FixCopyPaste => true; //Preferences.GetBool("Fix CopyPaste", true);
public string GeneratorID => Preferences.GetString("Generator ID", "space.customizing.generators.vanilla");
Expand Down Expand Up @@ -149,7 +154,13 @@ public void Init()
DebugOptions.Add(GSUI.Checkbox("Force Rare Spawn".Translate(), false, "Force Rare Spawn", null, "Ignore randomness/distance checks".Translate()));
_cheatModeCheckbox = DebugOptions.Add(GSUI.Checkbox("Cheat Mode".Translate(), false, "Cheat Mode", null, "All Research, TP by ctrl-click nav arrow".Translate()));
DebugOptions.Add(GSUI.Slider("Ship Speed Multiplier".Translate(), 1f, 1f, 100f, "Logistics Ship Multi", null, "Multiplier for Warp Speed of Ships".Translate()));
// DebugOptions.Add(GSUI.Button("Fix Binary Star Position".Translate(), "Now", ResetBinaryStars, null, "Will need to be saved and loaded to apply".Translate()));
DebugOptions.Add(GSUI.Button("Set ResourceMulti Infinite".Translate(), "Now", (o)=>
{
// GS2.WarnJson(gameDesc);
gameDesc.resourceMultiplier = 100;
GSSettings.GalaxyParams.resourceMulti = 100;
GS2.WarnJson(gameDesc.resourceMultiplier);
}, null, "Will need to be saved and loaded to apply".Translate()));
// DebugOptions.Add(GSUI.Button("Test", "Now", (o) =>
// {
// Warn("ExternalThemes:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static void GenerateTerrain6(GSPlanet gsPlanet, double modX = 0.0, double
{
if (gsPlanet == null) {GS2.Warn("gsPlanet Null");return;}
random = new GS2.Random(gsPlanet.Seed);
// GS2.Log($"USING GSTA6 FOR {gsPlanet.Name} with seed {GSSettings.Seed}");
GS2.Log($"USING GSTA6 FOR {gsPlanet.Name} with seed {GSSettings.Seed}");
var t = gsPlanet.GsTheme.TerrainSettings;
//GS2.Log("Generate Terrain for "+gsPlanet.Name + " " + t.landModifier );
var xPrecision = t.xFactor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private static void SearchPlanet()
var planet = closestStar.planets[i];
if (DistanceTo(planet) < TransisionDistance(planet))
{
GS2.Log($"Switching to {planet.name}");
// GS2.Log($"Switching to {planet.name}");
closestPlanet = planet;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class VegeAlgorithms

public static void GenerateVeges1(GSPlanet gsPlanet)
{
//GS2.Log("GenerateVeges1|" + gsPlanet.Name);
GS2.Log("GenerateVeges1|" + gsPlanet.Name);
GS2.Warn($"USING GS2 Vege FOR {gsPlanet.Name} with seed {GSSettings.Seed}");
var planet = gsPlanet.planetData;
var themeProto = LDB.themes.Select(planet.theme);
Expand Down

0 comments on commit 2edc8e4

Please sign in to comment.