Skip to content

Parse Feature Tables#59

Merged
AngeloTadeucci merged 2 commits intoMS2Community:masterfrom
Zintixx:feature
Mar 29, 2026
Merged

Parse Feature Tables#59
AngeloTadeucci merged 2 commits intoMS2Community:masterfrom
Zintixx:feature

Conversation

@Zintixx
Copy link
Copy Markdown

@Zintixx Zintixx commented Mar 29, 2026

Summary by CodeRabbit

  • New Features

    • Added two new parsing methods for reading and processing feature settings and feature configuration data from dedicated configuration files. These methods enable structured access to feature information.
  • Tests

    • Introduced test coverage for the newly added feature parsing methods to ensure proper functionality and reliability.
  • Chores

    • Version incremented to 2.4.2.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2026

📝 Walkthrough

Walkthrough

The pull request increments the package version to 2.4.2 and adds two new public parsing methods to the TableParser class: ParseFeatureSetting() and ParseFeature(). These methods deserialize XML files for feature settings and features respectively, each yielding key-value tuples. A corresponding test method validates the parsing functionality.

Changes

Cohort / File(s) Summary
Version Update
Maple2.File.Parser/Maple2.File.Parser.csproj
Incremented NuGet package version from 2.4.1 to 2.4.2.
Feature Parsing
Maple2.File.Parser/TableParser.cs
Added two XmlSerializer fields and two new public methods: ParseFeatureSetting() deserializes table/feature_setting.xml and yields setting type and Setting objects; ParseFeature() deserializes table/feature.xml and yields feature name and Feature objects.
Test Coverage
Maple2.File.Tests/TableParserTest.cs
Added TestFeatureParser() test method that enumerates results from both new parsing methods to verify functionality.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Parse Ugc Housing Point Reward #44: Adds new XmlSerializer fields and Parse methods to TableParser with version bump, following the same extension pattern.
  • Parse Smart Push #46: Extends TableParser with additional XmlSerializer fields and Parse methods (ParseSmartPush) using consistent deserialization patterns.
  • Quest Group #56: Adds new XmlSerializer field and parsing method to TableParser for additional table types (quest groups).

Suggested reviewers

  • AngeloTadeucci

Poem

🐰 The parser hops with features bright,
Two XML paths now in sight,
Settings and features, parsed with care,
Version bumped, the code runs fair!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Parse Feature Tables' directly and clearly describes the main change: adding parsing functionality for feature-related table files (feature_setting.xml and feature.xml).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
Maple2.File.Tests/TableParserTest.cs (1)

19-28: Strengthen this test beyond smoke enumeration.

This currently passes even if both parsers return empty sequences. Add minimal assertions for non-empty output and non-empty keys.

✅ Example improvement
 [TestMethod]
 public void TestFeatureParser() {
-    foreach ((_, _) in _parser.ParseFeatureSetting()) {
-        continue;
-    }
-
-    foreach ((_, _) in _parser.ParseFeature()) {
-        continue;
-    }
+    List<(string Type, Setting Setting)> settings = _parser.ParseFeatureSetting().ToList();
+    List<(string Name, Feature Feature)> features = _parser.ParseFeature().ToList();
+
+    Assert.IsTrue(settings.Count > 0, "Expected at least one feature setting.");
+    Assert.IsTrue(features.Count > 0, "Expected at least one feature.");
+    Assert.IsTrue(settings.All(s => !string.IsNullOrWhiteSpace(s.Type)));
+    Assert.IsTrue(features.All(f => !string.IsNullOrWhiteSpace(f.Name)));
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Maple2.File.Tests/TableParserTest.cs` around lines 19 - 28, The test
TestFeatureParser currently only enumerates _parser.ParseFeatureSetting() and
_parser.ParseFeature() and will pass if they return empty sequences; modify the
test to assert that each parsed sequence is not empty and that each entry
contains a non-empty key (e.g., assert collection.Any() and assert each
key/string is not null or empty) for both _parser.ParseFeatureSetting() and
_parser.ParseFeature() so the test fails when parsers return no meaningful data.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Maple2.File.Parser/TableParser.cs`:
- Around line 228-233: After deserializing with
featureSettingSerializer.Deserialize into a FeatureSetting, don't rely on
Debug.Assert; explicitly check that 'data' is not null and that 'data.setting'
and 'data.feature' are not null before iterating. In the code paths around
featureSettingSerializer.Deserialize / FeatureSetting, add null checks (and
either throw a clear exception such as
InvalidOperationException/InvalidDataException or return/yield break) or treat
the collections with a null-coalescing fallback (e.g., use
Enumerable.Empty<Setting>() / Enumerable.Empty<Feature>()) so iterating over
data.setting and data.feature cannot cause a NullReferenceException in Release
builds.

---

Nitpick comments:
In `@Maple2.File.Tests/TableParserTest.cs`:
- Around line 19-28: The test TestFeatureParser currently only enumerates
_parser.ParseFeatureSetting() and _parser.ParseFeature() and will pass if they
return empty sequences; modify the test to assert that each parsed sequence is
not empty and that each entry contains a non-empty key (e.g., assert
collection.Any() and assert each key/string is not null or empty) for both
_parser.ParseFeatureSetting() and _parser.ParseFeature() so the test fails when
parsers return no meaningful data.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ac62983d-4fec-4763-9c82-2cdbaacc2011

📥 Commits

Reviewing files that changed from the base of the PR and between 042a4a7 and 8208c7d.

📒 Files selected for processing (3)
  • Maple2.File.Parser/Maple2.File.Parser.csproj
  • Maple2.File.Parser/TableParser.cs
  • Maple2.File.Tests/TableParserTest.cs

Comment on lines +228 to +233
var data = featureSettingSerializer.Deserialize(reader) as FeatureSetting;
Debug.Assert(data != null);

foreach (Setting setting in data.setting) {
yield return (setting.type, setting);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Guard deserialization and collection nullability in release builds.

Debug.Assert on Line 229 and Line 239 won’t protect Release builds; data.setting (Line 231) and data.feature (Line 241) can still throw NullReferenceException.

🛠️ Proposed defensive fix
 public IEnumerable<(string Type, Setting Setting)> ParseFeatureSetting() {
     XmlReader reader = xmlReader.GetXmlReader(xmlReader.GetEntry("table/feature_setting.xml"));
-    var data = featureSettingSerializer.Deserialize(reader) as FeatureSetting;
-    Debug.Assert(data != null);
+    FeatureSetting data = featureSettingSerializer.Deserialize(reader) as FeatureSetting
+        ?? throw new InvalidDataException("Failed to deserialize table/feature_setting.xml");

-    foreach (Setting setting in data.setting) {
+    foreach (Setting setting in data.setting ?? Enumerable.Empty<Setting>()) {
         yield return (setting.type, setting);
     }
 }

 public IEnumerable<(string Name, Feature Feature)> ParseFeature() {
     XmlReader reader = xmlReader.GetXmlReader(xmlReader.GetEntry("table/feature.xml"));
-    var data = featureSerializer.Deserialize(reader) as FeatureRoot;
-    Debug.Assert(data != null);
+    FeatureRoot data = featureSerializer.Deserialize(reader) as FeatureRoot
+        ?? throw new InvalidDataException("Failed to deserialize table/feature.xml");

-    foreach (Feature feature in data.feature) {
+    foreach (Feature feature in data.feature ?? Enumerable.Empty<Feature>()) {
         yield return (feature.name, feature);
     }
 }

Also applies to: 238-243

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Maple2.File.Parser/TableParser.cs` around lines 228 - 233, After
deserializing with featureSettingSerializer.Deserialize into a FeatureSetting,
don't rely on Debug.Assert; explicitly check that 'data' is not null and that
'data.setting' and 'data.feature' are not null before iterating. In the code
paths around featureSettingSerializer.Deserialize / FeatureSetting, add null
checks (and either throw a clear exception such as
InvalidOperationException/InvalidDataException or return/yield break) or treat
the collections with a null-coalescing fallback (e.g., use
Enumerable.Empty<Setting>() / Enumerable.Empty<Feature>()) so iterating over
data.setting and data.feature cannot cause a NullReferenceException in Release
builds.

@AngeloTadeucci AngeloTadeucci merged commit 2fe4dd0 into MS2Community:master Mar 29, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants