Merge branch 'dev' into profiler
BIN
NewHorizons/Assets/DefaultMapModNoAtmoOutline.png
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
NewHorizons/Assets/DefaultMapModePlanetOutline.png
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
NewHorizons/Assets/DefaultMapModeStarOutline.png
Normal file
|
After Width: | Height: | Size: 9.8 KiB |
BIN
NewHorizons/Assets/textures/CloudEntry_GD_Island_d.png
Normal file
|
After Width: | Height: | Size: 2.9 MiB |
BIN
NewHorizons/Assets/textures/CloudExit__PlayerShip_d.png
Normal file
|
After Width: | Height: | Size: 2.9 MiB |
|
Before Width: | Height: | Size: 3.8 MiB After Width: | Height: | Size: 3.4 MiB |
|
Before Width: | Height: | Size: 3.3 MiB |
|
Before Width: | Height: | Size: 3.2 MiB After Width: | Height: | Size: 2.5 MiB |
|
Before Width: | Height: | Size: 2.4 MiB |
@ -1,14 +1,12 @@
|
||||
using NewHorizons.Components.ShipLog;
|
||||
using NewHorizons.External;
|
||||
using NewHorizons.External.Modules;
|
||||
using NewHorizons.External.Modules.VariableSize;
|
||||
using NewHorizons.Handlers;
|
||||
using NewHorizons.Utility;
|
||||
using NewHorizons.Utility.Files;
|
||||
using NewHorizons.Utility.OuterWilds;
|
||||
using NewHorizons.Utility.OWML;
|
||||
using OWML.ModHelper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
@ -195,10 +193,10 @@ namespace NewHorizons.Builder.ShipLog
|
||||
string outlinePath = body.Config.ShipLog?.mapMode?.outlineSprite;
|
||||
|
||||
if (imagePath != null) image = ImageUtilities.GetTexture(body.Mod, imagePath);
|
||||
if (image == null) image = AutoGenerateMapModePicture(body);
|
||||
if (image == null) image = ImageUtilities.AutoGenerateMapModePicture(body);
|
||||
|
||||
if (outlinePath != null) outline = ImageUtilities.GetTexture(body.Mod, outlinePath);
|
||||
if (outline == null) outline = ImageUtilities.MakeOutline(image, Color.white, 10);
|
||||
if (outline == null) outline = ImageUtilities.GetCachedOutlineOrCreate(body, image, imagePath);
|
||||
|
||||
astroObject._imageObj = CreateImage(gameObject, image, body.Config.name + " Revealed", layer);
|
||||
astroObject._outlineObj = CreateImage(gameObject, outline, body.Config.name + " Outline", layer);
|
||||
@ -246,10 +244,10 @@ namespace NewHorizons.Builder.ShipLog
|
||||
string outlinePath = info.outlineSprite;
|
||||
|
||||
if (imagePath != null) image = ImageUtilities.GetTexture(body.Mod, imagePath);
|
||||
else image = AutoGenerateMapModePicture(body);
|
||||
else image = ImageUtilities.AutoGenerateMapModePicture(body);
|
||||
|
||||
if (outlinePath != null) outline = ImageUtilities.GetTexture(body.Mod, outlinePath);
|
||||
else outline = ImageUtilities.MakeOutline(image, Color.white, 10);
|
||||
else outline = ImageUtilities.GetCachedOutlineOrCreate(body, image, imagePath);
|
||||
|
||||
Image revealedImage = CreateImage(detailGameObject, image, "Detail Revealed", parent.gameObject.layer).GetComponent<Image>();
|
||||
Image outlineImage = CreateImage(detailGameObject, outline, "Detail Outline", parent.gameObject.layer).GetComponent<Image>();
|
||||
@ -605,68 +603,6 @@ namespace NewHorizons.Builder.ShipLog
|
||||
}
|
||||
#endregion
|
||||
|
||||
private static Texture2D AutoGenerateMapModePicture(NewHorizonsBody body)
|
||||
{
|
||||
Texture2D texture;
|
||||
|
||||
if (body.Config.Star != null) texture = ImageUtilities.GetTexture(Main.Instance, "Assets/DefaultMapModeStar.png");
|
||||
else if (body.Config.Atmosphere != null) texture = ImageUtilities.GetTexture(Main.Instance, "Assets/DefaultMapModNoAtmo.png");
|
||||
else texture = ImageUtilities.GetTexture(Main.Instance, "Assets/DefaultMapModePlanet.png");
|
||||
|
||||
var color = GetDominantPlanetColor(body);
|
||||
var darkColor = new Color(color.r / 3f, color.g / 3f, color.b / 3f);
|
||||
|
||||
texture = ImageUtilities.LerpGreyscaleImage(texture, color, darkColor);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
private static Color GetDominantPlanetColor(NewHorizonsBody body)
|
||||
{
|
||||
try
|
||||
{
|
||||
var starColor = body.Config?.Star?.tint;
|
||||
if (starColor != null) return starColor.ToColor();
|
||||
|
||||
var atmoColor = body.Config.Atmosphere?.atmosphereTint;
|
||||
if (body.Config.Atmosphere?.clouds != null && atmoColor != null) return atmoColor.ToColor();
|
||||
|
||||
if (body.Config?.HeightMap?.textureMap != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var texture = ImageUtilities.GetTexture(body.Mod, body.Config.HeightMap.textureMap);
|
||||
var landColor = ImageUtilities.GetAverageColor(texture);
|
||||
if (landColor != null) return landColor;
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
var waterColor = body.Config.Water?.tint;
|
||||
if (waterColor != null) return waterColor.ToColor();
|
||||
|
||||
var lavaColor = body.Config.Lava?.tint;
|
||||
if (lavaColor != null) return lavaColor.ToColor();
|
||||
|
||||
var sandColor = body.Config.Sand?.tint;
|
||||
if (sandColor != null) return sandColor.ToColor();
|
||||
|
||||
switch (body.Config?.Props?.singularities?.FirstOrDefault()?.type)
|
||||
{
|
||||
case SingularityModule.SingularityType.BlackHole:
|
||||
return Color.black;
|
||||
case SingularityModule.SingularityType.WhiteHole:
|
||||
return Color.white;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
NHLogger.LogWarning($"Something went wrong trying to pick the colour for {body.Config.name} but I'm too lazy to fix it.");
|
||||
}
|
||||
|
||||
return Color.white;
|
||||
}
|
||||
|
||||
#region Replacement
|
||||
private static List<(NewHorizonsBody, ModBehaviour, MapModeInfo)> _mapModIconsToUpdate = new();
|
||||
public static void TryReplaceExistingMapModeIcon(NewHorizonsBody body, ModBehaviour mod, MapModeInfo info)
|
||||
|
||||
265
NewHorizons/Components/SplashColourizer.cs
Normal file
@ -0,0 +1,265 @@
|
||||
using NewHorizons.External.Configs;
|
||||
using NewHorizons.External.SerializableData;
|
||||
using NewHorizons.Utility;
|
||||
using NewHorizons.Utility.Files;
|
||||
using NewHorizons.Utility.OuterWilds;
|
||||
using NewHorizons.Utility.OWML;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NewHorizons.Components;
|
||||
|
||||
/// <summary>
|
||||
/// When a Fluid Detector enters this volume, it's splash effects will get colourized to match whats on this planet
|
||||
/// </summary>
|
||||
public class SplashColourizer : MonoBehaviour
|
||||
{
|
||||
public float _radius;
|
||||
|
||||
private SphereShape _sphereShape;
|
||||
|
||||
private Dictionary<SplashEffect, GameObject> _cachedOriginalPrefabs = new();
|
||||
private Dictionary<SplashEffect, GameObject> _cachedModifiedPrefabs = new();
|
||||
|
||||
private FluidDetector _playerDetector, _shipDetector, _probeDetector;
|
||||
|
||||
private MColor _waterColour, _cloudColour, _plasmaColour, _sandColour;
|
||||
|
||||
private GameObject _prefabHolder;
|
||||
|
||||
private bool _probeInsideVolume;
|
||||
|
||||
private List<Texture> _customTextures = new();
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
var volume = new GameObject("Volume");
|
||||
volume.transform.parent = transform;
|
||||
volume.transform.localPosition = Vector3.zero;
|
||||
volume.layer = Layer.BasicEffectVolume;
|
||||
|
||||
_sphereShape = gameObject.AddComponent<SphereShape>();
|
||||
_sphereShape.radius = _radius;
|
||||
|
||||
volume.AddComponent<OWTriggerVolume>();
|
||||
|
||||
_prefabHolder = new GameObject("Prefabs");
|
||||
_prefabHolder.SetActive(false);
|
||||
}
|
||||
|
||||
public static void Make(GameObject planet, PlanetConfig config, float soi)
|
||||
{
|
||||
var water = config.Water?.tint;
|
||||
var cloud = config.Atmosphere?.clouds?.tint;
|
||||
var plasma = config.Lava?.tint ?? config.Star?.tint;
|
||||
var sand = config.Sand?.tint;
|
||||
|
||||
if (water != null || cloud != null || plasma != null || sand != null)
|
||||
{
|
||||
var size = Mathf.Max(
|
||||
soi / 1.5f,
|
||||
config.Water?.size ?? 0f,
|
||||
config.Atmosphere?.clouds?.outerCloudRadius ?? 0f,
|
||||
config.Lava?.size ?? 0f,
|
||||
config.Star?.size ?? 0f,
|
||||
config.Sand?.size ?? 0f
|
||||
) * 1.5f;
|
||||
|
||||
var colourizer = planet.AddComponent<SplashColourizer>();
|
||||
|
||||
colourizer._radius = size;
|
||||
if (colourizer._sphereShape != null) colourizer._sphereShape.radius = size;
|
||||
|
||||
colourizer._waterColour = water;
|
||||
colourizer._cloudColour = cloud;
|
||||
colourizer._plasmaColour = plasma;
|
||||
colourizer._sandColour = sand;
|
||||
}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
// Cache all prefabs
|
||||
CachePrefabs(_playerDetector = Locator.GetPlayerDetector().GetComponent<DynamicFluidDetector>());
|
||||
CachePrefabs(_shipDetector = Locator.GetShipDetector().GetComponent<ShipFluidDetector>());
|
||||
CachePrefabs(_probeDetector = Locator.GetProbe().GetDetectorObject().GetComponent<ProbeFluidDetector>());
|
||||
|
||||
GlobalMessenger<SurveyorProbe>.AddListener("RetrieveProbe", OnRetrieveProbe);
|
||||
|
||||
// Check if player/ship are already inside
|
||||
if ((_playerDetector.transform.position - transform.position).magnitude < _radius)
|
||||
{
|
||||
SetSplashEffects(_playerDetector, true);
|
||||
}
|
||||
if ((_shipDetector.transform.position - transform.position).magnitude < _radius)
|
||||
{
|
||||
SetSplashEffects(_shipDetector, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
GlobalMessenger<SurveyorProbe>.RemoveListener("RetrieveProbe", OnRetrieveProbe);
|
||||
}
|
||||
|
||||
private void OnRetrieveProbe(SurveyorProbe probe)
|
||||
{
|
||||
if (_probeInsideVolume)
|
||||
{
|
||||
// Else it never leaves the volume
|
||||
SetProbeSplashEffects(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnTriggerEnter(Collider hitCollider) => OnEnterExit(hitCollider, true);
|
||||
|
||||
public void OnTriggerExit(Collider hitCollider) => OnEnterExit(hitCollider, false);
|
||||
|
||||
/// <summary>
|
||||
/// The probe keeps being null idgi
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool IsProbeLaunched()
|
||||
{
|
||||
return Locator.GetProbe()?.IsLaunched() ?? false;
|
||||
}
|
||||
|
||||
private void OnEnterExit(Collider hitCollider, bool entering)
|
||||
{
|
||||
if (!enabled) return;
|
||||
|
||||
if (hitCollider.attachedRigidbody != null)
|
||||
{
|
||||
var isPlayer = hitCollider.attachedRigidbody.CompareTag("Player");
|
||||
var isShip = hitCollider.attachedRigidbody.CompareTag("Ship");
|
||||
var isProbe = hitCollider.attachedRigidbody.CompareTag("Probe");
|
||||
|
||||
if (isPlayer)
|
||||
{
|
||||
SetSplashEffects(_playerDetector, entering);
|
||||
if (IsProbeLaunched())
|
||||
{
|
||||
SetProbeSplashEffects(entering);
|
||||
}
|
||||
}
|
||||
else if (isShip)
|
||||
{
|
||||
SetSplashEffects(_shipDetector, entering);
|
||||
if (PlayerState.IsInsideShip())
|
||||
{
|
||||
SetSplashEffects(_playerDetector, entering);
|
||||
}
|
||||
if (IsProbeLaunched())
|
||||
{
|
||||
SetProbeSplashEffects(entering);
|
||||
}
|
||||
}
|
||||
else if (isProbe)
|
||||
{
|
||||
SetProbeSplashEffects(entering);
|
||||
}
|
||||
|
||||
// If the probe isn't launched we always consider it as being inside the volume
|
||||
if (isProbe || !IsProbeLaunched())
|
||||
{
|
||||
_probeInsideVolume = entering;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void CachePrefabs(FluidDetector detector)
|
||||
{
|
||||
foreach (var splashEffect in detector._splashEffects)
|
||||
{
|
||||
if (!_cachedOriginalPrefabs.ContainsKey(splashEffect))
|
||||
{
|
||||
_cachedOriginalPrefabs[splashEffect] = splashEffect.splashPrefab;
|
||||
}
|
||||
if (!_cachedModifiedPrefabs.ContainsKey(splashEffect))
|
||||
{
|
||||
Color? colour = null;
|
||||
if (splashEffect.fluidType == FluidVolume.Type.CLOUD)
|
||||
{
|
||||
colour = _cloudColour?.ToColor();
|
||||
}
|
||||
switch(splashEffect.fluidType)
|
||||
{
|
||||
case FluidVolume.Type.CLOUD:
|
||||
colour = _cloudColour?.ToColor();
|
||||
break;
|
||||
case FluidVolume.Type.WATER:
|
||||
colour = _waterColour?.ToColor();
|
||||
break;
|
||||
case FluidVolume.Type.PLASMA:
|
||||
colour = _plasmaColour?.ToColor();
|
||||
break;
|
||||
case FluidVolume.Type.SAND:
|
||||
colour = _sandColour?.ToColor();
|
||||
break;
|
||||
}
|
||||
|
||||
if (colour is Color tint)
|
||||
{
|
||||
var flagError = false;
|
||||
var prefab = splashEffect.splashPrefab.InstantiateInactive();
|
||||
var meshRenderers = prefab.GetComponentsInChildren<MeshRenderer>(true);
|
||||
foreach (var meshRenderer in meshRenderers)
|
||||
{
|
||||
if (_customTextures.Contains(meshRenderer.material.mainTexture))
|
||||
{
|
||||
// Might be some shared material stuff? This image is already tinted, so skip it
|
||||
continue;
|
||||
}
|
||||
|
||||
// Can't access the textures in memory so we need to have our own copies
|
||||
var texture = ImageUtilities.GetTexture(Main.Instance, $"Assets/textures/{meshRenderer.material.mainTexture.name}.png");
|
||||
if (texture == null)
|
||||
{
|
||||
NHLogger.LogError($"Go tell an NH dev to add this image texture to the mod because I can't be bothered to until somebody complains: {meshRenderer.material.mainTexture.name}");
|
||||
GameObject.Destroy(prefab);
|
||||
flagError = true;
|
||||
}
|
||||
|
||||
_customTextures.Add(texture);
|
||||
|
||||
meshRenderer.material = new(meshRenderer.material)
|
||||
{
|
||||
color = Color.white,
|
||||
mainTexture = ImageUtilities.TintImage(texture, tint)
|
||||
};
|
||||
}
|
||||
|
||||
if (flagError) continue;
|
||||
|
||||
// Have to be active when being used by the base game classes but can't be seen
|
||||
// Keep them active as children of an inactive game object
|
||||
prefab.transform.parent = _prefabHolder.transform;
|
||||
prefab.SetActive(true);
|
||||
|
||||
_cachedModifiedPrefabs[splashEffect] = prefab;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSplashEffects(FluidDetector detector, bool entering)
|
||||
{
|
||||
NHLogger.LogVerbose($"Body {detector.name} {(entering ? "entered" : "left")} colourizing volume on {name}");
|
||||
|
||||
foreach (var splashEffect in detector._splashEffects)
|
||||
{
|
||||
var prefabs = entering ? _cachedModifiedPrefabs : _cachedOriginalPrefabs;
|
||||
if (prefabs.TryGetValue(splashEffect, out var prefab))
|
||||
{
|
||||
splashEffect.splashPrefab = prefab;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetProbeSplashEffects(bool entering)
|
||||
{
|
||||
_probeInsideVolume = entering;
|
||||
|
||||
SetSplashEffects(_probeDetector, entering);
|
||||
}
|
||||
}
|
||||
@ -61,7 +61,7 @@ namespace NewHorizons.External.Modules
|
||||
public float offset;
|
||||
|
||||
/// <summary>
|
||||
/// The path to the sprite (.png/.jpg/.exr) to show when the planet is unexplored in map mode.
|
||||
/// The path to the sprite (.png/.jpg/.exr) to show when the planet is unexplored in map mode. If empty, a texture will be created and cached based on the revealed sprite.
|
||||
/// </summary>
|
||||
public string outlineSprite;
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ using UnityEngine.SceneManagement;
|
||||
|
||||
namespace NewHorizons.Handlers
|
||||
{
|
||||
internal class InvulnerabilityHandler
|
||||
public static class InvulnerabilityHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Used in patches
|
||||
@ -32,8 +32,25 @@ namespace NewHorizons.Handlers
|
||||
}
|
||||
}
|
||||
|
||||
private static DeathManager GetDeathManager() => GameObject.FindObjectOfType<DeathManager>();
|
||||
private static PlayerResources GetPlayerResouces() => GameObject.FindObjectOfType<PlayerResources>();
|
||||
private static DeathManager _deathManager;
|
||||
private static DeathManager GetDeathManager()
|
||||
{
|
||||
if (_deathManager == null)
|
||||
{
|
||||
_deathManager = GameObject.FindObjectOfType<DeathManager>();
|
||||
}
|
||||
return _deathManager;
|
||||
}
|
||||
|
||||
private static PlayerResources _playerResources;
|
||||
private static PlayerResources GetPlayerResouces()
|
||||
{
|
||||
if (_playerResources == null)
|
||||
{
|
||||
_playerResources = GameObject.FindObjectOfType<PlayerResources>();
|
||||
}
|
||||
return _playerResources;
|
||||
}
|
||||
|
||||
static InvulnerabilityHandler()
|
||||
{
|
||||
|
||||
@ -20,6 +20,10 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using NewHorizons.Streaming;
|
||||
using Newtonsoft.Json;
|
||||
using NewHorizons.External.Modules.VariableSize;
|
||||
using NewHorizons.Components;
|
||||
|
||||
namespace NewHorizons.Handlers
|
||||
{
|
||||
@ -767,6 +771,8 @@ namespace NewHorizons.Handlers
|
||||
SpawnPointBuilder.Make(go, body.Config.Spawn, rb);
|
||||
}
|
||||
|
||||
SplashColourizer.Make(go, body.Config, sphereOfInfluence);
|
||||
|
||||
// We allow removing children afterwards so you can also take bits off of the modules you used
|
||||
if (body.Config.removeChildren != null) RemoveChildren(go, body);
|
||||
|
||||
|
||||
@ -4751,7 +4751,7 @@
|
||||
},
|
||||
"outlineSprite": {
|
||||
"type": "string",
|
||||
"description": "The path to the sprite (.png/.jpg/.exr) to show when the planet is unexplored in map mode."
|
||||
"description": "The path to the sprite (.png/.jpg/.exr) to show when the planet is unexplored in map mode. If empty, a texture will be created and cached based on the revealed sprite."
|
||||
},
|
||||
"remove": {
|
||||
"type": "boolean",
|
||||
|
||||
@ -1,9 +1,12 @@
|
||||
using NewHorizons.Builder.Props;
|
||||
using NewHorizons.External;
|
||||
using NewHorizons.External.Modules.VariableSize;
|
||||
using NewHorizons.Utility.OWML;
|
||||
using OWML.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NewHorizons.Utility.Files
|
||||
@ -43,7 +46,17 @@ namespace NewHorizons.Utility.Files
|
||||
return null;
|
||||
}
|
||||
// Copied from OWML but without the print statement lol
|
||||
var path = Path.Combine(mod.ModHelper.Manifest.ModFolderPath, filename);
|
||||
string path;
|
||||
try
|
||||
{
|
||||
path = Path.Combine(mod.ModHelper.Manifest.ModFolderPath, filename);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
NHLogger.LogError($"Invalid path: Couldn't combine {mod.ModHelper.Manifest.ModFolderPath} {filename} - {e}");
|
||||
return null;
|
||||
}
|
||||
|
||||
var key = GetKey(path);
|
||||
if (_textureCache.TryGetValue(key, out var existingTexture))
|
||||
{
|
||||
@ -247,7 +260,7 @@ namespace NewHorizons.Utility.Files
|
||||
return texture;
|
||||
}
|
||||
|
||||
public static Texture2D MakeOutline(Texture2D texture, Color color, int thickness)
|
||||
private static Texture2D MakeOutline(Texture2D texture, Color color, int thickness)
|
||||
{
|
||||
var key = $"{texture.name} > outline {color} {thickness}";
|
||||
if (_textureCache.TryGetValue(key, out var existingTexture)) return (Texture2D)existingTexture;
|
||||
@ -489,5 +502,119 @@ namespace NewHorizons.Utility.Files
|
||||
sprite.name = texture.name;
|
||||
return sprite;
|
||||
}
|
||||
|
||||
public static Texture2D GetCachedOutlineOrCreate(NewHorizonsBody body, Texture2D original, string originalPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(originalPath))
|
||||
{
|
||||
Texture2D defaultTexture = null;
|
||||
if (body.Config.Star != null)
|
||||
{
|
||||
defaultTexture = ImageUtilities.GetTexture(Main.Instance, "Assets/DefaultMapModeStarOutline.png");
|
||||
}
|
||||
else if (body.Config.Atmosphere != null)
|
||||
{
|
||||
defaultTexture = ImageUtilities.GetTexture(Main.Instance, "Assets/DefaultMapModNoAtmoOutline.png");
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultTexture = ImageUtilities.GetTexture(Main.Instance, "Assets/DefaultMapModePlanetOutline.png");
|
||||
}
|
||||
|
||||
return defaultTexture;
|
||||
}
|
||||
else
|
||||
{
|
||||
var cachedPath = Path.Combine(body.Mod.ModHelper.Manifest.ModFolderPath, $"TextureCache_{Main.Instance.CurrentStarSystem}", originalPath);
|
||||
var outlineTexture = ImageUtilities.GetTexture(body.Mod, cachedPath);
|
||||
|
||||
if (outlineTexture == null)
|
||||
{
|
||||
NHLogger.LogVerbose($"Caching outline to {cachedPath}");
|
||||
|
||||
var newTexture = ImageUtilities.MakeOutline(original, Color.white, 10);
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(cachedPath));
|
||||
File.WriteAllBytes(cachedPath, newTexture.EncodeToPNG());
|
||||
|
||||
return newTexture;
|
||||
}
|
||||
else
|
||||
{
|
||||
return outlineTexture;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Texture2D AutoGenerateMapModePicture(NewHorizonsBody body)
|
||||
{
|
||||
Texture2D texture;
|
||||
|
||||
if (body.Config.Star != null)
|
||||
{
|
||||
texture = ImageUtilities.GetTexture(Main.Instance, "Assets/DefaultMapModeStar.png");
|
||||
}
|
||||
else if (body.Config.Atmosphere != null)
|
||||
{
|
||||
texture = ImageUtilities.GetTexture(Main.Instance, "Assets/DefaultMapModNoAtmo.png");
|
||||
}
|
||||
else
|
||||
{
|
||||
texture = ImageUtilities.GetTexture(Main.Instance, "Assets/DefaultMapModePlanet.png");
|
||||
}
|
||||
|
||||
var color = GetDominantPlanetColor(body);
|
||||
var darkColor = new Color(color.r / 3f, color.g / 3f, color.b / 3f);
|
||||
|
||||
texture = ImageUtilities.LerpGreyscaleImage(texture, color, darkColor);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
private static Color GetDominantPlanetColor(NewHorizonsBody body)
|
||||
{
|
||||
try
|
||||
{
|
||||
var starColor = body.Config?.Star?.tint;
|
||||
if (starColor != null) return starColor.ToColor();
|
||||
|
||||
var atmoColor = body.Config.Atmosphere?.atmosphereTint;
|
||||
if (body.Config.Atmosphere?.clouds != null && atmoColor != null) return atmoColor.ToColor();
|
||||
|
||||
if (body.Config?.HeightMap?.textureMap != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var texture = ImageUtilities.GetTexture(body.Mod, body.Config.HeightMap.textureMap);
|
||||
var landColor = ImageUtilities.GetAverageColor(texture);
|
||||
if (landColor != null) return landColor;
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
var waterColor = body.Config.Water?.tint;
|
||||
if (waterColor != null) return waterColor.ToColor();
|
||||
|
||||
var lavaColor = body.Config.Lava?.tint;
|
||||
if (lavaColor != null) return lavaColor.ToColor();
|
||||
|
||||
var sandColor = body.Config.Sand?.tint;
|
||||
if (sandColor != null) return sandColor.ToColor();
|
||||
|
||||
switch (body.Config?.Props?.singularities?.FirstOrDefault()?.type)
|
||||
{
|
||||
case SingularityModule.SingularityType.BlackHole:
|
||||
return Color.black;
|
||||
case SingularityModule.SingularityType.WhiteHole:
|
||||
return Color.white;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
NHLogger.LogWarning($"Something went wrong trying to pick the colour for {body.Config.name} but I'm too lazy to fix it.");
|
||||
}
|
||||
|
||||
return Color.white;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
"author": "xen, Bwc9876, JohnCorby, MegaPiggy, Trifid, and friends",
|
||||
"name": "New Horizons",
|
||||
"uniqueName": "xen.NewHorizons",
|
||||
"version": "1.26.1",
|
||||
"version": "1.27.0",
|
||||
"owmlVersion": "2.12.1",
|
||||
"dependencies": [ "JohnCorby.VanillaFix", "xen.CommonCameraUtility", "dgarro.CustomShipLogModes" ],
|
||||
"conflicts": [ "PacificEngine.OW_CommonResources" ],
|
||||
|
||||