Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for some issues caused by gmcp changes #151

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion src/scripts/PRS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if table.contains(getPackages(), "generic_mapper") then
uninstallPackage("generic_mapper")
end

registerAnonymousEventHandler("gmcp.Char.player", function()
registerAnonymousEventHandler("PRSState.Char.player", function()
PRSstats.stats()
end, true)

Expand Down
2 changes: 1 addition & 1 deletion src/scripts/prs-ascii-map.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ map_handler_id = registerAnonymousEventHandler("gmcp.Char.Output", mapEventHandl
if send_command_handler_id then
killAnonymousEventHandler(send_command_handler_id)
end
send_command_handler_id = registerAnonymousEventHandler("gmcp.Char.room", sendMapCommand)
send_command_handler_id = registerAnonymousEventHandler("PRSState.Char.room", sendMapCommand)
8 changes: 4 additions & 4 deletions src/scripts/prs-inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ end
PRSinv.currentInventoryIndex = 1

PRSinv.getNextInventoryItem = function()
if PRSinv.currentInventoryIndex <= #gmcp.Char.inventory then
local iid = gmcp.Char.inventory[PRSinv.currentInventoryIndex]
if PRSinv.currentInventoryIndex <= #PRSState.Char.inventory then
local iid = PRSState.Char.inventory[PRSinv.currentInventoryIndex]
if not PRSinv.inventoryTable[iid] then
-- echo("Getting inventory item " .. PRSinv.currentInventoryIndex .. "/" .. #gmcp.Char.inventory .. "\n")
PRSinv.gmcpGetItem(iid)
Expand Down Expand Up @@ -52,7 +52,7 @@ end
PRSinv.labels = PRSinv.labels or {}

PRSinv.displayAllInventory = function()
for i, iid in ipairs(gmcp.Char.inventory) do
for i, iid in ipairs(PRSState.Char.inventory) do
PRSinv.displayItem(i, iid)
end
end
Expand Down Expand Up @@ -98,4 +98,4 @@ PRSinv.invEventHandler = registerAnonymousEventHandler("gmcp.Item", PRSinv.gmcpS
if PRSinv.getInvEventHandler then
killAnonymousEventHandler(PRSinv.getInvEventHandler)
end -- clean up any already registered handlers for this function
PRSinv.getInvEventHandler = registerAnonymousEventHandler("gmcp.Char.inventory", PRSinv.getAllInventoryData)
PRSinv.getInvEventHandler = registerAnonymousEventHandler("PRSState.Char.inventory", PRSinv.getAllInventoryData)
10 changes: 5 additions & 5 deletions src/scripts/prs-mapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -782,12 +782,12 @@ end
function map.speedwalk(roomID, walkPath, walkDirs)
roomID = roomID or speedWalkPath[#speedWalkPath]
local areas = getAreaTable()
local area_id = areas[gmcp.Char.room.area]
local area_id = areas[PRSState.Char.room.area]
if area_id == nil then
echo("Error: could not identify the current area.\n")
return
end
local current_room_id = get_room_id_by_coordinates(gmcp.Char.room.area, gmcp.Char.room.x, -gmcp.Char.room.y, 0)
local current_room_id = get_room_id_by_coordinates(PRSState.Char.room.area, PRSState.Char.room.x, -PRSState.Char.room.y, 0)
if current_room_id == nil then
echo("Error: could not find the current room in the map.\n")
return
Expand Down Expand Up @@ -901,13 +901,13 @@ map.events.connect_id = registerAnonymousEventHandler("sysConnectionEvent", "map
if map.events.centering_id then
killAnonymousEventHandler(map.events.centering_id)
end -- clean up any already registered handlers for this function
map.events.centering_id = registerAnonymousEventHandler("gmcp.Char.room", function(event, args)
map.events.centering_id = registerAnonymousEventHandler("PRSState.Char.room", function(event, args)

if gmcp.Char.room.area == "Battlefield" then
if PRSState.Char.room.area == "Battlefield" then
return
end

local room_id = get_room_id_by_coordinates(gmcp.Char.room.area, gmcp.Char.room.x, -gmcp.Char.room.y, 0)
local room_id = get_room_id_by_coordinates(PRSState.Char.room.area, PRSState.Char.room.x, -PRSState.Char.room.y, 0)
if room_id ~= nil then
centerview(room_id)
end
Expand Down
10 changes: 5 additions & 5 deletions src/scripts/prs-quests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ local QUEST_LABEL_HEIGHT = 65
local QUEST_GAP = 0

function displayAllQuests()
for i, quest in ipairs(gmcp.Char.quests) do
for i, quest in ipairs(PRSState.Char.quests) do
displayQuest(i)
end

for n=#gmcp.Char.quests+1, #questContainerTable, 1 do
for n=#PRSState.Char.quests+1, #questContainerTable, 1 do
questContainerTable[n]:hide()
questBox:remove(questContainerTable[n])
end
Expand All @@ -35,7 +35,7 @@ questBox = questBox or Geyser.ScrollBox:new({
}, scrollContainer)

function displayQuest(questNum)
local quest = gmcp.Char.quests[questNum]
local quest = PRSState.Char.quests[questNum]

createNewQuestLabel(questNum)

Expand Down Expand Up @@ -76,7 +76,7 @@ function createNewQuestLabel(questNum)
end

function addGaugeToQuestLabel(questNum)
local quest = gmcp.Char.quests[questNum]
local quest = PRSState.Char.quests[questNum]

-- box that holds the gauge and the label
questContainerTable[questNum].progressBox = questContainerTable[questNum].progressBox or Geyser.HBox:new({
Expand Down Expand Up @@ -159,4 +159,4 @@ end
if questEventHandlerId then
killAnonymousEventHandler(questEventHandlerId)
end -- clean up any already registered handlers for this function
questEventHandlerId = registerAnonymousEventHandler("gmcp.Char.quests", questEventHandler)
questEventHandlerId = registerAnonymousEventHandler("PRSState.Char.quests", questEventHandler)
18 changes: 12 additions & 6 deletions src/scripts/prs-skills.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ function addGaugeToSkillLabel(skillNum, skills, labels, color)
height = 15,
width = "100%", -- everything up to here is standard Geyser.Gauge
updateTime = 0,
updateEvent = "gmcp.Char.skills",
updateEvent = "PRSState.Char.skills",
textTemplate = "|p%",
currentVariable = "gmcp.Char.skills[" .. skill.gmcpIndex .. "].tnl", -- if it is nil or unreachable, it will use the defaultCurrent of 50
currentVariable = "PRSskills.skillList[" .. skill.gmcpIndex .. "].tnl", -- if it is nil or unreachable, it will use the defaultCurrent of 50
maxVariable = 100
}, labels[skillNum])
labels[skillNum].progressBar.front:setStyleSheet(string.format([[background-color: %s;
Expand All @@ -175,7 +175,7 @@ function getSkillString(skill)
end

function createSkills()
local sortedSkills = sortSkills(gmcp.Char.skills)
local sortedSkills = sortSkills(PRSskills.skillList)

local currentY = 0
for i, skill in ipairs(sortedSkills) do
Expand All @@ -196,12 +196,18 @@ function createSkills()
end

function skillEventHandler()
if (gmcp and gmcp.Char and gmcp.Char.skills and #gmcp.Char.skills ~= PRSskills.previousSkillCount) then
createSkills()
PRSskills.skillList = {}
if (PRSState and PRSState.Char and PRSState.Char.skills) then
for _, skill in pairs(PRSState.Char.skills) do
table.insert(PRSskills.skillList, skill)
end
if(#PRSskills.skillList ~= PRSskills.previousSkillCount) then
createSkills()
end
end
end

if skillEventHandlerId then
killAnonymousEventHandler(skillEventHandlerId)
end -- clean up any already registered handlers for this function
skillEventHandlerId = registerAnonymousEventHandler("gmcp.Char.skills", skillEventHandler)
skillEventHandlerId = registerAnonymousEventHandler("PRSState.Char.skills", skillEventHandler)
100 changes: 100 additions & 0 deletions src/scripts/prs-state-dispatcher.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
PRSState = PRSState or {}
PRSState.Char = PRSState.Char or {}
PRSState.Char.quests = PRSState.Char.quests or {}
PRSState.Char.player = PRSState.Char.player or {}
PRSState.Char.skills = PRSState.Char.skills or {}
PRSState.Char.room = PRSState.Char.room or {}
PRSState.Char.inventory = PRSState.Char.inventory or {}

function pathIsList(path)
i, j = string.find(path, "/%d+$")
return i ~= nil
end

function getAttributeAndIndex(path)
i, j = string.find(path, "/[^/]+/%d+$")
subpath = string.sub(path, i, j)
i, j = string.find(subpath, "^/[^/]+")
attr = string.sub(subpath, i+1, j)
i, j = string.find(subpath, "/%d+$")
slot = string.sub(subpath, i+1, j) + 1
return attr, slot
end

function getAttribute(path)
i, j = string.find(path, "/[^/]+$")
attr = string.sub(path, i+1, j)
return attr
end

function prs_state_dispatcher()
raisedEvents = {}
handledEvents = {}
for _, patch in ipairs(gmcp.State.Patch) do
table.insert(handledEvents, (string.gsub(string.sub(patch.path, 2), "/", ".")))
local segments = {}
local k = nil
for key in string.gmatch(patch.path, "([^/]+)") do
k = key
table.insert(segments, k)
end
if tonumber(k) then
k = k + 1
end
if #segments == 1 then
if patch.op == "replace" then
PRSState.Char[k] = patch.value
elseif patch.op == "remove" then
PRSState.Char[k] = nil
elseif patch.op == "add" then
if tonumber(k) then
table.insert(PRSState.Char, k, patch.value)
else
PRSState.Char[k] = patch.value
end
end
elseif #segments > 1 then
local target = PRSState.Char
local tk = nil
for i=1,#segments-1 do
tk = segments[i]
if target[tk] == nil then
target[tk] = {}
end
target = target[tk]
end
if patch.op == "replace" then
target[k] = patch.value
elseif patch.op == "remove" then
if tonumber(k) then
table.remove(target, k)
else
target[k] = nil
end
elseif patch.op == "add" then
if tonumber(k) then
table.insert(target, k, patch.value)
else
target[k] = patch.value
end
end
end
end
for _, event in ipairs(handledEvents) do
local eventToRaise = "PRSState.Char"
for subEvent in string.gmatch(event, "([^.]+)") do
eventToRaise = eventToRaise ..".".. subEvent
if raisedEvents[eventToRaise] == nil and tonumber(subEvent) == nil then
raisedEvents[eventToRaise] = {1}
raiseEvent(eventToRaise)
end
end
end
end

if stateEventHandlerId then
killAnonymousEventHandler(stateEventHandlerId)
end

stateEventHandlerId = registerAnonymousEventHandler("gmcp.State.Patch", prs_state_dispatcher, false)

Loading