Skip to content

Commit b021d5c

Browse files
Merge pull request #1 from blowfishpro/master
update
2 parents 2e3ee06 + 73db0ac commit b021d5c

File tree

66 files changed

+3015
-421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+3015
-421
lines changed

.rubocop.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
AllCops:
2-
TargetRubyVersion: 2.5.1
3-
41
Metrics/LineLength:
52
Max: 120
63

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ruby-2.5.1
1+
ruby-2.6.5

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ mono:
33
- 5.12.0
44
solution: B9PartSwitch.sln
55
before_install:
6-
- sudo apt-get install python3-pip
6+
- sudo apt-get install python3-pip python3-setuptools
77
install:
88
- rvm install $(cat .ruby-version)
99
- bundle install
1010
- pip3 install awscli --upgrade --user
1111
- install-ksp-dlls
1212
- nuget restore ${TRAVIS_SOLUTION}
1313
script:
14+
- bundle exec rubocop
1415
- msbuild /p:Configuration=Release /p:ReferencePath="${KSP_DLL_PATH}" ${TRAVIS_SOLUTION}
1516
- bin/test
1617
- build_script/script/make_release.sh

B9PartSwitch/B9PartSwitch.csproj

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\packages\Microsoft.Net.Compilers.3.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.3.0.0\build\Microsoft.Net.Compilers.props')" />
3+
<Import Project="..\packages\Microsoft.Net.Compilers.3.3.1\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.3.3.1\build\Microsoft.Net.Compilers.props')" />
44
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
55
<PropertyGroup>
66
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -10,7 +10,7 @@
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>B9PartSwitch</RootNamespace>
1212
<AssemblyName>B9PartSwitch</AssemblyName>
13-
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
13+
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>
1515
<TargetFrameworkProfile />
1616
<NuGetPackageImportStamp>
@@ -43,19 +43,28 @@
4343
<Reference Include="UnityEngine">
4444
<Private>False</Private>
4545
</Reference>
46+
<Reference Include="UnityEngine.CoreModule">
47+
<Private>False</Private>
48+
</Reference>
4649
<Reference Include="UnityEngine.UI">
4750
<Private>False</Private>
4851
</Reference>
4952
</ItemGroup>
5053
<ItemGroup>
5154
<Compile Include="CustomPartModule.cs" />
52-
<Compile Include="Extensions\CFGUtilPartModuleExtensions.cs" />
55+
<Compile Include="Extensions\AttachNodeExtensions.cs" />
56+
<Compile Include="Extensions\CustomPartModuleExtensions.cs" />
5357
<Compile Include="Extensions\IEnumerableExtensions.cs" />
58+
<Compile Include="Extensions\ListExtensions.cs" />
59+
<Compile Include="Extensions\ObjectExtensions.cs" />
60+
<Compile Include="Extensions\PartExtensions.cs" />
5461
<Compile Include="Extensions\PartModuleExtensions.cs" />
5562
<Compile Include="Extensions\StringExtensions.cs" />
5663
<Compile Include="Extensions\TransformExtensions.cs" />
64+
<Compile Include="Extensions\TypeExtensions.cs" />
5765
<Compile Include="Extensions\Vector3Extensions.cs" />
5866
<Compile Include="FatalErrorHandler.cs" />
67+
<Compile Include="FARChecker.cs" />
5968
<Compile Include="Fishbones\Context\Operation.cs" />
6069
<Compile Include="Fishbones\Context\OperationContext.cs" />
6170
<Compile Include="Fishbones\FieldWrappers\FieldWrapper.cs" />
@@ -87,24 +96,33 @@
8796
<Compile Include="Fishbones\Parsers\NodeObjectWrapperIContextualNode.cs" />
8897
<Compile Include="Fishbones\Parsers\OverrideValueParseMap.cs" />
8998
<Compile Include="Fishbones\Parsers\PartResourceDefinitionValueParser.cs" />
99+
<Compile Include="Fishbones\Parsers\ScaleParser.cs" />
90100
<Compile Include="Fishbones\Parsers\ValueParseMap.cs" />
91101
<Compile Include="Fishbones\Parsers\ValueParseMapWrapper.cs" />
92102
<Compile Include="Fishbones\Parsers\ValueParser.cs" />
93103
<Compile Include="Fishbones\NodeDataMappers\INodeDataMapperBuilder.cs" />
94104
<Compile Include="Fishbones\NodeDataBuilder.cs" />
95105
<Compile Include="Fishbones\NodeDataField.cs" />
96-
<Compile Include="Fishbones\OperationManager.cs" />
97106
<Compile Include="Fishbones\NodeDataMappers\ValueListMapperBuilder.cs" />
98107
<Compile Include="Fishbones\NodeDataMappers\ValueScalarMapperBuilder.cs" />
108+
<Compile Include="Fishbones\OperationManager.cs" />
99109
<Compile Include="Fishbones\UseParser.cs" />
100110
<Compile Include="Localization.cs" />
101111
<Compile Include="ModuleB9DisableTransform.cs" />
102112
<Compile Include="ModuleB9PropagateCopyEvents.cs" />
103-
<Compile Include="PartSwitch\PartModifiers\AttachNodeMover.cs" />
104113
<Compile Include="PartSwitch\AttachNodeModifierInfo.cs" />
114+
<Compile Include="PartSwitch\BestSubtypeDeterminator.cs" />
115+
<Compile Include="PartSwitch\LockedSubtypeWarningHandler.cs" />
105116
<Compile Include="PartSwitch\ModuleB9PartInfo.cs" />
117+
<Compile Include="PartSwitch\ModuleB9PartSwitch.cs" />
118+
<Compile Include="PartSwitch\ModuleModifierInfo.cs" />
119+
<Compile Include="PartSwitch\PartModifiers\AttachNodeMover.cs" />
106120
<Compile Include="PartSwitch\PartModifiers\AttachNodeToggler.cs" />
121+
<Compile Include="PartSwitch\PartModifiers\EffectDeactivator.cs" />
107122
<Compile Include="PartSwitch\PartModifiers\IPartModifier.cs" />
123+
<Compile Include="PartSwitch\PartModifiers\ModuleDataHandlerBasic.cs" />
124+
<Compile Include="PartSwitch\PartModifiers\ModuleDeactivator.cs" />
125+
<Compile Include="PartSwitch\PartModifiers\ModuleOutputResourceResetter.cs" />
108126
<Compile Include="PartSwitch\PartModifiers\PartAttachNodeModifier.cs" />
109127
<Compile Include="PartSwitch\PartModifiers\PartCenterOfBuoyancyModifier.cs" />
110128
<Compile Include="PartSwitch\PartModifiers\PartCenterOfDisplacementModifier.cs" />
@@ -117,29 +135,30 @@
117135
<Compile Include="PartSwitch\PartModifiers\PartSkinMaxTempModifier.cs" />
118136
<Compile Include="PartSwitch\PartModifiers\PartStackSymmetryModifier.cs" />
119137
<Compile Include="PartSwitch\PartModifiers\ResourceModifier.cs" />
138+
<Compile Include="PartSwitch\PartModifiers\TextureReplacement.cs" />
120139
<Compile Include="PartSwitch\PartModifiers\TransformMover.cs" />
121140
<Compile Include="PartSwitch\PartModifiers\TransformRotator.cs" />
141+
<Compile Include="PartSwitch\PartModifiers\TransformScaleModifier.cs" />
122142
<Compile Include="PartSwitch\PartModifiers\TransformToggler.cs" />
143+
<Compile Include="PartSwitch\PartSubtype.cs" />
123144
<Compile Include="PartSwitch\PartSwitchFlightDialog.cs" />
124-
<Compile Include="PartSwitch\PartModifiers\TextureReplacement.cs" />
125145
<Compile Include="PartSwitch\TextureSwitchInfo.cs" />
126146
<Compile Include="PartSwitch\TransformModifierInfo.cs" />
127147
<Compile Include="Serialization\SerializedDataContainer.cs" />
128-
<Compile Include="Extensions\AttachNodeExtensions.cs" />
129-
<Compile Include="Extensions\ObjectExtensions.cs" />
130-
<Compile Include="Extensions\PartExtensions.cs" />
131-
<Compile Include="Extensions\TypeExtensions.cs" />
132-
<Compile Include="FARChecker.cs" />
133-
<Compile Include="Extensions\ListExtensions.cs" />
134148
<Compile Include="SeriousWarningHandler.cs" />
135-
<Compile Include="TankSettings\B9TankSettings.cs" />
136-
<Compile Include="PartSwitch\ModuleB9PartSwitch.cs" />
137-
<Compile Include="PartSwitch\PartSubtype.cs" />
138149
<Compile Include="Properties\AssemblyInfo.cs" />
150+
<Compile Include="TankSettings\B9TankSettings.cs" />
139151
<Compile Include="TankSettings\Tanks.cs" />
140152
<Compile Include="TankSettings\TankTypeValueParser.cs" />
141-
<Compile Include="Test\ModuleB9PartSwitchTest.cs" />
142-
<Compile Include="Test\PartModuleTest.cs" />
153+
<Compile Include="UI\PrefabManager.cs" />
154+
<Compile Include="UI\SwitcherSubtypeDescriptionGenerator.cs" />
155+
<Compile Include="UI\TooltipHelper.cs" />
156+
<Compile Include="UI\UIPartActionSubtypeButton.cs" />
157+
<Compile Include="UI\UIPartActionSubtypeSelector.cs" />
158+
<Compile Include="UI\UI_SubtypeSelector.cs" />
159+
<Compile Include="Utils\ColorParser.cs" />
160+
<Compile Include="Utils\GroupedStringBuilder.cs" />
161+
<Compile Include="Utils\ResourceColors.cs" />
143162
</ItemGroup>
144163
<ItemGroup>
145164
<None Include="packages.config" />
@@ -159,7 +178,7 @@
159178
<PropertyGroup>
160179
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
161180
</PropertyGroup>
162-
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.3.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.3.0.0\build\Microsoft.Net.Compilers.props'))" />
181+
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.3.3.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.3.3.1\build\Microsoft.Net.Compilers.props'))" />
163182
</Target>
164183
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
165184
Other similar extension points exist, see Microsoft.Common.targets.

B9PartSwitch/CustomPartModule.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics.CodeAnalysis;
23
using UniLinq;
34
using UnityEngine;
45
using B9PartSwitch.Fishbones;
@@ -22,10 +23,11 @@ public abstract class CustomPartModule : PartModule, ISerializationCallbackRecei
2223

2324
#region Setup
2425

26+
[SuppressMessage("Code Quality", "IDE0051", Justification = "Called by Unity")]
2527
private void Start()
2628
{
2729
// Cast to array so that there aren't issues with modifying the enumerable in a loop
28-
var otherModules = part.Modules.OfType<CustomPartModule>().Where(m => m != this && m.GetType() == this.GetType()).ToArray();
30+
var otherModules = part.Modules.OfType<CustomPartModule>().Where(m => m != this && m.GetType() == GetType()).ToArray();
2931
if (otherModules.Length > 0 && moduleID.IsNullOrEmpty())
3032
{
3133
LogError("Must have a moduleID defined if more than one " + this.GetType().Name + " is present on a part. This module will be removed");
@@ -58,7 +60,7 @@ public override void OnLoad(ConfigNode node)
5860
string newID = node.GetValue(nameof(moduleID));
5961
if (!string.Equals(moduleID, newID))
6062
{
61-
var correctModule = part.Modules.OfType<CustomPartModule>().FirstOrDefault(m => m != this && m.GetType() == this.GetType() && m.moduleID == newID);
63+
var correctModule = part.Modules.OfType<CustomPartModule>().FirstOrDefault(m => m != this && m.GetType() == GetType() && m.moduleID == newID);
6264
if (correctModule.IsNotNull())
6365
{
6466
LogWarning("OnLoad was called with the wrong ModuleID ('" + newID + "'), but found the correct module to load");
@@ -154,6 +156,7 @@ public override string ToString()
154156
log += " on part " + part.partInfo?.name ?? part.name;
155157
return log;
156158
}
159+
157160
#endregion
158161
}
159162
}

B9PartSwitch/Extensions/CFGUtilPartModuleExtensions.cs renamed to B9PartSwitch/Extensions/CustomPartModuleExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace B9PartSwitch
66
{
7-
public static class CFGUtilPartModuleExtensions
7+
public static class CustomPartModuleExtensions
88
{
99
public static IEnumerable<T> FindSymmetryCounterparts<T>(this T module) where T : CustomPartModule
1010
{

B9PartSwitch/Extensions/IEnumerableExtensions.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-

1+
using System;
22
using System.Collections.Generic;
33

44
namespace B9PartSwitch
@@ -12,5 +12,29 @@ public static IEnumerable<T> All<T>(this IEnumerable<T> enumerable)
1212
yield return item;
1313
}
1414
}
15+
16+
public static Tcollection MaxBy<Tcollection, Tcompare>(this IEnumerable<Tcollection> enumerable, Func<Tcollection, Tcompare> mapper) where Tcompare : IComparable<Tcompare>
17+
{
18+
enumerable.ThrowIfNullArgument(nameof(enumerable));
19+
mapper.ThrowIfNullArgument(nameof(mapper));
20+
21+
IEnumerator<Tcollection> enumerator = enumerable.GetEnumerator();
22+
23+
if (!enumerator.MoveNext()) throw new InvalidOperationException("Enumerable is empty!");
24+
25+
Tcollection result = enumerator.Current;
26+
Tcompare resultValue = mapper(result);
27+
28+
while (enumerator.MoveNext())
29+
{
30+
Tcollection testResult = enumerator.Current;
31+
Tcompare testValue = mapper(testResult);
32+
if (testValue.CompareTo(resultValue) <= 0) continue;
33+
result = testResult;
34+
resultValue = testValue;
35+
}
36+
37+
return result;
38+
}
1539
}
1640
}

B9PartSwitch/Extensions/PartExtensions.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public static PartResource AddOrCreateResource(this Part part, PartResourceDefin
6767
return resource;
6868
}
6969

70+
public static float GetResourceMassMax(this Part part) => part.Resources.Sum(resource => (float)resource.maxAmount * resource.info.density);
71+
7072
public static float GetResourceCostMax(this Part part) => part.Resources.Sum(resource => (float)resource.maxAmount * resource.info.unitCost);
7173
public static float GetResourceCostOffset(this Part part) => part.Resources.Sum(resource => (float)(resource.amount - resource.maxAmount) * resource.info.unitCost);
7274

@@ -84,6 +86,15 @@ public static void UpdateTransformEnabled(this Part part, Transform t)
8486
}
8587

8688
t.gameObject.SetActive(shouldBeEnabled);
89+
90+
if (part.partRendererBoundsIgnore.Contains(t.name))
91+
{
92+
if (shouldBeEnabled) part.partRendererBoundsIgnore.Remove(t.name);
93+
}
94+
else
95+
{
96+
if (!shouldBeEnabled) part.partRendererBoundsIgnore.Add(t.name);
97+
}
8798
}
8899

89100
public static void UpdateNodeEnabled(this Part part, AttachNode node)

B9PartSwitch/Fishbones/NodeDataListLibrary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace B9PartSwitch.Fishbones
66
{
77
public static class NodeDataListLibrary
88
{
9-
private static Dictionary<Type, NodeDataList> dict = new Dictionary<Type, NodeDataList>();
9+
private static readonly Dictionary<Type, NodeDataList> dict = new Dictionary<Type, NodeDataList>();
1010

1111
public static NodeDataList Get<T>() => Get(typeof(T));
1212

B9PartSwitch/Fishbones/NodeDataObjectExtensions.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,25 @@ public static string SerializeToString(this object obj)
4747
{
4848
obj.ThrowIfNullArgument(nameof(obj));
4949

50-
return obj.SerializeToNode().ToString();
50+
ConfigNode node = obj.SerializeToNode();
51+
52+
void EscapeValuesRecursive(ConfigNode theNode)
53+
{
54+
foreach (ConfigNode subNode in theNode.nodes)
55+
{
56+
EscapeValuesRecursive(subNode);
57+
}
58+
59+
foreach (ConfigNode.Value value in theNode.values)
60+
{
61+
value.value = value.value.Replace("\n", "\\n");
62+
value.value = value.value.Replace("\t", "\\t");
63+
}
64+
}
65+
66+
EscapeValuesRecursive(node);
67+
68+
return node.ToString();
5169
}
5270

5371
public static ConfigNode SerializeToNode(this object obj)
@@ -93,6 +111,22 @@ public static void DeserializeFromString(this object obj, string serializedData)
93111
ConfigNode dataNode = node.GetNode(SERIALIZED_NODE);
94112
if (dataNode.IsNull()) throw new FormatException("No serialized data node found");
95113

114+
void UnescapeValuesRecursive(ConfigNode theNode)
115+
{
116+
foreach (ConfigNode subNode in theNode.nodes)
117+
{
118+
UnescapeValuesRecursive(subNode);
119+
}
120+
121+
foreach (ConfigNode.Value value in theNode.values)
122+
{
123+
value.value = value.value.Replace("\\n", "\n");
124+
value.value = value.value.Replace("\\t", "\t");
125+
}
126+
}
127+
128+
UnescapeValuesRecursive(dataNode);
129+
96130
obj.DeserializeFromNode(dataNode);
97131
}
98132

0 commit comments

Comments
 (0)