Description Modifiers - wofsauge/External-Item-Descriptions GitHub Wiki
Modifiers are a powerful tool to alter any description on the fly. This can be used for a lot of usecases, for example for adding informations, altering parts or completely rewriting the content.
How it works
Modifiers are defined by two parts:
- Condition function: The condition function is used to define, when the description should be modified. This can be used to limit the modifier to only trigger for certain objects.
- Callback function: The callback function does the altering. It will only be executed when the condition function returned
true
.
When these functions are defined, we need to register them using the EID:addDescriptionModifier(ModifierName, conditionFunction, callbackFunction)
function. The first value should be a unique name for the modifier. the second one is the condition function, and the last one is the callback function.
Description Object Attributes
Each modifier function receives the currently handled Description Object as a parameter. This object contains every known informations about the entity and the EID descriptions of it. It contains the following attributes:
- ObjType: Type of the described entity. Example:
5
- ObjVariant: Variant of the described entity. Example:
100
- ObjSubType: SubType of the described entity. Example for Sad Onion:
1
- fullItemString: Combined string that describes the entity. Example for Sad Onion:
"5.100.1"
- Name: Translated EID object name. Example for Sad Onion:
"Sad Onion"
or"ζ²δΌ€ζ΄θ±"
when chinese language is active - Description: Unformatted but translated EID description. Example for Sad Onion:
"β +0.7 Tears up"
orβ +0.7ε°ι"
when chinese language is active - Transformation: EID Transformation information object.
- ModName: Name of the mod this item comes from. Can be nil!
- Quality: Quality of the displayed object. Number between 0 and 4. Set to nil to remove it.
- Icon: Object icon displayed in the top left of the description. Set to nil to not display it. Format like any EID icon:
{Animationname, Frame, Width, Height, LeftOffset [Default: -1], TopOffset [Default: 0], SpriteObject [Default: EID.InlineIconSprite]}
- Entity: Entity Object which currently is described.
- ShowWhenUnidentified: Allows description modifiers to be shown when the pill is still unidentified
Example
--
local function myModifierCondition(descObj) -- descObj contains all informations about the currently described entity
if descObj.ObjType == 5 and descObj.ObjVariant == 100 and descObj.ObjSubType == 1 then return true end -- if entity is Sad onion returns true. This will execute the callback
end
local function myModifierCallback(descObj)
-- alter the description object as you like
EID:appendToDescription(descObj, "#Some new bulletpoint appended to the description")
return descObj -- return the modified description object
end
-- Register the modifier with a unique name
EID:addDescriptionModifier("My new Modifier", myModifierCondition, myModifierCallback)
Result: