Class ContractXmlCodec
java.lang.Object
mekhq.campaign.mission.contract.io.ContractXmlCodec
XML serialization and deserialization for
AbstractContract and its data records.
AbstractContract is intentionally a pure data class with no logic, so the (de)serialization lives here
rather than on the type itself. Writing uses MekHQ's standard PrintWriter / MHQXMLUtility tag
helpers. Reading uses a map-lookup: each element under a <contract> node is dispatched by its tag
name to a handler in READERS, mirroring the pattern used by CampaignOptionsUnmarshaller /
CampaignOptionCodecs.
The concrete subclass (ChaosContract, ChaosActOfPiracy, ChaosGameWorlds) is recorded as
the type attribute of the <contract> element and reinstated by reflection on load, exactly as
Scenario and Person do. Transient fields (the cached jump path and cached difficulty) are not
persisted.
- Since:
- 0.51.01
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic AbstractContractreadContract(Node node, Campaign campaign, megamek.Version version) Reconstructs a single contract from a<contract>element.static voidwriteContract(PrintWriter printWriter, int indent, AbstractContract contract, Campaign campaign) Writes a single contract as a<contract>element.
-
Field Details
-
CONTRACT_TAG
- See Also:
-
-
Method Details
-
writeContract
public static void writeContract(PrintWriter printWriter, int indent, AbstractContract contract, Campaign campaign) Writes a single contract as a<contract>element.- Parameters:
printWriter- the writer to emit toindent- the indentation level of the<contract>elementcontract- the contract to serializecampaign- the owning campaign (required to serialize nestedPersonnegotiators)
-
readContract
@Nullable public static AbstractContract readContract(Node node, Campaign campaign, megamek.Version version) Reconstructs a single contract from a<contract>element.- Parameters:
node- the<contract>elementcampaign- the owning campaignversion- the save file's version- Returns:
- the reconstructed contract, or
nullif its concrete type could not be instantiated
-