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
. UseClanID
instead. 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
(UseClanID
property instead) andAddToCardPool
(useCardPoolIDs
property instead). - Added
InitialKeyboardTarget
andRequireDLC
. - New property
StartingUpgradeBuilders
which is a convenience builder forStartingUpgrades
.
CardEffectDataBuilder
- Property
EffectStateName
is no longer settable. Use PropertyEffectStateType
instead. 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
ParamStatusEffects
is 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
AdditionalTooltips
is no longer an Array. It too is now a list. - Property
ParamSubtype
now 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
TargetCharacterSubtype
also defaults to Subtype_None. for the same reasons above. - Removed function
AddStatusEffect
You can simply append the status effect to the end of the list. - New Property
ParamCardUpgradeDataBuilder
Convenience builder forParamCardUpgradeData
. If this is set, then it overrides the value ofParamCardUpgradeData
- New Property
ParamCharacterDataBuilder
for the same reasons as above. - Added Property
ParamAdditionalCharacterData
,ParamCharacterDataPool
,ParamCharacterDataPoolBuilder
.
CardPoolDataBuilder
- No changes
CardTraitDataBuilder
- Property
TraitStateName
is no longer settable. UseTraitStateType
instead. See:EffectStateName
inCardEffectDataBuilder
for details why. - Property
ParamStatusEffects
is a list now. SeeCardEffectDataBuilder
for the reason. - Fixed Bug CardTraits previously had their
ParamCardData
set to theCardData
of where the trait was applied. This is a bug in Trainworks V1 that prevents Custom Cards with Traits that do something withParamCardData
not to work as expected. - Property
ParamSubtype
defaults to Subtype_None. - Property
ParamTeamType
defaults to Team.Type.Heroes. - Property
ParamFloat
defaults to 1f. - Added property
ParamCardUpgradeData
and 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
.. PreviouslyUpgradeTitle
was required; it no longer is since that property is not always required. - Renamed
UpgradeIconPath
toAssetPath
. 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
StarterCardData
renamed toStarterCardID
. This is to keep properties across builders consistent.
CharacterDataBuilder
- Property
StartingStatusEffects
is 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
MainClassStartingCards
and 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
LinkedClass
UseClanID
instead. 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_RewardSpritePath
toNameKey
,DescriptionKey
, andAssetPath
respectively. This is to keep consistency among other Builders. - Removed
SaveManager
property. - Removed the leading _ in property names
ShowCancelOverride
,ShowRewardFlowInEvent
,CollectSFXCuename
, andMerchantServiceIndex
. NameKey
andDescriptionKey
are 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
ID
toEnhancerID
. This is to keep things consistent among builders.EnhancerID
now setsNameKey
andDescriptionKey
. Name
andDescription
are no longer set by default.- Added
UnlockLevel
- Added
UpgradeBuilder
for convenience if set overrides Upgrade.
EnhancerPoolBuilder
- NEW
MutatorDataBuilder
- NEW
RandomChampionPoolBuilder
- NEW
RelicEffectConditionBuilder
ParamSubtype
now defaults to Subtype_None.
RelicEffectDataBuilder
- Property
RelicEffectClassName
is no longer settable. UseRelicEffectClassType
instead. See:EffectStateName
inCardEffectDataBuilder
for details on why. - Properties
TooltipBodyKey
andTooltipTitleKey
are 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:EffectStateName
inCardEffectDataBuilder
AdditionalTooltips
is now a List instead of an Array. This is to keep consistency withCardEffectDataBuilder
.ParamCharacterSubtype
now defaults to Subtype_None.- Added
CardTriggers
. - Added
ParamCardUpgradeDataBuilder
. - Added
ParamCardFilterBuilder
. - Added
ParamCardPoolBuilder
- Added
ParamEnhancerPool
andParamEnhancerPoolBuilder
. - Added
ParamRandomChampionPool
and convenience builderParamRandomChampionPoolBuilder
. - Added
ExcludedTraitBuilders
convenience builder forExcludedTraits
.
RewardNodeDataBuilder
- Renamed
TooltipTitleKey
andTooltipBodyKey
toNameKey
andDescriptionKey
respectively. - Property
RewardNodeID
now setsNameKey
andDescriptionKey
. - Renamed
RequiredClass
toRequiredClassID
this 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
ExtraTooltipBodyKey
andExtraTooltipTitleKey
are no longer set by default. This should fix this issue ParamStatusEffects
is now a list rather than an Array.- Removed Property
Icon
. Please use PropertyIconPath
instead. This change was made to keep consistency with other Builders. - Removed function
AddStartingStatusEffect
. Just append toParamStatusEffects
instead. ParamSubtype
now defaults to Subtype_None.- Added
ParamCardUpgradeData
andParamCardUpgradeDataBuilder
.
ScenarioDataBuilder (and dependencies)
- NEW
SinsDataBuilder
- NEW
SpChallengeDataBuilder
- NEW
StatusEffectDataBuilder
StatusEffectStateName
is no longer settable. See the notes ofEffectStateName
inCardEffectDataBuilder
- Renamed
StatusId
toStatusID
. This is to keep consistency with other Builders. - Setting Property
StatusID
will now generate a localization key inStatusIDKey
. - Added Properties
Name
andDescription
. - Added Property
AdditionalTriggerStages
. - Added Properties
RemoveAtEndOfTurnIfTriggered
,ShowOnPyreHeart
, andVFXDisplayType
.
SubtypeDataBuilder
- Removed the leading '_' from all Properties.
- Added property
IsPyre
.
TrialDataBuilder
- NEW