Integrate fuel line and strut variants

This commit is contained in:
2020-07-03 01:22:08 -07:00
parent 2e6a9d5190
commit 1671a65656
7 changed files with 147 additions and 39 deletions

View File

@ -64,7 +64,6 @@ Localization
#LOC_Restock_variant-mounting_compact = Compact #LOC_Restock_variant-mounting_compact = Compact
#LOC_Restock_variant-mounting_mounted = Mounted #LOC_Restock_variant-mounting_mounted = Mounted
#LOC_Restock_variant-gold-truss = Gold (Mounted) #LOC_Restock_variant-gold-truss = Gold (Mounted)
#LOC_Restock_variant-silver-truss = Silver (Mounted) #LOC_Restock_variant-silver-truss = Silver (Mounted)
@ -96,12 +95,18 @@ Localization
#LOC_Restock_variant-surface_truss = Truss #LOC_Restock_variant-surface_truss = Truss
#LOC_Restock_variant-surface_warningStripes = Warning Stripes #LOC_Restock_variant-surface_warningStripes = Warning Stripes
#LOC_Restock_variant-surface_thermalblankets = Insulated #LOC_Restock_variant-surface_thermalblankets = Insulated
#LOC_Restock_variant-decoupler_metal = Metal
#LOC_Restock_variant-decoupler_grey-orange = Orange/Grey
#LOC_Restock_variant-surface_yellow = Yellow #LOC_Restock_variant-surface_yellow = Yellow
#LOC_Restock_variant-surface_black = Black #LOC_Restock_variant-surface_black = Black
#LOC_Restock_variant-surface_white = White
#LOC_Restock_variant-surface_blue = Blue
#LOC_Restock_variant-strut_classic_metal = Metal
#LOC_Restock_variant-strut_classic_white = White
#LOC_Restock_variant-strut_compact_metal = Metal (Compact)
#LOC_Restock_variant-strut_compact_white = White (Compact)
#LOC_Restock_variant-decoupler_metal = Metal
#LOC_Restock_variant-decoupler_grey-orange = Orange/Grey
#LOC_Restock_variant-service-bay-opaque = Solid Caps #LOC_Restock_variant-service-bay-opaque = Solid Caps
#LOC_Restock_variant-service-bay-transparent = Truss Caps #LOC_Restock_variant-service-bay-transparent = Truss Caps

View File

@ -26,14 +26,16 @@
stretchAxis = x stretchAxis = x
stretchTextures = _MainTex _BumpMap stretchTextures = _MainTex _BumpMap
} }
!MODULE[ModulePartVariants] {}
MODULE MODULE
{ {
name = ModulePartVariants name = ModulePartVariants
useMultipleDragCubes = false useMultipleDragCubes = false
baseVariant = Yellow baseVariant = YellowAndWhite
VARIANT VARIANT
{ {
name = Yellow name = YellowAndWhite
displayName = #LOC_Restock_variant-surface_yellow displayName = #LOC_Restock_variant-surface_yellow
themeName = YellowAndWhite themeName = YellowAndWhite
primaryColor = #B08D43 primaryColor = #B08D43
@ -44,6 +46,8 @@
line_black = false line_black = false
line_metal = false line_metal = false
line_sofi = false line_sofi = false
line_white = false
line_blue = false
} }
} }
VARIANT VARIANT
@ -59,6 +63,8 @@
line_black = true line_black = true
line_metal = false line_metal = false
line_sofi = false line_sofi = false
line_white = false
line_blue = false
} }
} }
VARIANT VARIANT
@ -74,6 +80,8 @@
line_black = false line_black = false
line_metal = true line_metal = true
line_sofi = false line_sofi = false
line_white = false
line_blue = false
} }
} }
VARIANT VARIANT
@ -81,7 +89,7 @@
name = Orange name = Orange
displayName = #autoLOC_8007123 displayName = #autoLOC_8007123
themeName = Orange themeName = Orange
primaryColor = #B08D43 primaryColor = #A55929
secondaryColor = #999999 secondaryColor = #999999
GAMEOBJECTS GAMEOBJECTS
{ {
@ -89,6 +97,42 @@
line_black = false line_black = false
line_metal = false line_metal = false
line_sofi = true line_sofi = true
line_white = false
line_blue = false
}
}
VARIANT
{
name = White
displayName = #LOC_Restock_variant-surface_white
themeName = White
primaryColor = #ffffff
secondaryColor = #999999
GAMEOBJECTS
{
line_yellow = false
line_black = false
line_metal = false
line_sofi = false
line_white = true
line_blue = false
}
}
VARIANT
{
name = Blue
displayName = #LOC_Restock_variant-surface_blue
themeName = White
primaryColor = #426573
secondaryColor = #999999
GAMEOBJECTS
{
line_yellow = false
line_black = false
line_metal = false
line_sofi = false
line_white = false
line_blue = true
} }
} }
} }

View File

@ -26,16 +26,18 @@
stretchAxis = x stretchAxis = x
stretchTextures = _MainTex _BumpMap stretchTextures = _MainTex _BumpMap
} }
!MODULE[ModulePartVariants] {}
MODULE MODULE
{ {
name = ModulePartVariants name = ModulePartVariants
useMultipleDragCubes = false useMultipleDragCubes = false
baseVariant = Classic baseVariant = Gray
VARIANT VARIANT
{ {
name = Classic name = Gray
displayName = #LOC_Restock_variant-mounting_classic displayName = #LOC_Restock_variant-strut_classic_metal
themeName = White themeName = Metal
primaryColor = #6f6e6d primaryColor = #6f6e6d
secondaryColor = #999999 secondaryColor = #999999
GAMEOBJECTS GAMEOBJECTS
@ -44,13 +46,19 @@
strut_target_body_classic = true strut_target_body_classic = true
strut_main_body_compact = false strut_main_body_compact = false
strut_target_body_compact = false strut_target_body_compact = false
strut_main_body_classic_white = false
strut_target_body_classic_white = false
strut_main_body_compact_white = false
strut_target_body_compact_white = false
strut_metal = true
strut_white = false
} }
} }
VARIANT VARIANT
{ {
name = Compact name = Compact
displayName = #LOC_Restock_variant-mounting_compact displayName = #LOC_Restock_variant-strut_compact_metal
themeName = White themeName = Metal
primaryColor = #6f6e6d primaryColor = #6f6e6d
secondaryColor = #999999 secondaryColor = #999999
GAMEOBJECTS GAMEOBJECTS
@ -59,6 +67,54 @@
strut_target_body_classic = false strut_target_body_classic = false
strut_main_body_compact = true strut_main_body_compact = true
strut_target_body_compact = true strut_target_body_compact = true
strut_main_body_classic_white = false
strut_target_body_classic_white = false
strut_main_body_compact_white = false
strut_target_body_compact_white = false
strut_metal = true
strut_white = false
}
}
VARIANT
{
name = White
displayName = #LOC_Restock_variant-strut_classic_white
themeName = White
primaryColor = #ffffff
secondaryColor = #999999
GAMEOBJECTS
{
strut_main_body_classic = false
strut_target_body_classic = false
strut_main_body_compact = false
strut_target_body_compact = false
strut_main_body_classic_white = true
strut_target_body_classic_white = true
strut_main_body_compact_white = false
strut_target_body_compact_white = false
strut_metal = false
strut_white = true
}
}
VARIANT
{
name = White_Compact
displayName = #LOC_Restock_variant-strut_compact_white
themeName = White
primaryColor = #ffffff
secondaryColor = #999999
GAMEOBJECTS
{
strut_main_body_classic = false
strut_target_body_classic = false
strut_main_body_compact = false
strut_target_body_compact = false
strut_main_body_classic_white = false
strut_target_body_classic_white = false
strut_main_body_compact_white = true
strut_target_body_compact_white = true
strut_metal = false
strut_white = true
} }
} }
} }

View File

@ -1,5 +1,6 @@
v1.2.0 v1.2.0
------ ------
- KSP 1.10
- New stock part replacements - New stock part replacements
- Resources - Resources
-FTE-1 Drain Valve (Andrew Cassidy): now has metal and warning stripe variants -FTE-1 Drain Valve (Andrew Cassidy): now has metal and warning stripe variants
@ -11,6 +12,9 @@ v1.2.0
- Mk2 Command Pod (Andrew Cassidy): Now has dark and white variants. - Mk2 Command Pod (Andrew Cassidy): Now has dark and white variants.
- Coupling - Coupling
- Inflatable Airlock (Andrew Cassidy): now has built in decoupler and optional ring to connect seamlessly with KV-series pods. Has a new IVA. - Inflatable Airlock (Andrew Cassidy): now has built in decoupler and optional ring to connect seamlessly with KV-series pods. Has a new IVA.
- Bugfixes and tweaks
- New White and White (compact) variants for EAS-4 Strut Connector
- New White and Blue variants for the FTX-2 External Fuel Duct
v1.1.2 v1.1.2
------ ------

View File

@ -5,42 +5,40 @@ namespace Restock
{ {
/* Extends the stock CModuleLinkedMesh used on struts and pipes to make pipe textures repeat instead of stretch when /* Extends the stock CModuleLinkedMesh used on struts and pipes to make pipe textures repeat instead of stretch when
a pipe is extended beyond its default length */ a pipe is extended beyond its default length */
public class ModuleRestockLinkedMesh : CModuleLinkedMesh public class ModuleRestockLinkedMesh : CModuleLinkedMesh
{ {
// the direction along the texture that the pipe points. set to "x" or "y" // the direction along the texture that the pipe points. set to "x" or "y"
[KSPField] [KSPField] public string stretchAxis = "x";
public string stretchAxis = "x";
// space-seperated list of textures to be effected by the length, preferably all of the ones on the material // space-seperated list of textures to be effected by the length, preferably all of the ones on the material
// Unity has no good way to get all the texture names attached to a material so it has to be set manually, unfortunately // Unity has no good way to get all the texture names attached to a material so it has to be set manually, unfortunately
[KSPField] [KSPField] public string stretchTextures = "_MainTex";
public string stretchTextures = "_MainTex";
// reference to the material we will be modifying // reference to the material we will be modifying
private Material[] pipeMaterials; private Material[] pipeMaterials;
// array of property IDs corresponding to the textures // array of property IDs corresponding to the textures
private int[] pipeMaterialIDs; private int[] pipeMaterialIDs;
// index of the texture scale vector, 0 for x, 1 for y // index of the texture scale vector, 0 for x, 1 for y
private int pipeStretchIndex; private int pipeStretchIndex;
// initial scale of the pipe object, may not be 1 // initial scale of the pipe object, may not be 1
private float baseStretch; private float baseStretch;
// scale vector for the material // scale vector for the material
private Vector2 texScale = Vector2.one; private Vector2 texScale = Vector2.one;
// offset vector for the material // offset vector for the material
private Vector2 texOffset = Vector2.zero; private Vector2 texOffset = Vector2.zero;
public override void OnStart(StartState state) public override void OnStart(StartState state)
{ {
base.OnStart(state); base.OnStart(state);
// get all materials on the line object, including disabled ones // get all materials on the line object, including disabled ones
var renderers = line.GetComponentsInChildren<MeshRenderer>(true); var renderers = line.GetComponentsInChildren<MeshRenderer>(true);
pipeMaterials = new Material[renderers.Length]; pipeMaterials = new Material[renderers.Length];
@ -48,7 +46,7 @@ namespace Restock
{ {
pipeMaterials[i] = renderers[i].material; pipeMaterials[i] = renderers[i].material;
} }
// split texture list and convert to property IDs for easy access // split texture list and convert to property IDs for easy access
var texNames = stretchTextures.Split(' '); var texNames = stretchTextures.Split(' ');
pipeMaterialIDs = new int[texNames.Length]; pipeMaterialIDs = new int[texNames.Length];
@ -56,11 +54,11 @@ namespace Restock
{ {
pipeMaterialIDs[i] = Shader.PropertyToID(texNames[i]); pipeMaterialIDs[i] = Shader.PropertyToID(texNames[i]);
} }
// default to 'x' if an invalid value is used // default to 'x' if an invalid value is used
pipeStretchIndex = stretchAxis != "y" ? 0 : 1; pipeStretchIndex = stretchAxis != "y" ? 0 : 1;
baseStretch = part.scaleFactor; baseStretch = part.scaleFactor;
GameEvents.onEditorVariantApplied.Add(OnVariantApplied); GameEvents.onEditorVariantApplied.Add(OnVariantApplied);
} }
@ -91,23 +89,24 @@ namespace Restock
{ {
if (appliedPart == part) UpdateStretch(); if (appliedPart == part) UpdateStretch();
} }
// updates the texture stretch to match the pipe object's local scale // updates the texture stretch to match the pipe object's local scale
private void UpdateStretch() private void UpdateStretch()
{ {
var stretch = line.localScale.z / baseStretch; var stretch = line.localScale.z / baseStretch;
texScale[pipeStretchIndex] = stretch; texScale[pipeStretchIndex] = stretch;
texOffset[pipeStretchIndex] = (1 - stretch) / 2; texOffset[pipeStretchIndex] = (1 - stretch) / 2;
for (var i = 0; i < pipeMaterials.Length; i++) foreach (var material in pipeMaterials)
{ {
var material = pipeMaterials[i]; foreach (var id in pipeMaterialIDs)
for (var j = 0; j < pipeMaterialIDs.Length; j++)
{ {
var id = pipeMaterialIDs[j]; if (material.HasProperty(id))
material.SetTextureScale(id, texScale); {
material.SetTextureOffset(id, texOffset); material.SetTextureScale(id, texScale);
material.SetTextureOffset(id, texOffset);
}
} }
} }
} }