From 0be6a4125d7e60566d66e675f4f35ac130a09f44 Mon Sep 17 00:00:00 2001 From: "theo@manjaro" Date: Tue, 6 Jun 2023 18:08:11 +0200 Subject: [PATCH] Initial commit --- LICENSE | 14 +++++ README.md | 16 ++++++ main.lua | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++ metadata.xml | 11 ++++ save.lua | 25 +++++++++ 5 files changed, 218 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 main.lua create mode 100644 metadata.xml create mode 100644 save.lua diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ee7d6a5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,14 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..38549fc --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Dead God Helper + +A small mod for The Binding Of Isaac: Repentance! + +It signals items that were not previously picked up on this savefile when you encounter them.Very useful when you're trying to get a second or third Dead God. + +I made it mainly for myself, because it was annoying to go back to the menu every time I encountered an item I was unsure about. + +There's an integration with External Item Description. +It is also compatible with Mod Config Menu, if you want to toggle things (such as displaying info when on Curse Of The Blind) + +There's however a limitation: since (to my knowledge) there's no way to get information about seen items from the savefile, this mod takes it upon itself to track which item you picked up. (This mean that when you install the mod for the first time, every non-modded Item will be tagged as Unseen) + +Anyway, I hope that this mod will be useful to someone :) + +(Source code is available at https://forge.chapril.org/ayte/DeadGodHelper) diff --git a/main.lua b/main.lua new file mode 100644 index 0000000..0e2f9b7 --- /dev/null +++ b/main.lua @@ -0,0 +1,152 @@ +local modname = "DeadGod Helper" +local mod = RegisterMod(modname, 1) +local json = require("json") +local math = require("math") +mod.print = Isaac.ConsoleOutput +mod.game = Game() +local save = include("save"):new() +if mod:HasData() then + save = json.decode(mod:LoadData()) +end + +mod.font = Font() +mod.font:Load("font/terminus.fnt") + +function mod:isCurseBlind() + return mod.game:GetLevel():GetCurses() & LevelCurse.CURSE_OF_BLIND > 0 +end + +function mod.isIdNotTakenAlready(id) + if id>=1 and id<=save.settings.maxid then + return not save.seen[id] + else + return false + end +end + +function mod.registerTouched(id) + if id>=1 and id<=save.settings.maxid then + save.seen[id] = true + end + + -- Save + mod:SaveData(json.encode(save)) +end + +-- Used to check if EID's description should be modified +function mod.shouldBeModified(descObj) + -- Taken from https://github.com/wofsauge/External-Item-Descriptions/wiki/Description-Modifiers + -- if entity is a piedestal + if descObj.ObjType == 5 and descObj.ObjVariant == 100 then + -- Check if item was not already taken in this savefile + -- And if item is non-modded (id<= Mom's ring ID) + local id = descObj.ObjSubType + return mod.isIdNotTakenAlready(id) + end +end + +-- Used to modify EID's description +function mod.modifierCallback(descObj) + if save.settings.eid then + descObj.Description = "#{{Trophy}} Not picked up yet!#"..descObj.Description + end + return descObj +end + +-- Used to detect when an item is picked up +function mod:update() + for i=0, mod.game:GetNumPlayers()-1 do + local player = mod.game:GetPlayer(i) + local data = player:GetData() + local item = player.QueuedItem.Item + if data._deadgodlastid and data._deadgodlastcount and data._deadgodlastid>0 then + if item==nil then -- Finished animation + if player:GetCollectibleNum(data._deadgodlastid)>data._deadgodlastcount then -- Have it on me + -- Then I just picked it up, yay + mod.registerTouched(data._deadgodlastid) + data._deadgodlastid = 0 + data._deadgodlastcount = 0 + end + end + end + if item and item:IsCollectible() then + data._deadgodlastid = item.ID + data._deadgodlastcount = player:GetCollectibleNum(item.ID) + end + end +end + +-- Used to draw the ! sign +function mod:PickupDrawCallback(pickupEntity, _) + if save.settings.visual and (not mod:isCurseBlind() or save.settings.showonblind)then + if pickupEntity.Variant==PickupVariant.PICKUP_COLLECTIBLE then + if mod.isIdNotTakenAlready(pickupEntity.SubType) then + local v = Isaac.WorldToScreen(pickupEntity.Position + pickupEntity.SpriteOffset) + mod.font:DrawString("!", v.X-1, v.Y-52+math.sin(mod.game:GetFrameCount()/10)*2, KColor(0.98,0.93,0.55,1), 2, true) + end + end + end +end + +mod:AddCallback(ModCallbacks.MC_POST_UPDATE, mod.update) +mod:AddCallback(ModCallbacks.MC_POST_PICKUP_RENDER, mod.PickupDrawCallback) + +if EID then + EID:addDescriptionModifier( + modname, + mod.shouldBeModified, + mod.modifierCallback + ) +end + +if ModConfigMenu then + ModConfigMenu.AddSetting( + modname, -- This should be unique for your mod + nil, + { + Type = ModConfigMenu.OptionType.BOOLEAN, + CurrentSetting = function() + return save.settings.eid + end, + Display = function() + return "Show in EID: " .. (save.settings.eid and "on" or "off") + end, + OnChange = function(b) + save.settings.eid = b + end, + } + ) + ModConfigMenu.AddSetting( + modname, -- This should be unique for your mod + nil, + { + Type = ModConfigMenu.OptionType.BOOLEAN, + CurrentSetting = function() + return save.settings.visual + end, + Display = function() + return "Show on pedestals: " .. (save.settings.visual and "on" or "off") + end, + OnChange = function(b) + save.settings.visual = b + end, + } + ) + + ModConfigMenu.AddSetting( + modname, -- This should be unique for your mod + nil, + { + Type = ModConfigMenu.OptionType.BOOLEAN, + CurrentSetting = function() + return save.settings.showonblind + end, + Display = function() + return "Show while having Curse Of The Blind: " .. (save.settings.showonblind and "on" or "off") + end, + OnChange = function(b) + save.settings.showonblind = b + end, + } + ) +end diff --git a/metadata.xml b/metadata.xml new file mode 100644 index 0000000..85a278f --- /dev/null +++ b/metadata.xml @@ -0,0 +1,11 @@ + + + DeadGod Helper + deadgod helper + 2985754961 + + 1.1 + Private + + + diff --git a/save.lua b/save.lua new file mode 100644 index 0000000..caf45a1 --- /dev/null +++ b/save.lua @@ -0,0 +1,25 @@ +local savegen = {} + +function savegen:new() + + local save = {} + + save.settings = {} + save.settings.eid = true + save.settings.visual = true + save.settings.showonblind = false + save.settings.maxid = 732 + + save.seen = {} + for i=1, save.settings.maxid do + save.seen[i] = false + end + + function save:touch(id) + self.seen[id] = true + end + + return save +end + +return savegen