Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion scripts/autotracking/archipelago.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ CUR_INDEX = -1
LOCAL_ITEMS = {}
GLOBAL_ITEMS = {}

ALL_LOCATIONS = {}

MANUAL_CHECKED = true
ROOM_SEED = "default"

-- gets the data storage key for hints for the current player
-- returns nil when not connected to AP
function getHintDataStorageKey()
Expand Down Expand Up @@ -104,13 +109,56 @@ function apply_slot_data(slot_data)
-- put any code here that slot_data should affect (toggling setting items for example)
end

function preOnClear()
PLAYER_ID = Archipelago.PlayerNumber or -1
TEAM_NUMBER = Archipelago.TeamNumber or 0
if Archipelago.PlayerNumber > -1 then
if #ALL_LOCATIONS > 0 then
ALL_LOCATIONS = {}
end
for _, value in pairs(Archipelago.MissingLocations) do
table.insert(ALL_LOCATIONS, #ALL_LOCATIONS + 1, value)
end

for _, value in pairs(Archipelago.CheckedLocations) do
table.insert(ALL_LOCATIONS, #ALL_LOCATIONS + 1, value)
end
end

local custom_storage_item = Tracker:FindObjectForCode("manual_location_storage")
local seed_base = (Archipelago.Seed or tostring(#ALL_LOCATIONS)).."_"..Archipelago.TeamNumber.."_"..Archipelago.PlayerNumber
if ROOM_SEED == "default" or ROOM_SEED ~= seed_base then -- seed is default or from previous connection

ROOM_SEED = seed_base
if #custom_storage_item.ItemState.MANUAL_LOCATIONS > 10 then
custom_storage_item.ItemState.MANUAL_LOCATIONS[custom_storage_item.ItemState.MANUAL_LOCATIONS_ORDER[1]] = nil
table.remove(custom_storage_item.ItemState.MANUAL_LOCATIONS_ORDER, 1)
end
if custom_storage_item.ItemState.MANUAL_LOCATIONS[ROOM_SEED] == nil then
custom_storage_item.ItemState.MANUAL_LOCATIONS[ROOM_SEED] = {}
table.insert(custom_storage_item.ItemState.MANUAL_LOCATIONS_ORDER, ROOM_SEED)
end
else -- seed is from previous connection
-- do nothing
end
end

-- called right after an AP slot is connected
function onClear(slot_data)
-- use bulk update to pause logic updates until we are done resetting all items/locations
Tracker.BulkUpdate = true
if AUTOTRACKER_ENABLE_DEBUG_LOGGING_AP then
print(string.format("called onClear, slot_data:\n%s", dump_table(slot_data)))
end

MANUAL_CHECKED = false
local custom_storage_item = Tracker:FindObjectForCode("manual_location_storage")
if custom_storage_item == nil then
CreateLuaManualLocationStorage("manual_location_storage")
custom_storage_item = Tracker:FindObjectForCode("manual_location_storage")
end
preOnClear()

CUR_INDEX = -1
-- reset locations
for _, mapping_entry in pairs(LOCATION_MAPPING) do
Expand All @@ -124,7 +172,11 @@ function onClear(slot_data)
if location_code:sub(1, 1) == "@" then
local obj = Tracker:FindObjectForCode(location_code)
if obj then
obj.AvailableChestCount = obj.ChestCount
if custom_storage_item.ItemState.MANUAL_LOCATIONS[ROOM_SEED][obj.FullID] then
obj.AvailableChestCount = custom_storage_item.ItemState.MANUAL_LOCATIONS[ROOM_SEED][obj.FullID]
else
obj.AvailableChestCount = obj.ChestCount
end
if obj.Highlight then
obj.Highlight = Highlight.None
end
Expand Down Expand Up @@ -178,6 +230,7 @@ function onClear(slot_data)
-- gets the current value for the data storage keys
-- triggers callback in the Retrieved handler when result is received
Archipelago:Get(data_strorage_keys)
MANUAL_CHECKED = true
Tracker.BulkUpdate = false
end

Expand Down Expand Up @@ -237,10 +290,12 @@ function onItem(index, item_id, item_name, player_number)
if PopVersion < "0.20.1" or AutoTracker:GetConnectionState("SNES") == 3 then
-- add snes interface functions for local item tracking here
end
MANUAL_CHECKED = true
end

-- called when a location gets cleared
function onLocation(location_id, location_name)
MANUAL_CHECKED = false
if AUTOTRACKER_ENABLE_DEBUG_LOGGING_AP then
print(string.format("called onLocation: %s, %s", location_id, location_name))
end
Expand Down
62 changes: 62 additions & 0 deletions scripts/custom_items/manual_marked_storage.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
local function SaveManualLocationStorageFunc(self) -- executed on pack close or during export for each item
return {
MANUAL_LOCATIONS = self.ItemState.MANUAL_LOCATIONS,
MANUAL_LOCATIONS_ORDER = self.ItemState.MANUAL_LOCATIONS_ORDER,
Name = self.Name,
Icon = self.Icon
}
end

local function LoadManualLocationStorageFunc(self, data) --executed on pack load
if data ~= nil and self.Name == data.Name then
self.ItemState.MANUAL_LOCATIONS = data.MANUAL_LOCATIONS
self.ItemState.MANUAL_LOCATIONS_ORDER = data.MANUAL_LOCATIONS_ORDER
self.Icon = ImageReference:FromPackRelativePath(data.Icon)
else
end
end

local function OnLeftClickFunc(self)
end
local function OnRightClickFunc(self)
end
local function OnMiddleClickFunc(self)
end

local function CanProvideCodeFunc(self, code)
return code == self.Name
end

local function ProvidesCodeFunc(self, code)
if CanProvideCodeFunc(self, code) then
return 1
end
return 0
end

function CreateLuaManualLocationStorage(name)
local self = ScriptHost:CreateLuaItem()

self.Name = name --code --
self.Icon = ImageReference:FromPackRelativePath("/images/items/closed_Chest.png")
self.ItemState = {
MANUAL_LOCATIONS = {
["default"] = {}
},
MANUAL_LOCATIONS_ORDER = {}
}

self.CanProvideCodeFunc = CanProvideCodeFunc
self.OnLeftClickFunc = OnLeftClickFunc
self.OnRightClickFunc = OnRightClickFunc
self.OnMiddleClickFunc = OnMiddleClickFunc
self.ProvidesCodeFunc = ProvidesCodeFunc
-- self.AdvanceToCodeFunc = AdvanceToCodeFunc
self.SaveFunc = SaveManualLocationStorageFunc
self.LoadFunc = LoadManualLocationStorageFunc
-- self.PropertyChangedFunc = PropertyChangedFunc
-- self.ItemState = ItemState
return self
end

CreateLuaManualLocationStorage("manual_location_storage")
3 changes: 3 additions & 0 deletions scripts/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ScriptHost:LoadScript("scripts/logic/logic.lua")
ScriptHost:LoadScript("scripts/custom_items/class.lua")
ScriptHost:LoadScript("scripts/custom_items/progressiveTogglePlus.lua")
ScriptHost:LoadScript("scripts/custom_items/progressiveTogglePlusWrapper.lua")
ScriptHost:LoadScript("scripts/custom_items/manual_marked_storage.lua")

-- Items
Tracker:AddItems("items/items.jsonc")
Expand All @@ -42,3 +43,5 @@ Tracker:AddLayouts("layouts/broadcast.jsonc")
if PopVersion and PopVersion >= "0.18.0" then
ScriptHost:LoadScript("scripts/autotracking.lua")
end

ScriptHost:AddOnLocationSectionChangedHandler("location_section_change_handler", LocationHandler)
23 changes: 23 additions & 0 deletions scripts/logic/logic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,27 @@ function has_more_then_n_consumable(n)
return 1 -- 1 => access is in logic
end
return 0 -- 0 => no access
end

-- handler function for the custom lua item that stores manually marked off locations
function LocationHandler(location)
if MANUAL_CHECKED then
local custom_storage_item = Tracker:FindObjectForCode("manual_location_storage")
if not custom_storage_item then
return
end
if Archipelago.PlayerNumber == -1 then -- not connected
if ROOM_SEED ~= "default" then -- seed is from previous connection
ROOM_SEED = "default"
custom_storage_item.ItemState.MANUAL_LOCATIONS["default"] = {}
else -- seed is default
end
end
local full_path = location.FullID
if location.AvailableChestCount < location.ChestCount then --add to list
custom_storage_item.ItemState.MANUAL_LOCATIONS[ROOM_SEED][full_path] = location.AvailableChestCount
else --remove from list or set back to max chestcount
custom_storage_item.ItemState.MANUAL_LOCATIONS[ROOM_SEED][full_path] = nil
end
end
end