Formatted api and main file
This commit is contained in:
1 parent
2a6d330e2c
commit
bfa6addf65
3 files changed
+156
-102
No files matched your search
+119
-55
@@ -68,18 +68,66 @@ EID.TRANSFORMATION = {
|
||||
|
||||
-- List of item Types
|
||||
EID.ItemTypeAnm2Names = {
|
||||
"null", -- 1
|
||||
"passive", -- 2
|
||||
"active", -- 3
|
||||
"familiar", -- 4
|
||||
"trinket" -- 5
|
||||
"null", -- 1
|
||||
"passive", -- 2
|
||||
"active", -- 3
|
||||
"familiar", -- 4
|
||||
"trinket" -- 5
|
||||
}
|
||||
---------------------------------------------------------------------------
|
||||
-------------------------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
|
||||
function EID:isDisplayingText()
|
||||
return isDisplayingText
|
||||
return EID.isDisplayingText
|
||||
end
|
||||
|
||||
-- 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
|
||||
function EID:getLastDescribedEntity()
|
||||
return lastDescriptionEntity
|
||||
return EID.lastDescriptionEntity
|
||||
end
|
||||
|
||||
-- returns descriptions from the legacy mod descriptions if they exist
|
||||
@@ -114,8 +162,8 @@ function EID:getLegacyModDescription(objTable, id)
|
||||
end
|
||||
end
|
||||
|
||||
-- returns the specified object table in the current language.
|
||||
-- falls back to english if it doesnt exist
|
||||
-- returns the specified object table in the current language.
|
||||
-- falls back to english if it doesnt exist
|
||||
function EID:getDescriptionTable(objTable)
|
||||
return EID.descriptions[EIDConfig["Language"]][objTable] or EID.descriptions["en_us"][objTable]
|
||||
end
|
||||
@@ -123,22 +171,23 @@ end
|
||||
-- returns the description object of the specified object table translated with the current language
|
||||
-- falls back to english if the objID isnt available
|
||||
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 = {}
|
||||
description.ID = objID
|
||||
|
||||
|
||||
description.Name = EID:getObjectName(objID, objTable) or objTable
|
||||
|
||||
|
||||
local legacyModdedDescription = EID:getLegacyModDescription(objTable, objID)
|
||||
description.Description = legacyModdedDescription or tableEntry[4] or "MISSING DESCRIPTION"
|
||||
|
||||
|
||||
local legacyModdedTransformation = nil
|
||||
if objTable == "collectibles" then
|
||||
legacyModdedTransformation = EID:getLegacyModDescription("transformations", objID)
|
||||
end
|
||||
description.Transformation = legacyModdedTransformation or tableEntry[2] or "0"
|
||||
|
||||
|
||||
return description
|
||||
end
|
||||
|
||||
@@ -155,28 +204,28 @@ end
|
||||
function EID:getObjectName(objID, objType)
|
||||
local tableEntry = EID.descriptions[EIDConfig["Language"]][objType][objID] or EID.descriptions["en_us"][objType][objID]
|
||||
if objType == "collectibles" then
|
||||
if EIDConfig["Language"]~="en_us" and #tableEntry==4 then
|
||||
if EIDConfig["Language"] ~= "en_us" and #tableEntry == 4 then
|
||||
if tableEntry[3] ~= nil and tableEntry[3] ~= "" then
|
||||
return tableEntry[3]
|
||||
end
|
||||
end
|
||||
return EID.itemConfig:GetCollectible(objID).Name
|
||||
elseif objType == "trinkets" then
|
||||
if EIDConfig["Language"]~="en_us" and #tableEntry==3 then
|
||||
if EIDConfig["Language"] ~= "en_us" and #tableEntry == 3 then
|
||||
if tableEntry[3] ~= nil and tableEntry[3] ~= "" then
|
||||
return tableEntry[3]
|
||||
end
|
||||
end
|
||||
return EID.itemConfig:GetTrinket(objID).Name
|
||||
elseif objType == "cards" then
|
||||
if EIDConfig["Language"]~="en_us" and #tableEntry==3 then
|
||||
if EIDConfig["Language"] ~= "en_us" and #tableEntry == 3 then
|
||||
if tableEntry[3] ~= nil and tableEntry[3] ~= "" then
|
||||
return tableEntry[3]
|
||||
end
|
||||
end
|
||||
return EID.itemConfig:GetCard(objID).Name
|
||||
elseif objType == "pills" then
|
||||
if EIDConfig["Language"]~="en_us" and #tableEntry==3 then
|
||||
if EIDConfig["Language"] ~= "en_us" and #tableEntry == 3 then
|
||||
if tableEntry[3] ~= nil and tableEntry[3] ~= "" then
|
||||
return tableEntry[3]
|
||||
end
|
||||
@@ -198,7 +247,7 @@ function EID:hasDescription(entity)
|
||||
local isAllowed = false
|
||||
if EIDConfig["EnableEntityDescriptions"] then
|
||||
isAllowed = __eidEntityDescriptions[entity.Type .. "." .. entity.Variant .. "." .. entity.SubType] ~= nil
|
||||
--isAllowed = isAllowed or type(entity:GetData()["EID_Description"]) ~= type(nil)
|
||||
--isAllowed = isAllowed or type(entity:GetData()["EID_Description"]) ~= type(nil)
|
||||
end
|
||||
isAllowed = isAllowed or (entity.Variant == PickupVariant.PICKUP_COLLECTIBLE and EIDConfig["DisplayItemInfo"])
|
||||
isAllowed = isAllowed or (entity.Variant == PickupVariant.PICKUP_TRINKET and EIDConfig["DisplayTrinketInfo"])
|
||||
@@ -209,7 +258,7 @@ end
|
||||
|
||||
-- Replaces shorthand-representations of a character with the internal reference
|
||||
function EID:replaceShortMarkupStrings(text)
|
||||
for _,pair in ipairs(EID.TextReplacementPairs) do
|
||||
for _, pair in ipairs(EID.TextReplacementPairs) do
|
||||
text = string.gsub(text, pair[1], pair[2])
|
||||
end
|
||||
return text
|
||||
@@ -228,8 +277,17 @@ end
|
||||
-- Returns the inlineIcon object of a given Iconstring
|
||||
-- can be used to validate an iconstring
|
||||
function EID:getIcon(str)
|
||||
if str == nil then return EID.InlineIcons["ERROR"] end
|
||||
local strTrimmed = string.gsub(str, "{{(.-)}}", function(a) return a end)
|
||||
if str == nil then
|
||||
return EID.InlineIcons["ERROR"]
|
||||
end
|
||||
local strTrimmed =
|
||||
string.gsub(
|
||||
str,
|
||||
"{{(.-)}}",
|
||||
function(a)
|
||||
return a
|
||||
end
|
||||
)
|
||||
if #strTrimmed <= #str then
|
||||
return EID.InlineIcons[strTrimmed] or EID.InlineIcons["ERROR"]
|
||||
else
|
||||
@@ -239,14 +297,16 @@ end
|
||||
|
||||
-- Returns the icon for a given transformation name or ID
|
||||
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
|
||||
str = EID.descriptions["en_us"].transformations[tonumber(str+1)]
|
||||
str = EID.descriptions["en_us"].transformations[tonumber(str + 1)]
|
||||
end
|
||||
local transformSprite = EID:getIcon(str:gsub(" ", ""))
|
||||
if transformSprite[1] == "ERROR" then
|
||||
transformSprite = EID:getIcon("CustomTransformation")
|
||||
end
|
||||
end
|
||||
return transformSprite
|
||||
end
|
||||
|
||||
@@ -263,7 +323,7 @@ function EID:filterIconMarkup(text, textPosX, textPosY)
|
||||
local textposition = string.find(text, word)
|
||||
local lookup = EID:getIcon(word)
|
||||
local preceedingTextWidth = EID:getStrWidth(string.sub(text, 0, textposition - 1)) * EIDConfig["Scale"]
|
||||
table.insert(spriteTable,{lookup, preceedingTextWidth})
|
||||
table.insert(spriteTable, {lookup, preceedingTextWidth})
|
||||
text = string.gsub(text, word, EID:generatePlaceholderString(lookup[3]), 1)
|
||||
end
|
||||
return text, spriteTable
|
||||
@@ -272,25 +332,21 @@ end
|
||||
--renders a list of given inline sprite objects returned by the "EID:filterIconMarkup()" function
|
||||
-- Table entry format: {EID.InlineIcons Object, Width of text preceeding the icon}
|
||||
function EID:renderInlineIcons(spriteTable, posX, posY)
|
||||
for _,sprite in ipairs(spriteTable) do
|
||||
for _, sprite in ipairs(spriteTable) do
|
||||
local Xoffset = sprite[1][5] or -1
|
||||
local Yoffset = sprite[1][6] or 0
|
||||
local spriteObj = sprite[1][7] or EID.InlineIconSprite
|
||||
spriteObj:SetFrame(sprite[1][1], sprite[1][2])
|
||||
spriteObj.Scale = Vector(EIDConfig["Scale"], EIDConfig["Scale"])
|
||||
spriteObj.Color = Color(1,1,1,EIDConfig["Transparency"],0,0,0)
|
||||
spriteObj:Render(
|
||||
Vector((posX + sprite[2] + Xoffset), posY + Yoffset),
|
||||
Vector(0, 0),
|
||||
Vector(0, 0)
|
||||
)
|
||||
spriteObj.Color = Color(1, 1, 1, EIDConfig["Transparency"], 0, 0, 0)
|
||||
spriteObj:Render(Vector((posX + sprite[2] + Xoffset), posY + Yoffset), Vector(0, 0), Vector(0, 0))
|
||||
end
|
||||
end
|
||||
|
||||
-- Returns the icon used for the bulletpoint. It will look at the first word in the given string.
|
||||
function EID:handleBulletpointIcon(text)
|
||||
local firstWord = string.match(text, "([^%s]+)")
|
||||
if EID:getIcon(firstWord) ~= EID.InlineIcons["ERROR"] then
|
||||
if EID:getIcon(firstWord) ~= EID.InlineIcons["ERROR"] then
|
||||
return firstWord
|
||||
end
|
||||
return "\007"
|
||||
@@ -301,10 +357,17 @@ end
|
||||
function EID:getColor(str, baseKColor)
|
||||
local color = baseKColor
|
||||
local isColorMarkup = false
|
||||
if str ~= nil then
|
||||
local strTrimmed = string.gsub(str, "{{(.-)}}", function(a) return a end)
|
||||
if str ~= nil then
|
||||
local strTrimmed =
|
||||
string.gsub(
|
||||
str,
|
||||
"{{(.-)}}",
|
||||
function(a)
|
||||
return a
|
||||
end
|
||||
)
|
||||
if #strTrimmed <= #str then
|
||||
if type(EID.InlineColors[strTrimmed]) =="function" then
|
||||
if type(EID.InlineColors[strTrimmed]) == "function" then
|
||||
color = EID.InlineColors[strTrimmed](color)
|
||||
else
|
||||
color = EID.InlineColors[strTrimmed] or color
|
||||
@@ -328,15 +391,15 @@ function EID:filterColorMarkup(text, baseKColor)
|
||||
local lookup, isColor = EID:getColor(word, lastColor)
|
||||
if isColor then
|
||||
local preceedingText = string.sub(text, lastPosition, textposition - 1)
|
||||
local preceedingTextWidth = EID:getStrWidth(preceedingText)*EIDConfig["Scale"]
|
||||
local preceedingTextWidth = EID:getStrWidth(preceedingText) * EIDConfig["Scale"]
|
||||
lastPosition = textposition
|
||||
table.insert(textPartsTable,{preceedingText, lastColor, preceedingTextWidth})
|
||||
table.insert(textPartsTable, {preceedingText, lastColor, preceedingTextWidth})
|
||||
lastColor = lookup
|
||||
text = string.gsub(text, word, "", 1)
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(textPartsTable,{string.sub(text, lastPosition), lastColor, 0})
|
||||
|
||||
table.insert(textPartsTable, {string.sub(text, lastPosition), lastColor, 0})
|
||||
return textPartsTable
|
||||
end
|
||||
|
||||
@@ -349,12 +412,12 @@ function EID:fitTextToWidth(str, textboxWidth)
|
||||
for word in string.gmatch(str, "([^%s]+)") do
|
||||
local colorFiltered = EID:filterColorMarkup(word, EID:getTextColor())
|
||||
local filteredWord = ""
|
||||
for _,filtered in ipairs(colorFiltered) do
|
||||
filteredWord = filteredWord..filtered[1]
|
||||
for _, filtered in ipairs(colorFiltered) do
|
||||
filteredWord = filteredWord .. filtered[1]
|
||||
end
|
||||
local strFiltered, spriteTable = EID:filterIconMarkup(filteredWord, 0, 0)
|
||||
local wordLength = EID:getStrWidth(strFiltered)
|
||||
|
||||
|
||||
if curLength + wordLength <= textboxWidth or curLength < 12 then
|
||||
text = text .. word .. " "
|
||||
curLength = curLength + wordLength
|
||||
@@ -382,17 +445,18 @@ function EID:renderString(str, position, scale, kcolor)
|
||||
EID:renderInlineIcons(spriteTable, position.X, position.Y)
|
||||
EID.font:DrawStringScaledUTF8(strFiltered, position.X + offsetX, position.Y, scale.X, scale.Y, textPart[2], 0, false)
|
||||
offsetX = offsetX + textPart[3]
|
||||
end
|
||||
end
|
||||
return textPartsTable[#textPartsTable][2]
|
||||
end
|
||||
|
||||
-- Interpolates between 2 KColors with a given fraction.
|
||||
-- Interpolates between 2 KColors with a given fraction.
|
||||
function EID:interpolateColors(kColor1, kColor2, fraction)
|
||||
local t = KColor(
|
||||
(kColor2.Red-kColor1.Red)*fraction+kColor1.Red,
|
||||
(kColor2.Green-kColor1.Green)*fraction+kColor1.Green,
|
||||
(kColor2.Blue-kColor1.Blue)*fraction+kColor1.Blue,
|
||||
(kColor2.Alpha-kColor1.Alpha)*fraction+kColor1.Alpha,
|
||||
local t =
|
||||
KColor(
|
||||
(kColor2.Red - kColor1.Red) * fraction + kColor1.Red,
|
||||
(kColor2.Green - kColor1.Green) * fraction + kColor1.Green,
|
||||
(kColor2.Blue - kColor1.Blue) * fraction + kColor1.Blue,
|
||||
(kColor2.Alpha - kColor1.Alpha) * fraction + kColor1.Alpha,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
@@ -402,11 +466,11 @@ end
|
||||
|
||||
-- Creates a copy of a KColor object. This prevents overwriting existing
|
||||
function EID:copyKColor(colorObj)
|
||||
return KColor(colorObj.Red,colorObj.Green,colorObj.Blue,colorObj.Alpha,0,0,0)
|
||||
return KColor(colorObj.Red, colorObj.Green, colorObj.Blue, colorObj.Alpha, 0, 0, 0)
|
||||
end
|
||||
|
||||
-- Compares two KColors. Returns true if they are equal
|
||||
function EID:areColorsEqual(c1,c2)
|
||||
function EID:areColorsEqual(c1, c2)
|
||||
return c1.Red == c2.Red and c1.Green == c2.Green and c1.Blue == c2.Blue and c1.Alpha == c2.Alpha
|
||||
end
|
||||
|
||||
@@ -460,4 +524,4 @@ function EID:getErrorColor()
|
||||
0,
|
||||
0
|
||||
)
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user