Skip to content

Commit

Permalink
Fix missing attribute for MultipleModulePartAPI, refactor WriteValue …
Browse files Browse the repository at this point in the history
…for better support for other mods, update release script to behave correctly with new versioning bump version (only fileversion and KSPAssembly).
  • Loading branch information
NathanKell committed Sep 9, 2022
1 parent 9c5c432 commit af6ea83
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 57 deletions.
2 changes: 1 addition & 1 deletion GameData/KSPCommunityFixes/KSPCommunityFixes.version
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"NAME": "KSPCommunityFixes",
"URL": "https://raw.githubusercontent.com/KSPModdingLibs/KSPCommunityFixes/master/GameData/KSPCommunityFixes/KSPCommunityFixes.version",
"DOWNLOAD": "https://github.com/KSPModdingLibs/KSPCommunityFixes/releases",
"VERSION": {"MAJOR": 1, "MINOR": 22, "PATCH": 0, "BUILD": 0},
"VERSION": {"MAJOR": 1, "MINOR": 22, "PATCH": 1, "BUILD": 0},
"KSP_VERSION": {"MAJOR": 1, "MINOR": 12, "PATCH": 3},
"KSP_VERSION_MIN": {"MAJOR": 1, "MINOR": 8, "PATCH": 0},
"KSP_VERSION_MAX": {"MAJOR": 1, "MINOR": 12, "PATCH": 3}
Expand Down
6 changes: 4 additions & 2 deletions KSPCommunityFixes/KSPCommunityFixes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,10 @@
<Using Namespace="System.Text.RegularExpressions" />
<Code Type="Fragment" Language="cs"><![CDATA[
string content = File.ReadAllText(Path);
string newContent = Regex.Replace(content, "AssemblyVersion\\(\\\"(.*)\\\"\\)", "AssemblyVersion(\"" + Version + "\")");
newContent = Regex.Replace(newContent, "AssemblyFileVersion\\(\\\"(.*)\\\"\\)", "AssemblyFileVersion(\"" + Version + "\")");
string newContent = Regex.Replace(content, "AssemblyFileVersion\\(\\\"(.*)\\\"\\)", "AssemblyFileVersion(\"" + Version + "\")");
string v2 = Version.Replace(".", ", ");
v2 = ", " + v2.Remove(v2.LastIndexOf(','));
newContent = Regex.Replace(newContent, "KSPAssembly\\(\\\"KSPCommunityFixes\\\"(.*)\\)", "KSPAssembly(\"KSPCommunityFixes\"" + v2 + ")");
if (content != newContent)
File.WriteAllText(Path, newContent);
]]></Code>
Expand Down
87 changes: 36 additions & 51 deletions KSPCommunityFixes/Modding/PersistentIConfigNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -654,86 +654,71 @@ public static object ReadValue(string value, DataType dataType, Type fieldType)
}

public static bool WriteValue(string fieldName, object value, DataType dataType, ConfigNode node)
{
string v = WriteValue(value, dataType);
if (v == null)
return false;

node._values.values.Add(new Value(fieldName, v));
return true;
}

public static string WriteValue(object value, DataType dataType)
{
switch (dataType)
{
case DataType.ValueString:
node._values.values.Add(new Value(fieldName, (string)value));
return true;
return (string)value;
case DataType.ValueGuid:
node._values.values.Add(new Value(fieldName, ((Guid)value).ToString()));
return true;
return ((Guid)value).ToString();
case DataType.ValueBool:
node._values.values.Add(new Value(fieldName, ((bool)value).ToString(_Invariant)));
return true;
return ((bool)value).ToString(_Invariant);
case DataType.ValueDouble:
node._values.values.Add(new Value(fieldName, ((double)value).ToString("G17")));
return true;
return ((double)value).ToString("G17");
case DataType.ValueFloat:
node._values.values.Add(new Value(fieldName, ((float)value).ToString("G9")));
return true;
return ((float)value).ToString("G9");
case DataType.ValueDecimal:
node._values.values.Add(new Value(fieldName, ((decimal)value).ToString(_Invariant)));
return true;
return ((decimal)value).ToString(_Invariant);
case DataType.ValueInt:
node._values.values.Add(new Value(fieldName, ((int)value).ToString(_Invariant)));
return true;
return ((int)value).ToString(_Invariant);
case DataType.ValueUInt:
node._values.values.Add(new Value(fieldName, ((uint)value).ToString(_Invariant)));
return true;
return ((uint)value).ToString(_Invariant);
case DataType.ValueChar:
node._values.values.Add(new Value(fieldName, ((char)value).ToString(_Invariant)));
return true;
return ((char)value).ToString(_Invariant);
case DataType.ValueShort:
node._values.values.Add(new Value(fieldName, ((short)value).ToString(_Invariant)));
return true;
return ((short)value).ToString(_Invariant);
case DataType.ValueUShort:
node._values.values.Add(new Value(fieldName, ((ushort)value).ToString(_Invariant)));
return true;
return ((ushort)value).ToString(_Invariant);
case DataType.ValueLong:
node._values.values.Add(new Value(fieldName, ((long)value).ToString(_Invariant)));
return true;
return ((long)value).ToString(_Invariant);
case DataType.ValueULong:
node._values.values.Add(new Value(fieldName, ((ulong)value).ToString(_Invariant)));
return true;
return ((ulong)value).ToString(_Invariant);
case DataType.ValueByte:
node._values.values.Add(new Value(fieldName, ((byte)value).ToString(_Invariant)));
return true;
return ((byte)value).ToString(_Invariant);
case DataType.ValueSByte:
node._values.values.Add(new Value(fieldName, ((sbyte)value).ToString(_Invariant)));
return true;
return ((sbyte)value).ToString(_Invariant);
case DataType.ValueEnum:
node._values.values.Add(new Value(fieldName, ((System.Enum)value).ToString()));
return true;
return ((System.Enum)value).ToString();
case DataType.ValueVector2:
node._values.values.Add(new Value(fieldName, WriteVector((Vector2)value)));
return true;
return WriteVector((Vector2)value);
case DataType.ValueVector3:
node._values.values.Add(new Value(fieldName, WriteVector((Vector3)value)));
return true;
return WriteVector((Vector3)value);
case DataType.ValueVector3d:
node._values.values.Add(new Value(fieldName, WriteVector((Vector3)value)));
return true;
return WriteVector((Vector3)value);
case DataType.ValueVector4:
node._values.values.Add(new Value(fieldName, WriteVector((Vector4)value)));
return true;
return WriteVector((Vector4)value);
case DataType.ValueQuaternion:
node._values.values.Add(new Value(fieldName, WriteQuaternion((Quaternion)value)));
return true;
return WriteQuaternion((Quaternion)value);
case DataType.ValueQuaternionD:
node._values.values.Add(new Value(fieldName, WriteQuaternion((QuaternionD)value)));
return true;
return WriteQuaternion((QuaternionD)value);
case DataType.ValueMatrix4x4:
node._values.values.Add(new Value(fieldName, WriteMatrix4x4((Matrix4x4)value)));
return true;
return WriteMatrix4x4((Matrix4x4)value);
case DataType.ValueColor:
node._values.values.Add(new Value(fieldName, WriteColor((Color)value)));
return true;
return WriteColor((Color)value);
case DataType.ValueColor32:
node._values.values.Add(new Value(fieldName, WriteColor((Color32)value)));
return true;
return WriteColor((Color32)value);
}
return false;
return null;
}

public static DataType ValueDataType(Type fieldType)
Expand Down
7 changes: 4 additions & 3 deletions KSPCommunityFixes/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.22.0.0")]
[assembly: AssemblyFileVersion("1.22.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.22.1.0")]

[assembly: KSPAssembly("KSPCommunityFixes", 1, 22, 0)]
[assembly: KSPAssembly("KSPCommunityFixes", 1, 22, 1)]
[assembly: KSPAssemblyDependency("MultipleModulePartAPI", 1, 0, 0)]
4 changes: 4 additions & 0 deletions MultipleModuleInPartAPI/MultipleModuleInPartAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
<Name>System.Core (KSP/Mono)</Name>
<Private>False</Private>
</Reference>
<Reference Include="$(ManagedPath)\Assembly-CSharp.dll">
<Name>Assembly-CSharp</Name>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="IMultipleModuleInPart.cs" />
Expand Down
2 changes: 2 additions & 0 deletions MultipleModuleInPartAPI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

[assembly: KSPAssembly("MultipleModulePartAPI", 1, 0, 0)]
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ If doing so in the `Debug` configuration and if your KSP install is modified to

### Changelog

##### 1.22.1
- Add KSPAssembly attribute to MultipleModulePartAPI as well, and add the KSPAssemblyDependency to KSPCommunityFixes just in case.
- Set AssemblyVersion to 1.0 and only increment AssemblyFileVersion and KSPAssembly
- Refactor FieldData.WriteValue for ease in use by other mods.

##### 1.22.0
- New modding patch : [ModUpgradePipeline](https://github.com/KSPModdingLibs/KSPCommunityFixes/pull/91) (@NathanKell)
- Further improve ConfigNode performance. The tunable settings blocks have been removed since base performance is high enough now. They've been replaced by a single setting that enables not indenting save games and craft files on save, which offers a slight performance boost reading and writing and a fair amount of savings on disk. See https://github.com/KSPModdingLibs/KSPCommunityFixes/pull/90 for full details. Note that some of this rewrite is done via PersistentIConfigNode. (@NathanKell)
Expand Down

0 comments on commit af6ea83

Please sign in to comment.