Skip to content

Commit 9e61d85

Browse files
authored
Merge pull request #9 from nalathethird/update-to-net10
Update to net10 and remove verbose logging
2 parents 6859ea1 + 9600680 commit 9e61d85

3 files changed

Lines changed: 71 additions & 77 deletions

File tree

Numantics.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.9.34728.123
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "R-Numantics", "Numantics\R-Numantics.csproj", "{659110F4-88CB-4FF4-A510-08BB64DB6ACD}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Numantics", "Numantics\Numantics.csproj", "{659110F4-88CB-4FF4-A510-08BB64DB6ACD}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution

Numantics/Numantics.cs

Lines changed: 23 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace Numantics {
1414
public class Numantics : ResoniteMod {
15-
internal const string VERSION_CONSTANT = "1.0.2";
15+
internal const string VERSION_CONSTANT = "1.0.3";
1616
public override string Name => "Numantics";
1717
public override string Author => "NalaTheThird";
1818
public override string Version => VERSION_CONSTANT;
@@ -30,10 +30,6 @@ public class Numantics : ResoniteMod {
3030
private static readonly ModConfigurationKey<bool> RoundResults =
3131
new ModConfigurationKey<bool>("round_results", "Round all calculated results to nearest integer (e.g., 5*0.5=3 instead of 2.5)", () => false);
3232

33-
[AutoRegisterConfigKey]
34-
private static readonly ModConfigurationKey<bool> VerboseLogging =
35-
new ModConfigurationKey<bool>("verbose_logging", "Enables Verbose Logging (Not Likely needed for regular folks)", () => false);
36-
3733
private static ModConfiguration Config;
3834

3935
public override void OnEngineInit() {
@@ -49,11 +45,7 @@ public override void OnEngineInit() {
4945
class TextEditor_OnFinished_Patch {
5046
static void Prefix(TextEditor __instance) {
5147
try {
52-
bool verbose = Config?.GetValue(VerboseLogging) ?? false;
53-
54-
5548
if (__instance?.Text?.Target == null) {
56-
if (verbose) Msg("TextEditor or Text.Target is null, skipping");
5749
return;
5850
}
5951

@@ -63,81 +55,58 @@ static void Prefix(TextEditor __instance) {
6355
}
6456

6557
if (!Config.GetValue(EnableValueFieldMath)) {
66-
if (verbose) Msg("Math evaluation is disabled in config");
6758
return;
6859
}
6960

7061
string text = __instance.Text.Target.Text;
71-
if (verbose) Msg($"Input text: '{text}'");
7262

7363
if (string.IsNullOrWhiteSpace(text)) {
74-
if (verbose) Msg("Text is null or whitespace, skipping");
7564
return;
7665
}
7766

78-
Type fieldType = GetFieldType(__instance, verbose);
67+
Type fieldType = GetFieldType(__instance, false);
7968
bool isStringField = fieldType == typeof(string);
8069

81-
if (verbose) Msg($"Detected field type: {fieldType?.Name ?? "Unknown"}");
82-
8370
if (isStringField) {
8471
if (!Config.GetValue(IncludeStrings)) {
85-
if (verbose) Msg("Editing string field but include_strings is disabled, skipping");
8672
return;
8773
}
88-
if (verbose) Msg("String field detected and include_strings is enabled");
8974
}
9075

91-
// Storage for EE.
9276
string originalText = text.Replace(" ", "");
9377

9478
text = text.Replace("pi", Math.PI.ToString(CultureInfo.InvariantCulture));
95-
if (verbose && text != originalText) {
96-
Msg("Replaced 'pi' constant");
97-
}
9879

99-
string exprText = ProcessMathFunctions(text, verbose);
80+
string exprText = ProcessMathFunctions(text, false);
10081

101-
// Shorthand ops - with regex to avoid breaking function names
10282
exprText = Regex.Replace(exprText, @"(?<![a-zA-Z])x(?![a-zA-Z])", "*");
10383
exprText = Regex.Replace(exprText, @"(?<![a-zA-Z])d(?![a-zA-Z])", "/");
10484
exprText = Regex.Replace(exprText, @"(?<![a-zA-Z])a(?![a-zA-Z])", "+");
10585
exprText = Regex.Replace(exprText, @"(?<![a-zA-Z])s(?![a-zA-Z])", "-");
10686
exprText = exprText.Replace("^", "^");
10787

108-
if (verbose && exprText != text) {
109-
Msg($"Replaced operators: '{text}' => '{exprText}'");
110-
}
111-
11288
// Expression Evaluator - If you cant express it, you cant impress it! | Main Logic for Math Evaluation
113-
if (TryEvaluateExpression(exprText, out string result, verbose)) {
89+
if (TryEvaluateExpression(exprText, out string result, false)) {
11490
if (Config.GetValue(RoundResults)) {
11591
if (double.TryParse(result, NumberStyles.Float, CultureInfo.InvariantCulture, out double value)) {
11692
double rounded = Math.Round(value, MidpointRounding.AwayFromZero);
117-
if (verbose) Msg($"Rounded {value} to {rounded}");
11893
result = rounded.ToString(CultureInfo.InvariantCulture);
11994
}
12095
}
12196

122-
Msg($"SUCCESS - Evaluated '{originalText}' => '{result}'");
97+
Debug($"SUCCESS - Evaluated '{originalText}' => '{result}'");
12398
__instance.Text.Target.Text = result;
124-
125-
if (verbose) Msg($"Updated Text.Target.Text to '{result}'");
12699
} else {
127100
if (double.TryParse(exprText, NumberStyles.Float, CultureInfo.InvariantCulture, out double numValue)) {
128101
string numResult = numValue.ToString(CultureInfo.InvariantCulture);
129102

130103
if (Config.GetValue(RoundResults)) {
131104
double rounded = Math.Round(numValue, MidpointRounding.AwayFromZero);
132-
if (verbose) Msg($"Rounded {numValue} to {rounded}");
133105
numResult = rounded.ToString(CultureInfo.InvariantCulture);
134106
}
135107

136-
Msg($"SUCCESS - Evaluated '{originalText}' => '{numResult}'");
108+
Debug($"SUCCESS - Evaluated '{originalText}' => '{numResult}'");
137109
__instance.Text.Target.Text = numResult;
138-
if (verbose) Msg($"Updated Text.Target.Text to '{numResult}'");
139-
} else {
140-
if (verbose) Msg($"Not a math expression or evaluation failed: '{exprText}'");
141110
}
142111
}
143112
} catch (Exception e) {
@@ -174,7 +143,6 @@ private static Type GetFieldType(TextEditor editor, bool verbose) {
174143
if (targetTypeProp != null) {
175144
var targetType = targetTypeProp.GetValue(accessor) as Type;
176145
if (targetType != null) {
177-
if (verbose) Msg($"Found field type from MemberEditor.Accessor: {targetType.Name}");
178146
return targetType;
179147
}
180148
}
@@ -183,7 +151,6 @@ private static Type GetFieldType(TextEditor editor, bool verbose) {
183151
}
184152

185153
if (editor.Text.Target is IField directField) {
186-
if (verbose) Msg($"Text.Target is IField: {directField.ValueType.Name}");
187154
return directField.ValueType;
188155
}
189156

@@ -195,7 +162,6 @@ private static Type GetFieldType(TextEditor editor, bool verbose) {
195162
if (genericTypeDef == typeof(ValueField<>)) {
196163
var genericArgs = component.GetType().GetGenericArguments();
197164
if (genericArgs.Length > 0) {
198-
if (verbose) Msg($"Found ValueField<{genericArgs[0].Name}>");
199165
return genericArgs[0];
200166
}
201167
}
@@ -206,7 +172,6 @@ private static Type GetFieldType(TextEditor editor, bool verbose) {
206172
if (slot != null) {
207173
var parentField = slot.GetComponentInParents<IField>();
208174
if (parentField != null) {
209-
if (verbose) Msg($"Found IField in parents: {parentField.ValueType.Name}");
210175
return parentField.ValueType;
211176
}
212177
}
@@ -216,39 +181,36 @@ private static Type GetFieldType(TextEditor editor, bool verbose) {
216181
// Fallback: check editors slot hierarchy - JUSTTT in-case all the above fails. (which, I doubt it wont, but hey, safety first!)
217182
var editorField = editor.Slot.GetComponentInParents<IField>();
218183
if (editorField != null) {
219-
if (verbose) Msg($"Found IField from editor slot: {editorField.ValueType.Name}");
220184
return editorField.ValueType;
221185
}
222186

223-
if (verbose) Msg("Could not determine field type");
224187
return null;
225-
} catch (Exception ex) {
226-
if (verbose) Warn($"Error detecting field type: {ex.Message}");
188+
} catch {
227189
return null;
228190
}
229191
}
230192

231-
private static string ProcessMathFunctions(string input, bool verbose) {
193+
private static string ProcessMathFunctions(string input, bool _) {
232194
string processed = input;
233195

234-
processed = ProcessFunction(processed, "sqrt", Math.Sqrt, verbose);
235-
processed = ProcessFunction(processed, "sin", x => Math.Sin(x * Math.PI / 180.0), verbose);
236-
processed = ProcessFunction(processed, "cos", x => Math.Cos(x * Math.PI / 180.0), verbose);
237-
processed = ProcessFunction(processed, "tan", x => Math.Tan(x * Math.PI / 180.0), verbose);
238-
processed = ProcessFunction(processed, "asin", x => Math.Asin(x) * 180.0 / Math.PI, verbose);
239-
processed = ProcessFunction(processed, "acos", x => Math.Acos(x) * 180.0 / Math.PI, verbose);
240-
processed = ProcessFunction(processed, "atan", x => Math.Atan(x) * 180.0 / Math.PI, verbose);
241-
processed = ProcessFunction(processed, "log10", Math.Log10, verbose);
242-
processed = ProcessFunction(processed, "log", Math.Log, verbose);
243-
processed = ProcessFunction(processed, "ln", Math.Log, verbose);
244-
processed = ProcessFunction(processed, "abs", Math.Abs, verbose);
245-
processed = ProcessFunction(processed, "floor", Math.Floor, verbose);
246-
processed = ProcessFunction(processed, "ceil", Math.Ceiling, verbose);
196+
processed = ProcessFunction(processed, "sqrt", Math.Sqrt, false);
197+
processed = ProcessFunction(processed, "sin", x => Math.Sin(x * Math.PI / 180.0), false);
198+
processed = ProcessFunction(processed, "cos", x => Math.Cos(x * Math.PI / 180.0), false);
199+
processed = ProcessFunction(processed, "tan", x => Math.Tan(x * Math.PI / 180.0), false);
200+
processed = ProcessFunction(processed, "asin", x => Math.Asin(x) * 180.0 / Math.PI, false);
201+
processed = ProcessFunction(processed, "acos", x => Math.Acos(x) * 180.0 / Math.PI, false);
202+
processed = ProcessFunction(processed, "atan", x => Math.Atan(x) * 180.0 / Math.PI, false);
203+
processed = ProcessFunction(processed, "log10", Math.Log10, false);
204+
processed = ProcessFunction(processed, "log", Math.Log, false);
205+
processed = ProcessFunction(processed, "ln", Math.Log, false);
206+
processed = ProcessFunction(processed, "abs", Math.Abs, false);
207+
processed = ProcessFunction(processed, "floor", Math.Floor, false);
208+
processed = ProcessFunction(processed, "ceil", Math.Ceiling, false);
247209

248210
return processed;
249211
}
250212

251-
private static string ProcessFunction(string input, string funcName, Func<double, double> func, bool verbose) {
213+
private static string ProcessFunction(string input, string funcName, Func<double, double> func, bool _) {
252214
var regex = new Regex($@"{funcName}\(([^)]+)\)", RegexOptions.IgnoreCase);
253215
while (regex.IsMatch(input)) {
254216
var match = regex.Match(input);
@@ -262,38 +224,29 @@ private static string ProcessFunction(string input, string funcName, Func<double
262224
}
263225

264226
double funcResult = func(innerValue);
265-
266-
// Floating Point Rounding - We all float down here...
267227
funcResult = Math.Round(funcResult, 10, MidpointRounding.AwayFromZero);
268-
269228
input = input.Replace(match.Value, funcResult.ToString(CultureInfo.InvariantCulture));
270-
271-
if (verbose) Msg($"Evaluated {funcName}({innerExpr}) = {funcResult}");
272229
}
273230
return input;
274231
}
275232

276-
private static bool TryEvaluateExpression(string input, out string result, bool verbose) {
233+
private static bool TryEvaluateExpression(string input, out string result, bool _) {
277234
result = input;
278235

279236
// Container Checks - Operator, do we have a dial tone? - (basically checks for math operators then allows calculations)
280237
if (!(input.Contains("+") || input.Contains("-") || input.Contains("*") ||
281238
input.Contains("/") || input.Contains("^") || input.Contains("%"))) {
282-
if (verbose) Msg("No math operators found in input");
283239
return false;
284240
}
285241

286242
try {
287-
if (verbose) Msg($"Attempting to parse expression: '{input}'");
288-
289243
string processedInput = input;
290244

291245
// Percentage Handler - you just HAD to use these instead of decimals didn't you? For SHAME!
292246
var percentRegex = new Regex(@"(\d+(?:\.\d+)?)%");
293247
processedInput = percentRegex.Replace(processedInput, match => {
294248
double percentValue = double.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture);
295249
string converted = $"*{(percentValue / 100.0).ToString(CultureInfo.InvariantCulture)}";
296-
if (verbose) Msg($"Converted {match.Value} to {converted}");
297250
return converted;
298251
});
299252

@@ -327,8 +280,6 @@ private static bool TryEvaluateExpression(string input, out string result, bool
327280
processedInput = processedInput.Substring(0, leftStart) +
328281
powResult.ToString(CultureInfo.InvariantCulture) +
329282
processedInput.Substring(rightEnd);
330-
331-
if (verbose) Msg($"Evaluated power: {left}^{right} = {powResult}");
332283
}
333284

334285
var table = new DataTable();
@@ -337,14 +288,10 @@ private static bool TryEvaluateExpression(string input, out string result, bool
337288

338289
// Floating Point Precision Handling
339290
resultValue = Math.Round(resultValue, 7, MidpointRounding.AwayFromZero);
340-
341-
if (verbose) Msg($"Evaluated to: {resultValue}");
342-
343291
result = resultValue.ToString(CultureInfo.InvariantCulture);
344292
return true;
345293
} catch (Exception ex) {
346294
Warn($"Expression evaluation failed for '{input}': {ex.Message}");
347-
if (verbose) Warn($"Exception type: {ex.GetType().Name}");
348295
return false;
349296
}
350297
}

Numantics/Numantics.csproj

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<RootNamespace>Numantics</RootNamespace>
4+
<AssemblyName>Numantics</AssemblyName>
5+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
6+
<TargetFramework>net10.0</TargetFramework>
7+
<FileAlignment>512</FileAlignment>
8+
<LangVersion>latest</LangVersion>
9+
<Nullable>enable</Nullable>
10+
<Deterministic>true</Deterministic>
11+
<!-- Change CopyToMods to true if you'd like builds to be moved into the Mods folder automatically-->
12+
<CopyToMods Condition="'$(CopyToMods)'==''">true</CopyToMods>
13+
<DebugType Condition="'$(Configuration)'=='Debug'">embedded</DebugType>
14+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
15+
</PropertyGroup>
16+
17+
<PropertyGroup Condition="'$(ResonitePath)'==''">
18+
<!-- If you don't want to provide a ResonitePath in dotnet build, you can specify one here -->
19+
<ResonitePath>$(MSBuildThisFileDirectory)Resonite/</ResonitePath>
20+
<ResonitePath Condition="Exists('E:\SteamLibrary\steamapps\common\Resonite\')">E:\SteamLibrary\steamapps\common\Resonite\</ResonitePath>
21+
<ResonitePath Condition="Exists('C:\Program Files (x86)\Steam\steamapps\common\Resonite\')">C:\Program Files (x86)\Steam\steamapps\common\Resonite\</ResonitePath>
22+
<ResonitePath Condition="Exists('$(HOME)/.steam/steam/steamapps/common/Resonite/')">$(HOME)/.steam/steam/steamapps/common/Resonite/</ResonitePath>
23+
</PropertyGroup>
24+
25+
<ItemGroup>
26+
<Reference Include="0Harmony">
27+
<HintPath>$(ResonitePath)rml_libs\0Harmony.dll</HintPath>
28+
</Reference>
29+
<Reference Include="ResoniteModLoader">
30+
<HintPath>$(ResonitePath)Libraries\ResoniteModLoader.dll</HintPath>
31+
</Reference>
32+
<Reference Include="FrooxEngine">
33+
<HintPath>$(ResonitePath)FrooxEngine.dll</HintPath>
34+
</Reference>
35+
<Reference Include="Renderite.Shared">
36+
<HintPath>$(ResonitePath)Renderite.Shared.dll</HintPath>
37+
</Reference>
38+
<Reference Include="Elements.Core">
39+
<HintPath>$(ResonitePath)Elements.Core.dll</HintPath>
40+
</Reference>
41+
42+
</ItemGroup>
43+
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(CopyToMods)'=='true'">
44+
<Message Text="Attempting to copy $(TargetFileName) to $(ResonitePath)rml_mods" Importance="high" />
45+
<Copy SourceFiles="$(TargetDir)$(TargetFileName)" DestinationFolder="$(ResonitePath)rml_mods" ContinueOnError="true" />
46+
</Target>
47+
</Project>

0 commit comments

Comments
 (0)