Added new method to add descriptions

This commit is contained in:
Wofsauge committed 2020-11-25 23:12:31 +01:00
1 parent 3ed0daea76
commit 9c50c5ba84
3 files changed
+121 -110

No files matched your search

+96 -84
View File
@@ -57,28 +57,28 @@ local nullVector = Vector(0,0)
function EID:addCollectible(id, description, itemName, language) function EID:addCollectible(id, description, itemName, language)
itemName = itemName or nil itemName = itemName or nil
language = language or "en_us" language = language or "en_us"
EID.descriptions[language].custom["collectible_" .. id] = {id, itemName, description} EID.descriptions[language].custom["5.100." .. id] = {id, itemName, description}
end end
-- Adds a description for a trinket. Optional parameters: itemName, language -- Adds a description for a trinket. Optional parameters: itemName, language
function EID:addTrinket(id, description, itemName, language) function EID:addTrinket(id, description, itemName, language)
itemName = itemName or nil itemName = itemName or nil
language = language or "en_us" language = language or "en_us"
EID.descriptions[language].custom["trinket_" .. id] = {id, itemName, description} EID.descriptions[language].custom["5.350." .. id] = {id, itemName, description}
end end
-- Adds a description for a card/rune. Optional parameters: itemName, language -- Adds a description for a card/rune. Optional parameters: itemName, language
function EID:addCard(id, description, itemName, language) function EID:addCard(id, description, itemName, language)
itemName = itemName or nil itemName = itemName or nil
language = language or "en_us" language = language or "en_us"
EID.descriptions[language].custom["card_" .. id] = {id, itemName, description} EID.descriptions[language].custom["5.300." .. id] = {id, itemName, description}
end end
-- Adds a description for a pilleffect id. Optional parameters: itemName, language -- Adds a description for a pilleffect id. Optional parameters: itemName, language
function EID:addPill(id, description, itemName, language) function EID:addPill(id, description, itemName, language)
itemName = itemName or nil itemName = itemName or nil
language = language or "en_us" language = language or "en_us"
EID.descriptions[language].custom["pill_" .. id] = {id, itemName, description} EID.descriptions[language].custom["5.70." .. id] = {id, itemName, description}
end end
-- Creates a new transformation with a given unique name and a display name -- Creates a new transformation with a given unique name and a display name
@@ -154,13 +154,28 @@ end
-- function to turn entity type names into actual ingame ID.Variant pairs -- function to turn entity type names into actual ingame ID.Variant pairs
function EID:getIDVariantString(typeName) function EID:getIDVariantString(typeName)
if typeName == "collectible" or typeName == "collectibles" then return "5.100" if typeName == "collectible" or typeName == "collectibles" then return "5.100"
elseif typeName == "trinket" or typeName == "trinkets" then return "5.350." elseif typeName == "trinket" or typeName == "trinkets" then return "5.350"
elseif typeName == "card" or typeName == "cards" then return "5.300." elseif typeName == "card" or typeName == "cards" then return "5.300"
elseif typeName == "pill" or typeName == "pills" then return "5.70." elseif typeName == "pill" or typeName == "pills" then return "5.70"
elseif typeName == "sacrifice" then return "-999.-1"
elseif typeName == "dice" then return "-999.-2"
end end
return nil return nil
end end
-- function to turn entity typ and variants into their EID table-name
function EID:getTableName(Type, Variant)
local idString = Type.."."..Variant
if idString == "5.100" then return "collectibles"
elseif idString == "5.350" then return "trinkets"
elseif idString == "5.300" then return "cards"
elseif idString == "5.70" then return "pills"
elseif idString == "-999.-1" then return "sacrifice"
elseif idString == "-999.-2" then return "dice"
else return "custom"
end
end
-- Loads a given font from a given file path and use it to render text -- Loads a given font from a given file path and use it to render text
function EID:loadFont(fontFileName) function EID:loadFont(fontFileName)
EID.font:Load(fontFileName) EID.font:Load(fontFileName)
@@ -192,22 +207,46 @@ function EID:getLastDescribedEntity()
return EID.lastDescriptionEntity return EID.lastDescriptionEntity
end end
-- returns descriptions from the legacy mod descriptions if they exist -- returns the description object of the specified entity
function EID:getLegacyModDescription(objTable, id) -- falls back to english if the objID isnt available
id = tonumber(id) function EID:getDescriptionObj(Type, Variant, SubType)
if objTable == "collectibles" then local description = {}
return __eidItemDescriptions[id] description.ItemType = Type
elseif objTable == "trinkets" then description.ItemVariant = Variant
return __eidTrinketDescriptions[id] description.RealID = SubType
elseif objTable == "cards" then description.ID = SubType
return __eidCardDescriptions[id] if EID:getTableName(Type, Variant) =="pills" then
elseif objTable == "pills" then local pool = Game():GetItemPool()
return __eidPillDescriptions[id] description.ID = pool:GetPillEffect(SubType)+1
elseif objTable == "transformations" then
return __eidItemTransformations[id]
elseif objTable == "custom" then
return __eidEntityDescriptions[id] and __eidEntityDescriptions[id][2]
end end
description.fullItemString = Type.."."..Variant.."."..description.ID
description.Name = EID:getObjectName(Type, Variant, description.ID)
local tableEntry = EID:getDescriptionData(Type, Variant, description.ID)
description.Description = tableEntry[3] or "MISSING DESCRIPTION"
description.Transformation = EID:getTransformation(description.fullItemString)
return description
end
-- returns description Object from the legacy mod descriptions if they exist
function EID:getLegacyModDescription(Type, Variant, SubType)
local tableName = EID:getTableName(Type, Variant)
local customDesc = __eidEntityDescriptions[Type.."."..Variant.."."..SubType]
if tableName == "collectibles" and __eidItemDescriptions[SubType] then
return {"","",__eidItemDescriptions[SubType]}
elseif tableName == "trinkets" and __eidTrinketDescriptions[SubType] then
return{"","", __eidTrinketDescriptions[SubType]}
elseif tableName == "cards" and __eidCardDescriptions[SubType] then
return {"","",__eidCardDescriptions[SubType]}
elseif tableName == "pills" and __eidPillDescriptions[SubType-1] then
print(SubType)
return {"","",__eidPillDescriptions[SubType-1]}
elseif customDesc~=nil then
return {"", customDesc[1], customDesc[2]}
end
return nil
end end
-- returns the specified object table in the current language. -- returns the specified object table in the current language.
@@ -216,28 +255,17 @@ function EID:getDescriptionTable(objTable)
return EID.descriptions[EIDConfig["Language"]][objTable] or EID.descriptions["en_us"][objTable] return EID.descriptions[EIDConfig["Language"]][objTable] or EID.descriptions["en_us"][objTable]
end end
-- returns the description object of the specified object table translated with the current language -- returns the description data table related to a given id, variant and subtype
-- falls back to english if the objID isnt available -- falls back to english if it doesnt exist
function EID:getDescriptionObj(objTable, Type, Variant, SubType) function EID:getDescriptionData(Type, Variant, SubType)
objTable = objTable or "custom" local fullString = Type.."."..Variant
local tableEntry = local moddedDesc = EID.descriptions[EIDConfig["Language"]].custom[fullString.."."..SubType] or
EID.descriptions[EIDConfig["Language"]][objTable][SubType] or EID.descriptions["en_us"][objTable][SubType] or {} EID.descriptions["en_us"].custom[fullString.."."..SubType] or nil
local tableName = EID:getTableName(Type, Variant)
local description = {} local legacyModdedDescription = EID:getLegacyModDescription(Type, Variant, SubType)
description.ObjectTable = objTable local defaultDesc = EID.descriptions[EIDConfig["Language"]][tableName][SubType] or EID.descriptions["en_us"][tableName][SubType] or nil
description.ItemType = Type
description.ItemVariant = Variant return moddedDesc or legacyModdedDescription or defaultDesc
description.ID = SubType
description.Name = EID:getObjectName(SubType, objTable) or objTable
local legacyModdedDescription = EID:getLegacyModDescription(objTable, SubType)
description.Description = legacyModdedDescription or tableEntry[3] or "MISSING DESCRIPTION"
description.fullItemString = Type.."."..Variant.."."..SubType
description.Transformation = EID:getTransformation(description.fullItemString)
return description
end end
-- Get the transformation uniqueName / ID of a given "ID.Variant.Subtype" pair -- Get the transformation uniqueName / ID of a given "ID.Variant.Subtype" pair
@@ -250,7 +278,7 @@ function EID:getTransformation(entityIdentifier)
table.insert(splitString,identifier) table.insert(splitString,identifier)
end end
if splitString[1] == "5" and splitString[2] == "100" then if splitString[1] == "5" and splitString[2] == "100" then
customLegacy = EID:getLegacyModDescription("transformations", splitString[3]) customLegacy = __eidItemTransformations[splitString[3]]
end end
local default = EID.EntityTransformations[entityIdentifier] local default = EID.EntityTransformations[entityIdentifier]
return custom or customLegacy or default or "0" return custom or customLegacy or default or "0"
@@ -267,48 +295,32 @@ function EID:getTransformationName(id)
end end
return id return id
end end
return EID:getObjectName(tonumber(id) + 1, "transformations") or str return EID:getDescriptionTable("transformations")[tonumber(id) + 1] or str
end end
-- tries to get the ingame name of an item based on its ID -- tries to get the ingame name of an item based on its ID
function EID:getObjectName(objID, objType) function EID:getObjectName(Type, Variant, SubType)
local tableEntry = EID.descriptions[EIDConfig["Language"]][objType][objID] or EID.descriptions["en_us"][objType][objID] local tableEntry = EID:getDescriptionData(Type, Variant, SubType)
if objType == "collectibles" then local tableName = EID:getTableName(Type, Variant)
if EIDConfig["Language"] ~= "en_us" and #tableEntry == 3 then local name = nil
if tableEntry[2] ~= nil and tableEntry[2] ~= "" then if tableEntry[2] ~= nil and tableEntry[2] ~= "" then
return tableEntry[2] name = tableEntry[2]
end end
end if tableName == "collectibles" then
return EID.itemConfig:GetCollectible(objID).Name return name or EID.itemConfig:GetCollectible(SubType).Name
elseif objType == "trinkets" then elseif tableName == "trinkets" then
if EIDConfig["Language"] ~= "en_us" and #tableEntry == 3 then return name or EID.itemConfig:GetTrinket(SubType).Name
if tableEntry[2] ~= nil and tableEntry[2] ~= "" then elseif tableName == "cards" then
return tableEntry[2] return name or EID.itemConfig:GetCard(SubType).Name
end elseif tableName == "pills" then
end name = name or EID.itemConfig:GetPillEffect(SubType-1).Name
return EID.itemConfig:GetTrinket(objID).Name return string.gsub(name,"I'm Excited!!!","I'm Excited!!") -- prevent markup trigger
elseif objType == "cards" then elseif tableName == "sacrifice" then
if EIDConfig["Language"] ~= "en_us" and #tableEntry == 3 then
if tableEntry[2] ~= nil and tableEntry[2] ~= "" then
return tableEntry[2]
end
end
return EID.itemConfig:GetCard(objID).Name
elseif objType == "pills" then
if EIDConfig["Language"] ~= "en_us" and #tableEntry == 3 then
if tableEntry[2] ~= nil and tableEntry[2] ~= "" then
return tableEntry[2]
end
end
return EID.itemConfig:GetPillEffect(objID).Name
elseif objType == "transformations" then
return tableEntry
elseif objType == "sacrifice" then
return EID:getDescriptionTable("sacrificeHeader") return EID:getDescriptionTable("sacrificeHeader")
elseif objType == "dice" then elseif tableName == "dice" then
return EID:getDescriptionTable("diceHeader") return EID:getDescriptionTable("diceHeader")
elseif objType == "custom" then elseif tableName == "custom" then
return __eidEntityDescriptions[objID][1] or tableEntry[1] or objID return name or SubType
end end
return "" return ""
end end
@@ -359,7 +371,7 @@ function EID:getIcon(str)
end end
end end
-- Tries to read special markup used to generate icons for all Collectibles/Trinkets and the default cards -- Tries to read special markup used to generate icons for all Collectibles/Trinkets and the default Cards/Pills
-- Returns an inlineIcon Object or nil if no parsing was possible -- Returns an inlineIcon Object or nil if no parsing was possible
function EID:createItemIconObject(str) function EID:createItemIconObject(str)
local collID,numReplace = string.gsub(str, "Collectible", "") local collID,numReplace = string.gsub(str, "Collectible", "")
@@ -374,7 +386,7 @@ function EID:createItemIconObject(str)
local cardID,numReplace3 = string.gsub(str, "Card", "") local cardID,numReplace3 = string.gsub(str, "Card", "")
if numReplace3 > 0 and cardID ~= "" and tonumber(cardID) ~= nil then if numReplace3 > 0 and cardID ~= "" and tonumber(cardID) ~= nil then
if tonumber(cardID)>54 then return EID.InlineIcons[str] or EID.InlineIcons["Blank"] end if tonumber(cardID)>54 then return EID.InlineIcons[str] or EID.InlineIcons["Blank"] end
return {"Cards",tonumber(cardID)-1,8,8,0,0,EID.CardPillSprite} return {"Cards",tonumber(cardID)-1,8,8,0,1,EID.CardPillSprite}
end end
local pillID,numReplace4 = string.gsub(str, "Pill", "") local pillID,numReplace4 = string.gsub(str, "Pill", "")
if numReplace4 > 0 and pillID ~= "" and tonumber(pillID) ~= nil then if numReplace4 > 0 and pillID ~= "" and tonumber(pillID) ~= nil then
+1
View File
@@ -45,6 +45,7 @@ __eidItemDescriptions[3] =
------ Overriding descriptions------ ------ Overriding descriptions------
EID:addCollectible(2, "New override Method") -- minimal method EID:addCollectible(2, "New override Method") -- minimal method
EID:addCollectible(2, "New override Method", "new Name", "ru") -- maximal method EID:addCollectible(2, "New override Method", "new Name", "ru") -- maximal method
EID:addTrinket(2, "New override Method") -- minimal method
EID:addCard(2, "New override Method", "new Name") -- card EID:addCard(2, "New override Method", "new Name") -- card
EID:addPill(2, "New override Method", "new Name") -- pill EID:addPill(2, "New override Method", "new Name") -- pill
EID:addEntity(5, 10, 2, "Custom Name", "Custom description") -- Entity EID:addEntity(5, 10, 2, "Custom Name", "Custom description") -- Entity
+24 -26
View File
@@ -105,6 +105,7 @@ function EID:printDescription(desc)
local offsetX = 0 local offsetX = 0
if EIDConfig["ShowItemIcon"] then if EIDConfig["ShowItemIcon"] then
local iconType = nil local iconType = nil
local renderID = desc.ID
if desc.ItemType == 5 and desc.ItemVariant == 100 then if desc.ItemType == 5 and desc.ItemVariant == 100 then
iconType = "Collectible" iconType = "Collectible"
elseif desc.ItemType == 5 and desc.ItemVariant == 350 then elseif desc.ItemType == 5 and desc.ItemVariant == 350 then
@@ -113,12 +114,13 @@ function EID:printDescription(desc)
iconType = "Card" iconType = "Card"
elseif desc.ItemType == 5 and desc.ItemVariant == 70 then elseif desc.ItemType == 5 and desc.ItemVariant == 70 then
iconType = "Pill" iconType = "Pill"
renderID = desc.RealID
end end
if iconType ~= nil then if iconType ~= nil then
offsetX = offsetX + 12 offsetX = offsetX + 12
EID:renderString( EID:renderString(
"{{" .. iconType .. desc.ID .. "}}", "{{" .. iconType .. renderID .. "}}",
Vector(EIDConfig["XPosition"], padding - 5), Vector(EIDConfig["XPosition"]-3, padding - 5),
Vector(EIDConfig["Scale"], EIDConfig["Scale"]), Vector(EIDConfig["Scale"], EIDConfig["Scale"]),
EID:getNameColor() EID:getNameColor()
) )
@@ -280,7 +282,7 @@ local function onRender(t)
if MCMLoaded then if MCMLoaded then
if MCM.IsVisible and EID.permanentDisplayTextObj == nil and EID.MCMCompat_isDisplayingEIDTab then if MCM.IsVisible and EID.permanentDisplayTextObj == nil and EID.MCMCompat_isDisplayingEIDTab then
MCMCompat_oldPermanentObj = EID.permanentDisplayTextObj MCMCompat_oldPermanentObj = EID.permanentDisplayTextObj
local demoDescObj = EID:getDescriptionObj("collectibles", 5, 100, 33) local demoDescObj = EID:getDescriptionObj(5, 100, 33)
demoDescObj.Name = "Demo Object Name" demoDescObj.Name = "Demo Object Name"
demoDescObj.Transformation = "Demo Transformation" demoDescObj.Transformation = "Demo Transformation"
demoDescObj.Description = "A very cool description as a demonstration of the power of EID!#\1 This is also a cool line#This line loves you {{Heart}}" demoDescObj.Description = "A very cool description as a demonstration of the power of EID!#\1 This is also a cool line#This line loves you {{Heart}}"
@@ -299,7 +301,6 @@ local function onRender(t)
end end
if EID.isDisplayingPermanent and EID.permanentDisplayTextObj ~= nil then if EID.isDisplayingPermanent and EID.permanentDisplayTextObj ~= nil then
print("Display")
EID:printDescription(EID.permanentDisplayTextObj) EID:printDescription(EID.permanentDisplayTextObj)
EID.isDisplayingText = true EID.isDisplayingText = true
return return
@@ -321,12 +322,12 @@ local function onRender(t)
if dist / 40 > tonumber(EIDConfig["MaxDistance"]) or not closest.Type == EntityType.ENTITY_PICKUP then if dist / 40 > tonumber(EIDConfig["MaxDistance"]) or not closest.Type == EntityType.ENTITY_PICKUP then
if Game():GetRoom():GetType() == RoomType.ROOM_SACRIFICE and EIDConfig["DisplaySacrificeInfo"] then if Game():GetRoom():GetType() == RoomType.ROOM_SACRIFICE and EIDConfig["DisplaySacrificeInfo"] then
EID:printDescription(EID:getDescriptionObj("sacrifice", EID.sacrificeCounter)) EID:printDescription(EID:getDescriptionObj(-999, -1, EID.sacrificeCounter))
end end
if if
Game():GetRoom():GetType() == RoomType.ROOM_DICE and EIDConfig["DisplayDiceInfo"] and type(closestDice) ~= type(nil) Game():GetRoom():GetType() == RoomType.ROOM_DICE and EIDConfig["DisplayDiceInfo"] and type(closestDice) ~= type(nil)
then then
EID:printDescription(EID:getDescriptionObj("dice", closestDice.SubType + 1)) EID:printDescription(EID:getDescriptionObj(-999, -2, closestDice.SubType + 1))
EID:renderIndicator(closestDice) EID:renderIndicator(closestDice)
end end
return return
@@ -347,36 +348,25 @@ local function onRender(t)
return return
end end
]] ]]
--Handle Entities (omni)
local objIDString = closest.Type .. "." .. closest.Variant .. "." .. closest.SubType
local tableEntry =
EID.descriptions[EIDConfig["Language"]]["custom"][objIDString] or EID.descriptions["en_us"]["custom"][objIDString] or
EID:getLegacyModDescription("custom", objIDString) or
nil
if EIDConfig["EnableEntityDescriptions"] and tableEntry ~= nil then
EID:printDescription(EID:getDescriptionObj("custom", closest.Type, closest.Variant, closest.SubType))
return
end
--Handle Trinkets
if closest.Variant == PickupVariant.PICKUP_TRINKET then if closest.Variant == PickupVariant.PICKUP_TRINKET then
--Handle Collectibles --Handle Trinkets
EID:printDescription(EID:getDescriptionObj("trinkets", closest.Type, closest.Variant, closest.SubType)) EID:printDescription(EID:getDescriptionObj(closest.Type, closest.Variant, closest.SubType))
elseif closest.Variant == PickupVariant.PICKUP_COLLECTIBLE then elseif closest.Variant == PickupVariant.PICKUP_COLLECTIBLE then
--Handle Cards & Runes --Handle Collectibles
if EID:hasCurseBlind() and EIDConfig["DisableOnCurse"] then if EID:hasCurseBlind() and EIDConfig["DisableOnCurse"] then
EID:renderQuestionMark() EID:renderQuestionMark()
return return
end end
EID:printDescription(EID:getDescriptionObj("collectibles", closest.Type, closest.Variant, closest.SubType)) EID:printDescription(EID:getDescriptionObj(closest.Type, closest.Variant, closest.SubType))
elseif closest.Variant == PickupVariant.PICKUP_TAROTCARD then elseif closest.Variant == PickupVariant.PICKUP_TAROTCARD then
--Handle Pills --Handle Cards & Runes
if closest:ToPickup():IsShopItem() and not EIDConfig["DisplayCardInfoShop"] then if closest:ToPickup():IsShopItem() and not EIDConfig["DisplayCardInfoShop"] then
EID:renderQuestionMark() EID:renderQuestionMark()
return return
end end
EID:printDescription(EID:getDescriptionObj("cards", closest.Type, closest.Variant, closest.SubType)) EID:printDescription(EID:getDescriptionObj(closest.Type, closest.Variant, closest.SubType))
elseif closest.Variant == PickupVariant.PICKUP_PILL then elseif closest.Variant == PickupVariant.PICKUP_PILL then
--Handle Pills
if closest:ToPickup():IsShopItem() and not EIDConfig["DisplayPillInfoShop"] then if closest:ToPickup():IsShopItem() and not EIDConfig["DisplayPillInfoShop"] then
EID:renderQuestionMark() EID:renderQuestionMark()
return return
@@ -384,10 +374,11 @@ local function onRender(t)
local pillColor = closest.SubType local pillColor = closest.SubType
local pool = Game():GetItemPool() local pool = Game():GetItemPool()
local pillEffect = pool:GetPillEffect(pillColor)
local identified = pool:IsPillIdentified(pillColor) local identified = pool:IsPillIdentified(pillColor)
if (identified or EIDConfig["ShowUnidentifiedPillDescriptions"]) then if (identified or EIDConfig["ShowUnidentifiedPillDescriptions"]) then
EID:printDescription(EID:getDescriptionObj("pills", closest.Type, closest.Variant, pillEffect + 1)) local descEntry = EID:getDescriptionObj(closest.Type, closest.Variant, pillColor)
descEntry["realSubType"] = pillColor
EID:printDescription(descEntry)
else else
EID:renderString( EID:renderString(
"{{Pill"..pillColor.."}} "..EID:getDescriptionTable("unidentifiedPill"), "{{Pill"..pillColor.."}} "..EID:getDescriptionTable("unidentifiedPill"),
@@ -396,6 +387,13 @@ local function onRender(t)
EID:getErrorColor() EID:getErrorColor()
) )
end end
elseif EIDConfig["EnableEntityDescriptions"] then
--Handle Entities (omni)
local descriptionEntry = EID:getDescriptionObj(closest.Type, closest.Variant, closest.SubType)
if descriptionEntry~=nil then
EID:printDescription(descriptionEntry)
return
end
end end
if player:HasCollectible(CollectibleType.COLLECTIBLE_SCHOOLBAG) then if player:HasCollectible(CollectibleType.COLLECTIBLE_SCHOOLBAG) then
modifiedPosY = EIDConfig["YPosition"] + 30 modifiedPosY = EIDConfig["YPosition"] + 30