mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Refactor yet again and add autotiling
This commit is contained in:
50
Source/ConformalDecals/ModuleConformalFlag.cs
Normal file
50
Source/ConformalDecals/ModuleConformalFlag.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using ConformalDecals.Util;
|
||||
|
||||
namespace ConformalDecals {
|
||||
public class ModuleConformalFlag : ModuleConformalDecal {
|
||||
private const string DefaultFlag = "Squad/Flags/default";
|
||||
|
||||
public override void OnLoad(ConfigNode node) {
|
||||
base.OnLoad(node);
|
||||
|
||||
UpdateFlag(GetDefaultFlag());
|
||||
}
|
||||
|
||||
public override void OnStart(StartState state) {
|
||||
base.OnStart(state);
|
||||
|
||||
if (HighLogic.LoadedSceneIsGame) {
|
||||
GameEvents.onMissionFlagSelect.Add(UpdateFlag);
|
||||
}
|
||||
|
||||
UpdateFlag(GetDefaultFlag());
|
||||
}
|
||||
|
||||
public override void OnDestroy() {
|
||||
GameEvents.onMissionFlagSelect.Remove(UpdateFlag);
|
||||
base.OnDestroy();
|
||||
}
|
||||
|
||||
private string GetDefaultFlag() {
|
||||
if (HighLogic.LoadedSceneIsGame) {
|
||||
return EditorLogic.FlagURL != string.Empty ? EditorLogic.FlagURL : HighLogic.CurrentGame.flagURL;
|
||||
}
|
||||
else {
|
||||
return DefaultFlag;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateFlag(string flagUrl) {
|
||||
this.Log($"Loading flag texture '{flagUrl}'.");
|
||||
var flagTexture = GameDatabase.Instance.GetTexture(flagUrl, false);
|
||||
if (flagTexture == null) {
|
||||
this.LogWarning($"Unable to find flag texture '{flagUrl}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
materialProperties.AddOrGetTextureProperty("_Decal", true).texture = flagTexture;
|
||||
|
||||
UpdateMaterials();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user