MegaMekParser.Mtf 1.1.2

dotnet add package MegaMekParser.Mtf --version 1.1.2
                    
NuGet\Install-Package MegaMekParser.Mtf -Version 1.1.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MegaMekParser.Mtf" Version="1.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MegaMekParser.Mtf" Version="1.1.2" />
                    
Directory.Packages.props
<PackageReference Include="MegaMekParser.Mtf" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MegaMekParser.Mtf --version 1.1.2
                    
#r "nuget: MegaMekParser.Mtf, 1.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MegaMekParser.Mtf@1.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MegaMekParser.Mtf&version=1.1.2
                    
Install as a Cake Addin
#tool nuget:?package=MegaMekParser.Mtf&version=1.1.2
                    
Install as a Cake Tool

MegaMekParser.Mtf

MegaMekParser.Mtf is a .NET library for parsing BattleTech MegaMek MTF (Mech Template Format) files. This package provides the ability to load and parse MTF files into strongly-typed C# objects.

Features

  • Parse MTF files into domain models
  • Support for all standard MTF sections
  • Mech quirk parsing
  • Weapon and equipment recognition
  • Complete mech data representation

Installation

dotnet add package MegaMekParser.Mtf

Usage

using MegaMekParser.Mtf.Parsers;
using MegaMekAbstractions.Parsers.Interfaces;
using System.Text.Json;

// Load MTF file content
string mtfContent = await File.ReadAllTextAsync("path/to/mech.mtf");

// Parse the MTF file
IMtfParser parser = new MtfParser();
var mech = await parser.ParseMechDataAsync(mtfContent);

// Access mech properties
Console.WriteLine($"Mech: {mech.Chassis} {mech.Model}");
Console.WriteLine($"Mass: {mech.Mass} tons");
Console.WriteLine($"Tech Base: {mech.TechBase}");

// Get quirks
if (mech.Quirks.Any())
{
    Console.WriteLine("Quirks:");
    foreach (var quirk in mech.Quirks)
    {
        Console.WriteLine($"- {quirk}");
    }
}

Command-line Usage Example

Create a simple viewer app:

using MegaMekParser.Mtf.Parsers;
using MegaMekAbstractions.Parsers.Interfaces;
using System.Text.Json;
using System.Text.Json.Serialization;

if (args.Length == 0)
{
    Console.WriteLine("Please provide a path to an MTF file.");
    return;
}

var filePath = args[0];
if (!File.Exists(filePath))
{
    Console.WriteLine($"File not found: {filePath}");
    return;
}

try
{
    var content = await File.ReadAllTextAsync(filePath);
    IMtfParser parser = new MtfParser();
    var mech = await parser.ParseMechDataAsync(content);

    // Pretty print the mech details as JSON
    var options = new JsonSerializerOptions
    {
        WriteIndented = true,
        DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
        Converters = { new JsonStringEnumConverter() }
    };
    
    var json = JsonSerializer.Serialize(mech, options);
    Console.WriteLine(json);
}
catch (Exception ex)
{
    Console.WriteLine($"Error parsing file: {ex.Message}");
}

License

MIT

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.2 230 4/22/2025
1.1.1 223 4/21/2025
1.1.0 215 4/21/2025
1.0.0 218 4/21/2025