From f562d6cd7d188a4984438909d952189fd082d42f Mon Sep 17 00:00:00 2001 From: Wofsauge Date: Thu, 5 Nov 2020 22:57:09 +0100 Subject: [PATCH] Added feature to render Collectible and trinket icons --- eid_api.lua | 33 +++++++++++++++++++++-------- eid_data.lua | 2 ++ eid_debugging.lua | 1 + main.lua | 3 +++ resources/gfx/eid_inline_icons.anm2 | 29 ++++++++++++++++++++++++- 5 files changed, 58 insertions(+), 10 deletions(-) diff --git a/eid_api.lua b/eid_api.lua index 5ccc8a28..9e90fa9f 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -303,21 +303,36 @@ function EID:getIcon(str) if str == nil then return EID.InlineIcons["ERROR"] end - local strTrimmed = - string.gsub( - str, - "{{(.-)}}", - function(a) - return a - end - ) + local strTrimmed = string.gsub(str,"{{(.-)}}",function(a) return a end ) if #strTrimmed <= #str then - return EID.InlineIcons[strTrimmed] or EID.InlineIcons["ERROR"] + return EID:createItemIconObject(strTrimmed) or EID.InlineIcons[strTrimmed] or EID.InlineIcons["ERROR"] else return EID.InlineIcons["ERROR"] end end +-- Tries to read special markup used to generate icons for all Collectibles/Trinkets +-- Returns an inlineIcon Object or nil if no parsing was possible +function EID:createItemIconObject(str) + local collID,numReplace = string.gsub(str, "Collectible", "") + local item = nil + if numReplace>0 then + item = EID.itemConfig:GetCollectible(tonumber(collID)) + end + local trinketID,numReplace2 = string.gsub(str, "Trinket", "") + if numReplace2>0 then + item = EID.itemConfig:GetTrinket(tonumber(trinketID)) + end + if item == nil then + return nil + end + local spriteDummy = Sprite() + spriteDummy:Load("gfx/eid_inline_icons.anm2", true) + spriteDummy:ReplaceSpritesheet(1, item.GfxFileName) + spriteDummy:LoadGraphics() + return {"ItemIcon",0,7,7,-4,-2,spriteDummy} +end + -- Returns the icon for a given transformation name or ID function EID:getTransformationIcon(str) if str == nil then diff --git a/eid_data.lua b/eid_data.lua index 04071b12..be40c709 100644 --- a/eid_data.lua +++ b/eid_data.lua @@ -63,7 +63,9 @@ EID.InlineIcons = { ["Pill"] = {"pickups", 8, 9, 9}, ["Battery"] = {"pickups", 9, 8, 9}, ["Collectible"] = {"Collectible", 0, 7, 7}, + ----- Use Markup "Collectible"+ ITEMID to render collectible sprites (example: {{Collectible1}} = Sad Onion) ["Trinket"] = {"Trinket", 0, 7, 7}, + ----- Use Markup "Trinket"+ ITEMID to render trinket sprites (example: {{Trinket1}} = Swallowed Penny) ["Slotmachine"] = {"Slotmachine", 0, 7, 7}, -- Room Icons ["Shop"] = {"roomicons", 0, 7, 9}, diff --git a/eid_debugging.lua b/eid_debugging.lua index e1c8b665..84c5f48d 100644 --- a/eid_debugging.lua +++ b/eid_debugging.lua @@ -67,6 +67,7 @@ dummySprite2:Load("gfx/eid_inline_icons.anm2", true) EID.InlineIcons["Test"] = {"pickups", -1, 9, 9, -1, 0, dummySprite2} __eidItemDescriptions[2] = "{{Bomb}} Emote {{Key}} Test {{Test}}{{TestIcon}} {{ColorBlackBlink}}description {{SomeInvalidInnerStuff}} cool" -- 5.100.2 = Inner Eye +__eidItemDescriptions[6] = "This item as Inline Icon {{Collectible6}}#And here are others {{Collectible69}} {{Collectible16}} {{Collectible323}} {{Collectible345}} {{Collectible223}}#And some trinket sprites {{Trinket12}} {{Trinket22}} {{Trinket1}} {{Trinket55}} {{Trinket100}} {{Trinket123}}" -- 5.100.2 = Inner Eye ------ Test: adding custom transformation icon ------ EID.InlineIcons["SomeTestTransformation"] = {"hearts", 2, 9, 9, -1, 0, dummySprite} diff --git a/main.lua b/main.lua index d7aa77b2..f31abb4c 100644 --- a/main.lua +++ b/main.lua @@ -14,6 +14,9 @@ EID.IconSprite:Load("gfx/icons.anm2", true) EID.InlineIconSprite = Sprite() EID.InlineIconSprite:Load("gfx/eid_inline_icons.anm2", true) +EID.ItemSprite = Sprite() +EID.ItemSprite:Load("gfx/005.100_collectible.anm2", true) + local ArrowSprite = Sprite() ArrowSprite:Load("gfx/icons.anm2", true) ArrowSprite:Play("Arrow", false) diff --git a/resources/gfx/eid_inline_icons.anm2 b/resources/gfx/eid_inline_icons.anm2 index 6693704b..5d0ff9c2 100644 --- a/resources/gfx/eid_inline_icons.anm2 +++ b/resources/gfx/eid_inline_icons.anm2 @@ -1,11 +1,13 @@ - + + + @@ -31,6 +33,7 @@ + @@ -43,6 +46,7 @@ + @@ -70,6 +74,7 @@ + @@ -82,6 +87,7 @@ + @@ -94,6 +100,7 @@ + @@ -106,6 +113,7 @@ + @@ -127,6 +135,7 @@ + @@ -157,6 +166,7 @@ + @@ -169,6 +179,7 @@ + @@ -181,6 +192,7 @@ + @@ -193,6 +205,7 @@ + @@ -216,6 +229,20 @@ + + + + + + + + + + + + + +