Skip to content

Commit

Permalink
Merge pull request #331 from ihsoft/next
Browse files Browse the repository at this point in the history
KIS v1.21
  • Loading branch information
ihsoft authored May 17, 2019
2 parents 9aa7906 + 7dab9c4 commit 84543b0
Show file tree
Hide file tree
Showing 25 changed files with 145 additions and 143 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# 1.20 (May 3rd, 2019)):
# 1.21 (May 16th, 2019):
* [Fix #89] Portable containers revert to previous content when dropped.
* [Fix #328] KIS fails on every new DLC or major patch that changes kerbal models.
* [Fix #330] KIS containers mass and volume physically realistic. __Read the issue description for details!__

# 1.20 (May 3rd, 2019):
* [Fix #326] Text formating in PAW menu.

# 1.19 (May 2nd, 2019):
Expand Down
6 changes: 3 additions & 3 deletions KIS.version
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"NAME": "Kerbal Inventory System",
"URL": "https://raw.githubusercontent.com/ihsoft/KIS/master/KIS.version",
"VERSION": {
"BUILD": 41416,
"BUILD": 35942,
"MAJOR": 1,
"MINOR": 20,
"PATCH": 7062
"MINOR": 21,
"PATCH": 7075
}
}
2 changes: 1 addition & 1 deletion Lang/en-us.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ Localization
// The name of the context menu item to release the mounted part.
#kisLOC_10000 = Release
// ********** Type: Patches localization
// ********** Global strings
// Caption for the editor category.
#kisLOC_99001 = EVA Items
Expand Down
2 changes: 1 addition & 1 deletion Lang/es-es.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ Localization
// The name of the context menu item to release the mounted part.
#kisLOC_10000 = Lanzar
// ********** Type: Patches localization
// ********** Global strings
// Caption for the editor category.
#kisLOC_99001 = Artículos AEV
Expand Down
2 changes: 1 addition & 1 deletion Lang/fr-fr.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ Localization
// The name of the context menu item to release the mounted part.
#kisLOC_10000 = Relâcher

// ********** Type: Patches localization
// ********** Global strings

// Caption for the editor category.
#kisLOC_99001 = Objets EVA
Expand Down
2 changes: 1 addition & 1 deletion Lang/pt-br.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ Localization
// The name of the context menu item to release the mounted part.
#kisLOC_10000 = Soltar
// ********** Type: Patches localization
// ********** Global strings
// Caption for the editor category.
#kisLOC_99001 = Itens AEV
Expand Down
2 changes: 1 addition & 1 deletion Lang/ru.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ Localization
// The name of the context menu item to release the mounted part.
#kisLOC_10000 = Открепить
// ********** Type: Patches localization
// ********** Global strings
// Caption for the editor category.
#kisLOC_99001 = Предметы для открытого космоса
Expand Down
5 changes: 2 additions & 3 deletions Parts/container1/part.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PART
manufacturer = #KIS_Container1_Part_manufacturer // #KIS_Container1_Part_manufacturer = Kerbal Inventory Systems
description = #KIS_Container1_Part_description // #KIS_Container1_Part_description = This external container for tools, snacks, and more was designed specifically for the Mun mission. Two days before launch, the ground crew discovered that there was no more room for Valentina's favorite koffee mug. This put the entire mission at risk! Our engineers were thankfully able to solve the problem by attaching an ordinary hiking backpack reinforced with aluminum tubing to the exterior of the ship. Crews liked this design so much that these container-backpacks are now mass-produced.
attachRules = 1,0,1,1,0
mass = 0.1
mass = 0.01
dragModelType = default
maximum_drag = 0.2
minimum_drag = 0.3
Expand All @@ -30,7 +30,7 @@ PART
MODULE
{
name = ModuleKISInventory
maxVolume = 1000
maxVolume = 280
externalAccess = true
internalAccess = false
slotsX = 4
Expand All @@ -45,7 +45,6 @@ PART
MODULE
{
name = ModuleKISItemEvaTweaker
volumeOverride = 1100
carriable = true
equipMode = part
equipSlot = jetpack
Expand Down
9 changes: 2 additions & 7 deletions Parts/container2/part.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PART
manufacturer = #KIS_Container2_Part_manufacturer // #KIS_Container2_Part_manufacturer = Kerbal Inventory Systems
description = #KIS_Container2_Part_description // #KIS_Container2_Part_description = Sometimes missions require stuff. And things. Lots of stuff & things. Sometimes you run out of places to stuff your stuff, so you need more things in which to put your things. As such, here is the ILC-18k, a larger container in which to stuff your things.
attachRules = 1,0,1,1,1
mass = 1.5
mass = 0.5
dragModelType = default
maximum_drag = 0.2
minimum_drag = 0.3
Expand All @@ -31,7 +31,7 @@ PART
MODULE
{
name = ModuleKISInventory
maxVolume = 18000
maxVolume = 8800
externalAccess = true
internalAccess = true
slotsX = 8
Expand All @@ -43,9 +43,4 @@ PART
closeSndPath = KIS/Sounds/containerClose
defaultMoveSndPath = KIS/Sounds/itemMove
}
MODULE
{
name = ModuleKISItem
volumeOverride = 19000
}
}
9 changes: 2 additions & 7 deletions Parts/container3/part.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PART
manufacturer = #KIS_Container3_Part_manufacturer // #KIS_Container3_Part_manufacturer = Kerbal Inventory Systems
description = #KIS_Container3_Part_description // #KIS_Container3_Part_description = The SC-62 portable container-backpack was a huge success, but there were some shortcomings, like the fact that it cannot be accessed from inside the ship. To solve this problem, a full-fledged container module was developed. Due to the need to maintain a constant pressure inside the module, its size and cost have increased.
attachRules = 1,0,1,1,1
mass = 0.5
mass = 0.3
dragModelType = default
maximum_drag = 0.2
minimum_drag = 0.3
Expand All @@ -31,7 +31,7 @@ PART
MODULE
{
name = ModuleKISInventory
maxVolume = 6000
maxVolume = 3900
externalAccess = true
internalAccess = true
slotsX = 4
Expand All @@ -43,9 +43,4 @@ PART
closeSndPath = KIS/Sounds/containerClose
defaultMoveSndPath = KIS/Sounds/itemMove
}
MODULE
{
name = ModuleKISItem
volumeOverride = 7000
}
}
2 changes: 1 addition & 1 deletion Parts/containerMount1/containerMount1.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ PART
manufacturer = #KIS_ContainerMount1_Part_manufacturer // #KIS_ContainerMount1_Part_manufacturer = Kerbal Inventory Systems
description = #KIS_ContainerMount1_Part_description // #KIS_ContainerMount1_Part_description = This simple mounting system allows you to attach a SC-62 container-backpack. Wehrner von Kerman personally adjusts each mount before launch - that is why there have never been any failures, and all of them safely reach orbit. Warranty void if installed on Wehrner's day off.
attachRules = 1,1,1,0,1
mass = 0.025
mass = 0.005
dragModelType = default
maximum_drag = 0.2
minimum_drag = 0.2
Expand Down
11 changes: 0 additions & 11 deletions Patches/MM-Kerbals.cfg

This file was deleted.

50 changes: 28 additions & 22 deletions Source/KISAddonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ sealed class KISAddonConfig : MonoBehaviour {
[PersistentField("EvaPickup")]
readonly static PersistentConfigNode evaPickup = new PersistentConfigNode();

const string MaleKerbalEva = "kerbalEVA";
const string FemaleKerbalEva = "kerbalEVAfemale";
const string MaleKerbalEvaVintage = "kerbalEVAVintage";
const string FemaleKerbalEvaVintage = "kerbalEVAfemaleVintage";
const string RdKerbalEva = "kerbalEVA_RD";

/// <summary>Instantly loads the KIS global settings.</summary>
class KISConfigLoader: LoadingSystem {
public override bool IsReady() {
Expand All @@ -64,26 +58,28 @@ public override bool IsReady() {
}

public override void StartLoad() {
// Kerbal parts.
UpdateEvaPrefab(MaleKerbalEva);
UpdateEvaPrefab(MaleKerbalEvaVintage);
UpdateEvaPrefab(FemaleKerbalEva);
UpdateEvaPrefab(FemaleKerbalEvaVintage);

// Set inventory module for every pod with crew capacity.
DebugEx.Info("Loading pod inventories...");
DebugEx.Info("Adding KIS modules to the parts...");
for (var i = 0; i < PartLoader.LoadedPartsList.Count; i++) {
var avPart = PartLoader.LoadedPartsList[i];
if (!(avPart.name == MaleKerbalEva || avPart.name == FemaleKerbalEva
|| avPart.name == MaleKerbalEvaVintage || avPart.name == FemaleKerbalEvaVintage
|| avPart.name == RdKerbalEva
|| !avPart.partPrefab || avPart.partPrefab.CrewCapacity < 1)) {
DebugEx.Fine("Found part with crew: {0}, CrewCapacity={1}",
avPart.name, avPart.partPrefab.CrewCapacity);
var hasEvaModules = avPart.partPrefab.Modules.OfType<KerbalEVA>().Any();
if (hasEvaModules) {
var invModule = AddModule<ModuleKISInventory>(avPart.partPrefab, evaInventory);
invModule.invType = ModuleKISInventory.InventoryType.Eva;
AddModule<ModuleKISPickup>(avPart.partPrefab, evaPickup);
} else if (avPart.partPrefab.CrewCapacity > 0) {
AddPodInventories(avPart.partPrefab);
}
}
}

/// <summary>Adds a custom part module and loads its fields from the config.</summary>
T AddModule<T>(Part prefab, ConfigNode node) where T : PartModule {
var module = prefab.AddModule(typeof(T).Name, forceAwake: true) as T;
HostedDebugLog.Fine(module, "Add module and load config: type={0}", typeof(T));
module.Fields.Load(node);
return module;
}
}

public void Awake() {
Expand Down Expand Up @@ -117,13 +113,23 @@ public void Awake() {
/// </remarks>
/// <param name="part">The part to add seat inventorties for.</param>
public static void AddPodInventories(Part part) {
// Check the fields that once had unexpected values.
if (part.partInfo == null) {
HostedDebugLog.Error(part, "Unexpected part configuration: partInfo=<NULL>");
return;
}
if (part.partInfo.partConfig == null) {
HostedDebugLog.Error(part, "Unexpected part configuration: partConfig=<NULL>");
return;
}

var checkInventories = part.Modules.OfType<ModuleKISInventory>()
.Where(m => m.invType == ModuleKISInventory.InventoryType.Pod)
.ToArray();
var seatIndex = 0;
foreach (var inventory in checkInventories) {
HostedDebugLog.Info(
inventory, "Assinging seat to a pre-configured pod inventory: {0}", seatIndex);
inventory, "Assing seat to a pre-configured pod inventory: {0}", seatIndex);
inventory.podSeat = seatIndex++;
}
while (seatIndex < part.CrewCapacity) {
Expand All @@ -135,7 +141,7 @@ public static void AddPodInventories(Part part) {
moduleNode.SetValue("podSeat", seatIndex, createIfNotFound: true);
part.partInfo.partConfig.AddNode(moduleNode);
var inventory = part.AddModule(moduleNode, forceAwake: true);
HostedDebugLog.Info(inventory, "Dynamically created pod inventory at seat: {0}", seatIndex);
HostedDebugLog.Info(inventory, "Dynamically create pod inventory at seat: {0}", seatIndex);
seatIndex++;
}
}
Expand All @@ -154,7 +160,7 @@ static void UpdateEvaPrefab(string partName) {
}
}

/// <summary>Loads config values for the part's module fro the provided config node.</summary>
/// <summary>Loads config values for the part's module from the provided config node.</summary>
/// <returns><c>true</c> if loaded successfully.</returns>
static bool LoadModuleConfig(Part p, Type moduleType, ConfigNode node) {
var module = p.GetComponent(moduleType);
Expand Down
37 changes: 20 additions & 17 deletions Source/KISAddonPickup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Module authors: KospY, [email protected]
// License: Restricted

using KISAPIv1;
using KSP.UI.Screens;
using KSPDev.ConfigUtils;
using KSPDev.GUIUtils;
Expand Down Expand Up @@ -707,7 +706,7 @@ void OnDragReleased() {
}
if (HighLogic.LoadedSceneIsFlight) {
if (draggedItem != null) {
Drop(draggedItem.inventory.part, item: draggedItem);
Drop(null, item: draggedItem);
} else {
movingPart = draggedPart;
Drop(movingPart);
Expand Down Expand Up @@ -973,7 +972,7 @@ ModuleKISPickup GetActivePickupNearest(Part refPart,
Vector3 oldPos = refPart.transform.position;
Quaternion oldRot = refPart.transform.rotation;

// Legacy code compatibility.
// Legacy code compatibility.
if (testFunc == null) {
if (!canPartAttachOnly && !canStaticAttachOnly) {
testFunc = x => true;
Expand Down Expand Up @@ -1029,8 +1028,8 @@ float GetAllPickupMaxMassInRange(Part refPart,
refPart.transform.rotation = probeRotation ?? oldRot;

float maxMass = 0;
var allPickupModules = FindObjectsOfType(typeof(ModuleKISPickup)) as ModuleKISPickup[];
foreach (ModuleKISPickup pickupModule in allPickupModules) {
var allPickupModules = FindObjectsOfType(typeof(ModuleKISPickup)).Cast<ModuleKISPickup>();
foreach (var pickupModule in allPickupModules) {
var partDist = Colliders.GetSqrDistanceToPartOrDefault(
pickupModule.part.transform.position, refPart);
if (partDist <= pickupModule.maxDistance * pickupModule.maxDistance) {
Expand Down Expand Up @@ -1084,32 +1083,33 @@ void HandlePickup(PickupMode newPickupMode) {
}

public void Drop(KIS_Item item) {
Drop(item.inventory.part, item: item);
Drop(null, item: item);
}

/// <summary>Handles part drop action.</summary>
/// <param name="fromPart">
/// The part that was the source of the dragging action. If a world's part is grabbed than it will
/// be that part. If part is being dragged from inventory, then this parameter is an inventory
/// reference.
/// be that part. This part must have active physical colliders! As a last resort, leave it
/// <c>null</c>, and the root part of the currently active vessel will be used.
/// </param>
/// <param name="item">The item being dragged.</param>
void Drop(Part fromPart, KIS_Item item = null) {
fromPart = fromPart ?? FlightGlobals.ActiveVessel.rootPart; // A very bad workaround!
if (item != null) {
draggedItem = item;
DebugEx.Info("End pickup of item {0} from inventory {1}",
item.availablePart.name, item.inventory);
HostedDebugLog.Info(
item.inventory,
"End item pickup: item={0}, fromPart={1}", item.availablePart.title, fromPart);
} else {
grabbedPart = fromPart;
DebugEx.Info("End pickup of {0}", fromPart);
HostedDebugLog.Info(fromPart, "End part pickup");
}
if (!KISAddonPointer.isRunning) {
var pickupModule = GetActivePickupNearest(fromPart);
var pickupModule = GetActivePickupNearest(fromPart);
if (!KISAddonPointer.isRunning && pickupModule != null) {
var grabPosition = fromPart.transform.position;
int unusedPartsCount;
if (pickupModule
&& (item == null && CheckMass(fromPart, out unusedPartsCount, reportToConsole: true)
|| item != null && CheckItemMass(item, reportToConsole: true))) {
if (item == null && CheckMass(fromPart, out unusedPartsCount, reportToConsole: true)
|| item != null && CheckItemMass(item, reportToConsole: true)) {
KISAddonPointer.allowPart = true;
KISAddonPointer.allowEva = true;
KISAddonPointer.allowMount = true;
Expand Down Expand Up @@ -1503,7 +1503,10 @@ bool CheckMass(Part srcPart, out int grabbedPartsCount, bool reportToConsole = f
/// <returns><c>true</c> if total mass is within the limits.</returns>
bool CheckItemMass(KIS_Item item, bool reportToConsole = false) {
grabbedMass = item.totalSlotMass;
var pickupMaxMass = GetAllPickupMaxMassInRange(item.inventory.part);
var refPart = item.inventory.vessel.isEVA
? item.inventory.vessel.rootPart // Inventories on EVA kerbal may not have colliders.
: item.inventory.part;
var pickupMaxMass = GetAllPickupMaxMassInRange(refPart);
if (grabbedMass > pickupMaxMass) {
ReportCheckError(TooHeavyStatusTooltipTxt,
TooHeavyTooltipTxt.Format(grabbedMass, pickupMaxMass),
Expand Down
2 changes: 1 addition & 1 deletion Source/KIS_IconViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Texture texture {
RenderTexture cameraTarget;

public KIS_IconViewer(Part part, int resolution) {
if (part.vessel != null && part.vessel.isEVA) {
if (part.Modules.OfType<KerbalEVA>().Any()) {
MakeKerbalAvatar(part, resolution);
} else {
MakePartIcon(part.partInfo, resolution, VariantsUtils.GetCurrentPartVariant(part));
Expand Down
Loading

0 comments on commit 84543b0

Please sign in to comment.