Formatted api and main file

This commit is contained in:
Wofsauge committed 2020-11-01 19:32:35 +01:00
1 parent 2a6d330e2c
commit bfa6addf65
3 files changed
+107 -53

No files matched your search

+77 -13
View File
@@ -77,9 +77,57 @@ EID.ItemTypeAnm2Names = {
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
-------------------------Handle API Functions ----------------------------- -------------------------Handle API Functions -----------------------------
-- Adds a description for a collectible. Optional parameters: itemName, language, transformations
function EID:addCollectible(id, description, itemName, language, transformations)
itemName = itemName or nil
language = language or "en_us"
transformations = transformations or "0"
EID.descriptions[language].custom["collectible_" .. id] = {id, transformations, itemName, description}
end
-- Adds a description for a trinket. Optional parameters: itemName, language, transformations
function EID:addTrinket(id, description, itemName, language, transformations)
itemName = itemName or nil
language = language or "en_us"
transformations = transformations or "0"
EID.descriptions[language].custom["trinket_" .. id] = {id, transformations, itemName, description}
end
-- Adds a description for a card/rune. Optional parameters: itemName, language, transformations
function EID:addCard(id, description, itemName, language, transformations)
itemName = itemName or nil
language = language or "en_us"
transformations = transformations or "0"
EID.descriptions[language].custom["card_" .. id] = {id, transformations, itemName, description}
end
-- Adds a description for a pilleffect id. Optional parameters: itemName, language, transformations
function EID:addPill(id, description, itemName, language, transformations)
itemName = itemName or nil
language = language or "en_us"
transformations = transformations or "0"
EID.descriptions[language].custom["pill_" .. id] = {id, transformations, itemName, description}
end
-- Adds a description for a pilleffect id. Optional parameters: language, transformations
-- when subtype is -1 or empty, it will affect all subtypes of that entity
function EID:addEntity(id, variant, subtype, entityName, description, language, transformations)
subtype = subtype or nil
language = language or "en_us"
transformations = transformations or "0"
EID.descriptions[language].custom[id .. "." .. variant .. "." .. subtype] = {
id,
variant,
subtype,
entityName,
description,
transformations
}
end
-- Returns if EID is displaying text right now -- Returns if EID is displaying text right now
function EID:isDisplayingText() function EID:isDisplayingText()
return isDisplayingText return EID.isDisplayingText
end end
-- Returns true, if curse of blind is active -- Returns true, if curse of blind is active
@@ -94,7 +142,7 @@ end
-- returns the entity that is currently described. returns last described entity if currently not displaying text -- returns the entity that is currently described. returns last described entity if currently not displaying text
function EID:getLastDescribedEntity() function EID:getLastDescribedEntity()
return lastDescriptionEntity return EID.lastDescriptionEntity
end end
-- returns descriptions from the legacy mod descriptions if they exist -- returns descriptions from the legacy mod descriptions if they exist
@@ -123,7 +171,8 @@ end
-- returns the description object of the specified object table translated with the current language -- returns the description object of the specified object table translated with the current language
-- falls back to english if the objID isnt available -- falls back to english if the objID isnt available
function EID:getDescriptionObj(objTable, objID) function EID:getDescriptionObj(objTable, objID)
local tableEntry = EID.descriptions[EIDConfig["Language"]][objTable][objID] or EID.descriptions["en_us"][objTable][objID] or {} local tableEntry =
EID.descriptions[EIDConfig["Language"]][objTable][objID] or EID.descriptions["en_us"][objTable][objID] or {}
local description = {} local description = {}
description.ID = objID description.ID = objID
@@ -228,8 +277,17 @@ end
-- Returns the inlineIcon object of a given Iconstring -- Returns the inlineIcon object of a given Iconstring
-- can be used to validate an iconstring -- can be used to validate an iconstring
function EID:getIcon(str) function EID:getIcon(str)
if str == nil then return EID.InlineIcons["ERROR"] end if str == nil then
local strTrimmed = string.gsub(str, "{{(.-)}}", function(a) return a end) return EID.InlineIcons["ERROR"]
end
local strTrimmed =
string.gsub(
str,
"{{(.-)}}",
function(a)
return a
end
)
if #strTrimmed <= #str then if #strTrimmed <= #str then
return EID.InlineIcons[strTrimmed] or EID.InlineIcons["ERROR"] return EID.InlineIcons[strTrimmed] or EID.InlineIcons["ERROR"]
else else
@@ -239,7 +297,9 @@ end
-- Returns the icon for a given transformation name or ID -- Returns the icon for a given transformation name or ID
function EID:getTransformationIcon(str) function EID:getTransformationIcon(str)
if str == nil then return EID.InlineIcons["ERROR"] end if str == nil then
return EID.InlineIcons["ERROR"]
end
if tonumber(str) ~= nil then if tonumber(str) ~= nil then
str = EID.descriptions["en_us"].transformations[tonumber(str + 1)] str = EID.descriptions["en_us"].transformations[tonumber(str + 1)]
end end
@@ -279,11 +339,7 @@ function EID:renderInlineIcons(spriteTable, posX, posY)
spriteObj:SetFrame(sprite[1][1], sprite[1][2]) spriteObj:SetFrame(sprite[1][1], sprite[1][2])
spriteObj.Scale = Vector(EIDConfig["Scale"], EIDConfig["Scale"]) spriteObj.Scale = Vector(EIDConfig["Scale"], EIDConfig["Scale"])
spriteObj.Color = Color(1, 1, 1, EIDConfig["Transparency"], 0, 0, 0) spriteObj.Color = Color(1, 1, 1, EIDConfig["Transparency"], 0, 0, 0)
spriteObj:Render( spriteObj:Render(Vector((posX + sprite[2] + Xoffset), posY + Yoffset), Vector(0, 0), Vector(0, 0))
Vector((posX + sprite[2] + Xoffset), posY + Yoffset),
Vector(0, 0),
Vector(0, 0)
)
end end
end end
@@ -302,7 +358,14 @@ function EID:getColor(str, baseKColor)
local color = baseKColor local color = baseKColor
local isColorMarkup = false local isColorMarkup = false
if str ~= nil then if str ~= nil then
local strTrimmed = string.gsub(str, "{{(.-)}}", function(a) return a end) local strTrimmed =
string.gsub(
str,
"{{(.-)}}",
function(a)
return a
end
)
if #strTrimmed <= #str then if #strTrimmed <= #str then
if type(EID.InlineColors[strTrimmed]) == "function" then if type(EID.InlineColors[strTrimmed]) == "function" then
color = EID.InlineColors[strTrimmed](color) color = EID.InlineColors[strTrimmed](color)
@@ -388,7 +451,8 @@ end
-- Interpolates between 2 KColors with a given fraction. -- Interpolates between 2 KColors with a given fraction.
function EID:interpolateColors(kColor1, kColor2, fraction) function EID:interpolateColors(kColor1, kColor2, fraction)
local t = KColor( local t =
KColor(
(kColor2.Red - kColor1.Red) * fraction + kColor1.Red, (kColor2.Red - kColor1.Red) * fraction + kColor1.Red,
(kColor2.Green - kColor1.Green) * fraction + kColor1.Green, (kColor2.Green - kColor1.Green) * fraction + kColor1.Green,
(kColor2.Blue - kColor1.Blue) * fraction + kColor1.Blue, (kColor2.Blue - kColor1.Blue) * fraction + kColor1.Blue,
+1 -1
View File
@@ -1,4 +1,4 @@
local showDebugChars = false local showDebugChars = true
local charsToDebug = { local charsToDebug = {
"!!! EID DEBUG MODE ACTIVATED !!!", -- Header "!!! EID DEBUG MODE ACTIVATED !!!", -- Header
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 1234567890", -- Basic chars "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 1234567890", -- Basic chars
+29 -39
View File
@@ -2,9 +2,9 @@ EID = RegisterMod("External Item Descriptions", 1)
EID.itemConfig = Isaac.GetItemConfig() EID.itemConfig = Isaac.GetItemConfig()
EID.descriptions = {} -- Table that holds all translation strings EID.descriptions = {} -- Table that holds all translation strings
EID.isDisplayingText = false
EID.lastDescriptionEntity = nil
local lineHeight = 11 local lineHeight = 11
local isDisplayingText = false
local lastDescriptionEntity = nil
local hideDescToggle = false local hideDescToggle = false
EID.sacrificeCounter = 1 EID.sacrificeCounter = 1
@@ -99,19 +99,11 @@ function printDescription(desc)
EID.IconSprite:Play(EID.ItemTypeAnm2Names[itemType]) EID.IconSprite:Play(EID.ItemTypeAnm2Names[itemType])
EID.IconSprite.Scale = Vector(EIDConfig["Scale"], EIDConfig["Scale"]) EID.IconSprite.Scale = Vector(EIDConfig["Scale"], EIDConfig["Scale"])
EID.IconSprite:Update() EID.IconSprite:Update()
EID.IconSprite:Render( EID.IconSprite:Render(Vector(EIDConfig["XPosition"], padding + offsetY), Vector(0, 0), Vector(0, 0))
Vector(EIDConfig["XPosition"], padding + offsetY),
Vector(0, 0),
Vector(0, 0)
)
if itemType == 3 then -- Display Charge if itemType == 3 then -- Display Charge
EID.IconSprite:Play(EID.itemConfig:GetCollectible(desc.ID).MaxCharges) EID.IconSprite:Play(EID.itemConfig:GetCollectible(desc.ID).MaxCharges)
EID.IconSprite:Update() EID.IconSprite:Update()
EID.IconSprite:Render( EID.IconSprite:Render(Vector(EIDConfig["XPosition"], padding + offsetY), Vector(0, 0), Vector(0, 0))
Vector(EIDConfig["XPosition"], padding + offsetY),
Vector(0, 0),
Vector(0, 0)
)
end end
if not EIDConfig["ShowItemName"] then if not EIDConfig["ShowItemName"] then
padding = padding + lineHeight * EIDConfig["Scale"] padding = padding + lineHeight * EIDConfig["Scale"]
@@ -173,10 +165,10 @@ function printDescription(desc)
end end
end end
end end
printBulletPoints(desc.Description, padding) EID:printBulletPoints(desc.Description, padding)
end end
function printBulletPoints(description, padding) function EID:printBulletPoints(description, padding)
local textboxWidth = tonumber(EIDConfig["TextboxWidth"]) * 4 local textboxWidth = tonumber(EIDConfig["TextboxWidth"]) * 4
description = EID:replaceShortMarkupStrings(description) description = EID:replaceShortMarkupStrings(description)
for line in string.gmatch(description, "([^#]+)") do for line in string.gmatch(description, "([^#]+)") do
@@ -191,14 +183,11 @@ function printBulletPoints(description, padding)
lineToPrint = string.gsub(lineToPrint, bpIcon .. " ", "") lineToPrint = string.gsub(lineToPrint, bpIcon .. " ", "")
end end
textColor = EID:renderString(bpIcon, Vector(posX, padding), Vector(EIDConfig["Scale"], EIDConfig["Scale"]), textColor) textColor =
EID:renderString(bpIcon, Vector(posX, padding), Vector(EIDConfig["Scale"], EIDConfig["Scale"]), textColor)
end end
textColor = EID:renderString( textColor =
lineToPrint, EID:renderString(lineToPrint, Vector(posX + 12, padding), Vector(EIDConfig["Scale"], EIDConfig["Scale"]), textColor)
Vector(posX + 12, padding),
Vector(EIDConfig["Scale"], EIDConfig["Scale"]),
textColor
)
padding = padding + lineHeight * EIDConfig["Scale"] padding = padding + lineHeight * EIDConfig["Scale"]
end end
end end
@@ -207,7 +196,7 @@ end
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
---------------------------Handle Rendering-------------------------------- ---------------------------Handle Rendering--------------------------------
function renderQuestionMark() function EID:renderQuestionMark()
IconSprite:Play("CurseOfBlind") IconSprite:Play("CurseOfBlind")
IconSprite.Scale = Vector(EIDConfig["Scale"], EIDConfig["Scale"]) IconSprite.Scale = Vector(EIDConfig["Scale"], EIDConfig["Scale"])
IconSprite:Update() IconSprite:Update()
@@ -221,7 +210,7 @@ function renderQuestionMark()
end end
end end
function renderIndicator(entity) function EID:renderIndicator(entity)
if EIDConfig["Indicator"] == "blink" then if EIDConfig["Indicator"] == "blink" then
local c = 255 - math.floor(255 * ((entity.FrameCount % 40) / 40)) local c = 255 - math.floor(255 * ((entity.FrameCount % 40) / 40))
entity:SetColor(Color(1, 1, 1, 1, c, c, c), 1, 1, false, false) entity:SetColor(Color(1, 1, 1, 1, c, c, c), 1, 1, false, false)
@@ -258,7 +247,7 @@ end
---------------------------On Render Function------------------------------ ---------------------------On Render Function------------------------------
local function onRender(t) local function onRender(t)
isDisplayingText = false EID.isDisplayingText = false
local player = Isaac.GetPlayer(0) local player = Isaac.GetPlayer(0)
local closest = nil local closest = nil
local closestDice = nil local closestDice = nil
@@ -292,7 +281,7 @@ local function onRender(t)
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
printDescription(EID:getDescriptionObj("dice", closestDice.SubType + 1)) printDescription(EID:getDescriptionObj("dice", closestDice.SubType + 1))
renderIndicator(closestDice) EID:renderIndicator(closestDice)
end end
return return
end end
@@ -300,42 +289,44 @@ local function onRender(t)
if closest == nil then if closest == nil then
return return
end end
lastDescriptionEntity = closest EID.lastDescriptionEntity = closest
isDisplayingText = true EID.isDisplayingText = true
--Handle Indicators --Handle Indicators
renderIndicator(closest) EID:renderIndicator(closest)
--
--Handle Entities (specific) --Handle Entities (specific)
--[[ if EIDConfig["EnableEntityDescriptions"] and type(closest:GetData()["EID_Description"]) ~= type(nil) then --[[ if EIDConfig["EnableEntityDescriptions"] and type(closest:GetData()["EID_Description"]) ~= type(nil) then
printTrinketDescription({closest.Type, closest:GetData()["EID_Description"]}, "custom") printTrinketDescription({closest.Type, closest:GetData()["EID_Description"]}, "custom")
return return
end end
]]-- ]] --Handle Entities (omni)
--Handle Entities (omni)
local objIDString = closest.Type .. "." .. closest.Variant .. "." .. closest.SubType local objIDString = closest.Type .. "." .. closest.Variant .. "." .. closest.SubType
local tableEntry = EID.descriptions[EIDConfig["Language"]]["custom"][objIDString] local tableEntry =
or EID.descriptions["en_us"]["custom"][objIDString] or EID:getLegacyModDescription("custom", objIDString) or nil 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 if EIDConfig["EnableEntityDescriptions"] and tableEntry ~= nil then
printDescription(EID:getDescriptionObj("custom", objIDString)) printDescription(EID:getDescriptionObj("custom", objIDString))
return return
end end
--Handle Trinkets --Handle Trinkets
if closest.Variant == PickupVariant.PICKUP_TRINKET then if closest.Variant == PickupVariant.PICKUP_TRINKET then
printDescription(EID:getDescriptionObj("trinkets", closest.SubType))
--Handle Collectibles --Handle Collectibles
printDescription(EID:getDescriptionObj("trinkets", closest.SubType))
elseif closest.Variant == PickupVariant.PICKUP_COLLECTIBLE then elseif closest.Variant == PickupVariant.PICKUP_COLLECTIBLE then
--Handle Cards & Runes
if EID:hasCurseBlind() and EIDConfig["DisableOnCurse"] then if EID:hasCurseBlind() and EIDConfig["DisableOnCurse"] then
renderQuestionMark() EID:renderQuestionMark()
return return
end end
printDescription(EID:getDescriptionObj("collectibles", closest.SubType)) printDescription(EID:getDescriptionObj("collectibles", closest.SubType))
--Handle Cards & Runes
elseif closest.Variant == PickupVariant.PICKUP_TAROTCARD then elseif closest.Variant == PickupVariant.PICKUP_TAROTCARD then
--Handle Pills
if closest:ToPickup():IsShopItem() and not EIDConfig["DisplayCardInfoShop"] then if closest:ToPickup():IsShopItem() and not EIDConfig["DisplayCardInfoShop"] then
renderQuestionMark() EID:renderQuestionMark()
return return
end end
printDescription(EID:getDescriptionObj("cards", closest.SubType)) printDescription(EID:getDescriptionObj("cards", closest.SubType))
@@ -353,10 +344,9 @@ local function onRender(t)
Vector(0, 0) Vector(0, 0)
) )
end end
--Handle Pills
elseif closest.Variant == PickupVariant.PICKUP_PILL then elseif closest.Variant == PickupVariant.PICKUP_PILL then
if closest:ToPickup():IsShopItem() and not EIDConfig["DisplayPillInfoShop"] then if closest:ToPickup():IsShopItem() and not EIDConfig["DisplayPillInfoShop"] then
renderQuestionMark() EID:renderQuestionMark()
return return
end end