Upgrade Trainworks Tutorial - brandonandzeus/Trainworks2 GitHub Wiki
Switching from Trainworks V1 to Trainworks V2.
If you already have code written for Trainworks prior to November 2023 or already have a mod written for Monster Train using Trainworks Modding Tools this page is for you.
Why switch?
There have been a number of improvements (speed and design-wise) and bug fixes to the modding framework.
- Support for many things added in the DLC that weren't included before. Unit synthesis builder objects are now a part of CharacterDataBuilder.
- Various Bug fixes for known issues especially with custom clans and enhancers. See the following issues from the original repo:
- New builders are outlined below.
However, the upgrade is opt-in, meaning you will have to switch the following using statements in your code to use the newer Builders. This is done to not change the behavior of existing mods. For instance, some mods may have depended on certain behavior or attempted to fix bugs in the framework within their own mod, so to not break existing mods the newer code is opt-in.
using Trainworks.Builders > using Trainworks.BuildersV2
using Trainworks.Constants > using Trainworks.ConstantsV2
However, this isn't a drop-in replacement. API changes will break existing code, hence the newer namespaces. Most of the breaking changes were done to keep the framework consistent or prevent logic errors in code. Some Builders may require a unique ID where it did not previously (to generate localization keys). Here I will attempt to list all of the incompatible changes or renamed properties or inform of new properties to make the code more concise. Bolded changes are potentially breaking API changes.
CardDataBuilder
- Removed Property
LinkedClass. UseClanIDinstead. Having both was a confusing interface to indicate whether or not the card was clanless. - Removed Property
FallbackData. Unnecessary this should set itself. - Removed functions
SetClan(UseClanIDproperty instead) andAddToCardPool(useCardPoolIDsproperty instead). - Added
InitialKeyboardTargetandRequireDLC. - New property
StartingUpgradeBuilderswhich is a convenience builder forStartingUpgrades.
CardEffectDataBuilder
- Property
EffectStateNameis no longer settable. Use PropertyEffectStateTypeinstead. This is to prevent bugs like this from occurring. The framework will now compute the appropriate class name from the Type info passed in. (Essentially, Vanilla Effects will output the class name, and Custom Effects will output the fully qualified class name with assembly info). - Property
ParamStatusEffectsis no longer an Array. It is now a List. Setting the parameter is now less typing. That is, instead of
The code is nowParamStatusEffects = new StatusEffectStackData[] { new StatusEffectStackData {...} }ParamStatusEffects = { new StatusEffectStackData {...} } - Property
AdditionalTooltipsis no longer an Array. It too is now a list. - Property
ParamSubtypenow defaults to Subtype_None. This was actually a required Param for many CardEffects to work and can not default to null or empty string. - Property
TargetCharacterSubtypealso defaults to Subtype_None. for the same reasons above. - Removed function
AddStatusEffectYou can simply append the status effect to the end of the list. - New Property
ParamCardUpgradeDataBuilderConvenience builder forParamCardUpgradeData. If this is set, then it overrides the value ofParamCardUpgradeData - New Property
ParamCharacterDataBuilderfor the same reasons as above. - Added Property
ParamAdditionalCharacterData,ParamCharacterDataPool,ParamCharacterDataPoolBuilder.
CardPoolDataBuilder
- No changes
CardTraitDataBuilder
- Property
TraitStateNameis no longer settable. UseTraitStateTypeinstead. See:EffectStateNameinCardEffectDataBuilderfor details why. - Property
ParamStatusEffectsis a list now. SeeCardEffectDataBuilderfor the reason. - Fixed Bug CardTraits previously had their
ParamCardDataset to theCardDataof where the trait was applied. This is a bug in Trainworks V1 that prevents Custom Cards with Traits that do something withParamCardDatanot to work as expected. - Property
ParamSubtypedefaults to Subtype_None. - Property
ParamTeamTypedefaults to Team.Type.Heroes. - Property
ParamFloatdefaults to 1f. - Added property
ParamCardUpgradeDataand convenience builderParamCardUpgradeDataBuilder. - Added property
TraitIsRemovable. - Added property
StackMode.
CardTriggerEffectDataBuilder
- New required Property
TriggerID. This must be set to ensure unique localization keys are generated. If this is not set, an exception will be thrown. This is to prevent bugs like this from happening. - Added convenience static function
MakeCardTrigger.
CardUpgradeDataBuilder
- New required Property
UpgradeID.. PreviouslyUpgradeTitlewas required; it no longer is since that property is not always required. - Renamed
UpgradeIconPathtoAssetPath. This keeps consistency with other Builders. - Added new properties
IsUnique,LickedPactDuplicateRarity,SourceSynthesisUnit, andIsUnitSynthesisUpgrade
IMPORTANT When migrating set UpgradeID to what UpgradeTitleKey was, add this code after you've built the upgrade.
GameDataMigrationManager.MigrateOldCardUpgradeID(UpgradeID, builtCardUpgrade.GetID())
This will preserve runs from the older CardUpgradeDataBuilder
CardUpgradeMaskDataBuilder
- New required Property
CardUpgradeMaskID. Not a hard requirement to set this and will throw a warning if unset, but technically the object should have a name.
CardUpgradeTreeDataBuilder
- No major changes
ChampionCardDataBuilder
- Property
StarterCardDatarenamed toStarterCardID. This is to keep properties across builders consistent.
CharacterDataBuilder
- Property
StartingStatusEffectsis now a list. - Removed Property
FallbackData. - Added Property CharacterChatterDataBuilder.
- Added new properties
BlockVisualSizeIncrease,BypassPactCrystalsUpgradeDataList,PactCrystalsRequiredCount,PactCrystalsVariantData,RemoveTriggersOnRelentlessChange,ValidBossAttackPhase,
CharacterChatterDataBuilder
- NEW thanks to ThreeFishes for the original implementation that was adopted.
CharacterTriggerDataBuilder
- New required Property
TriggerID. This must be set to ensure unique localization keys are generated. If this is not set, an exception will be thrown. This is to prevent bugs like this from happening.
ClassDataBuilder
- Removed Properties
MainClassStartingCardsand SubClassStartingCards`. These are unused in the Builder and in the Monster Train source code. - Added new properties
CorruptionEnabled,StarterCardUpgrade,StarterCardUpgradeBuilder,RandomDraftEnhancerPool,RandomDraftEnhancerPoolBuilder.
CollectableRelicDataBuilder
- Removed Property
LinkedClassUseClanIDinstead. Having both was a confusing interface to indicate whether or not the relic was clanless. - Added new properties
IgnoreForNoRelicAchievement,DivineVariant,RelicLoreTooltipStyle, andRequiredDLC.
DraftRewardDataBuilder
- Renamed
_RewardTitleKey,_RewardDescriptionKey, and_RewardSpritePathtoNameKey,DescriptionKey, andAssetPathrespectively. This is to keep consistency among other Builders. - Removed
SaveManagerproperty. - Removed the leading _ in property names
ShowCancelOverride,ShowRewardFlowInEvent,CollectSFXCuename, andMerchantServiceIndex. NameKeyandDescriptionKeyare now set automatically by DraftRewardID.- Added new property
Crystals. - It is not required to call BuildAndRegister for this builder. Calling Build() will automatically register the DraftRewardData. This is to allow ease of use in using this builder within other builders.
EnhancerDataBuilder
- Bug Fix Use CustomEnhancerManager to query for Enhancers. The new class uses this Manager to register Enhancers. The older Builder/Manager has a bug, in which, the EnhancerData wasn't added to the GameData, causing Spell/Unit Merchants to fail to load and showing the fallback merchant when the game was reloaded.
- Renamed
IDtoEnhancerID. This is to keep things consistent among builders.EnhancerIDnow setsNameKeyandDescriptionKey. NameandDescriptionare no longer set by default.- Added
UnlockLevel - Added
UpgradeBuilderfor convenience if set overrides Upgrade.
EnhancerPoolBuilder
- NEW
MutatorDataBuilder
- NEW
RandomChampionPoolBuilder
- NEW
RelicEffectConditionBuilder
ParamSubtypenow defaults to Subtype_None.
RelicEffectDataBuilder
- Property
RelicEffectClassNameis no longer settable. UseRelicEffectClassTypeinstead. See:EffectStateNameinCardEffectDataBuilderfor details on why. - Properties
TooltipBodyKeyandTooltipTitleKeyare no longer set by default. These shouldn't be too commonly used, and using the Class Name is a bad identifier to use since the strings can be much longer than just the class name. Again See:EffectStateNameinCardEffectDataBuilder AdditionalTooltipsis now a List instead of an Array. This is to keep consistency withCardEffectDataBuilder.ParamCharacterSubtypenow defaults to Subtype_None.- Added
CardTriggers. - Added
ParamCardUpgradeDataBuilder. - Added
ParamCardFilterBuilder. - Added
ParamCardPoolBuilder - Added
ParamEnhancerPoolandParamEnhancerPoolBuilder. - Added
ParamRandomChampionPooland convenience builderParamRandomChampionPoolBuilder. - Added
ExcludedTraitBuildersconvenience builder forExcludedTraits.
RewardNodeDataBuilder
- Renamed
TooltipTitleKeyandTooltipBodyKeytoNameKeyandDescriptionKeyrespectively. - Property
RewardNodeIDnow setsNameKeyandDescriptionKey. - Renamed
RequiredClasstoRequiredClassIDthis is now the ID of the Clan. This was done to keep consistency across Builders. - Added
UseFormattedOverrideTooltipTitle,DlcHellhorgedCrystalsCost, andRequiredDLC
RoomModifierDataBuilder
- New Soft-Required Property
RoomModifierID. Previously RoomModifierClassName was used to set the localization keys. Using the class name to generate the key isn't a good design since it may be a long string especially if the RoomModifier is a custom class. If unset a warning message is printed. - Properties
ExtraTooltipBodyKeyandExtraTooltipTitleKeyare no longer set by default. This should fix this issue ParamStatusEffectsis now a list rather than an Array.- Removed Property
Icon. Please use PropertyIconPathinstead. This change was made to keep consistency with other Builders. - Removed function
AddStartingStatusEffect. Just append toParamStatusEffectsinstead. ParamSubtypenow defaults to Subtype_None.- Added
ParamCardUpgradeDataandParamCardUpgradeDataBuilder.
ScenarioDataBuilder (and dependencies)
- NEW
SinsDataBuilder
- NEW
SpChallengeDataBuilder
- NEW
StatusEffectDataBuilder
StatusEffectStateNameis no longer settable. See the notes ofEffectStateNameinCardEffectDataBuilder- Renamed
StatusIdtoStatusID. This is to keep consistency with other Builders. - Setting Property
StatusIDwill now generate a localization key inStatusIDKey. - Added Properties
NameandDescription. - Added Property
AdditionalTriggerStages. - Added Properties
RemoveAtEndOfTurnIfTriggered,ShowOnPyreHeart, andVFXDisplayType.
SubtypeDataBuilder
- Removed the leading '_' from all Properties.
- Added property
IsPyre.
TrialDataBuilder
- NEW