Thread: FGU support of custom unit size?
-
December 1st, 2019, 22:32 #21---
Coding the Official AD&D Ruleset
My Twitch Channel for AD&D and FG related streams (See schedule for live days)
My YouTube for FG related Tutorials and AD&D Actual Plays
-
December 2nd, 2019, 00:31 #22
Developer
- Join Date
- Mar 2007
- Posts
- 11,190
It's supposed to be in whole grid units (multiplied by base units). If not, then FGC is not working as intended.
Also, I'm not sure how you got that to appear like that in your version, since it does not do that when I try in CoreRPG, 3.5E or 5E on FGC.
Thanks,
JPGLast edited by Moon Wizard; December 2nd, 2019 at 00:36.
FG Wish List - http://fg2app.idea.informer.com/
-
December 2nd, 2019, 05:05 #23
Only bringing this up because you told me to not make kludges around FGU when FGC works another way.
To be clear this is not untouched ruleset, it's related to the unit/suffix code. I had it already in the AD&D ruleset. I updated the code to function within FGU (with your new API functions) and FGC.
I added this script to the image_record class.
Code:<!-- standard image template --> <template name="image_record"> <image_record_step> <bounds>21,63,-27,-29</bounds> <script file="campaign/scripts/image_record.lua"/> </image_record_step> </template>
Code:-- -- Please see the license.html file included with this distribution for -- attribution and copyright information. -- function onInit() -- if Interface.getVersion() >= 4 then if User.isHost() then local node = getDatabaseNode(); DB.addHandler(DB.getPath(node.getParent(), "muse_unitsize_number"), "onUpdate", onUnitSizeUpdates); DB.addHandler(DB.getPath(node.getParent(), "muse_suffix_string"), "onUpdate", onUnitSizeUpdates); DB.addHandler(DB.getPath(node.getParent(), "locked"), "onUpdate", onLockChanged); onUnitSizeUpdates(node); onLockChanged(node); end end -- when the map is loaded setup these. TokenManagerADND.updateCTEntries(); end function onClose() if Interface.getVersion() >= 4 then if User.isHost() then local node = getDatabaseNode(); DB.removeHandler(DB.getPath(node.getParent(), "muse_unitsize_number"), "onUpdate", onUnitSizeUpdates); DB.removeHandler(DB.getPath(node.getParent(), "muse_suffix_string"), "onUpdate", onUnitSizeUpdates); DB.removeHandler(DB.getPath(node.getParent(), "locked"), "onUpdate", onLockChanged); end end end -- update size/suffix on the map when they are reconfigured. function onUnitSizeUpdates(node) node = node.getParent(); --local node = getDatabaseNode().getParent(); setDistanceBaseUnits(tostring(DB.getValue(node,"muse_unitsize_number","5"))); setDistanceSuffix(DB.getValue(node,"muse_suffix_string","ft")); --getDistanceBaseUnits() = current base units (override if >0; otherwise ruleset value) --getDistanceSuffix() = current suffix value (override if not nil; otherwise ruleset value) --Debug.console("image_record.lua","onUnitSizeUpdates","getDistanceBaseUnits()",getDistanceBaseUnits()); --Debug.console("image_record.lua","onUnitSizeUpdates","getDistanceSuffix()",getDistanceSuffix()); end -- when the map unlocked show the size/suffix fields. function onLockChanged() local node = getDatabaseNode().getParent(); --Debug.console("image_record.lua","onLockChanged","node",node); local bUnLocked = DB.getValue(node, "locked", 0) == 0; window.header.subwindow.muse_unitsize_label.setVisible(bUnLocked); window.header.subwindow.muse_unitsize_number.setVisible(bUnLocked); window.header.subwindow.muse_suffix_label.setVisible(bUnLocked); window.header.subwindow.muse_suffix_string.setVisible(bUnLocked); end -- get the unit scale and measurement function getUnitControlSetting() local sValue = '5ft'; if Interface.getVersion() < 4 then local node = getDatabaseNode().getChild(".."); sValue = DB.getValue(node,"scale","10ft"); -- default to 10ft here but we should never see this. else sValue = getDistanceBaseUnit() .. getDistanceSuffix(); end return sValue; end -- is the scale value VALID? function getUnitControlisValid() local bValid = false; if Interface.getVersion() < 4 then bValid = getUnitControlSetting():find("^[%d%.]+") ~= nil else bValid = true; end return bValid; end -- get the size of each unit function getUnitControlValue() local nScaleValue = 0; if Interface.getVersion() < 4 then if getUnitControlisValid() then nScaleValue = tonumber(getUnitControlSetting():match("^([%d%.]+)")) or 0 end else nScaleValue = getDistanceBaseUnit() or 5; end return nScaleValue; end -- get the scale measurement name/string function getUnitControlLabel() local sValue = "ft"; if Interface.getVersion() < 4 then sValue = StringManager.trim(getUnitControlSetting():gsub("^[%d%.]+%s*", "")) else sValue = getDistanceSuffix(); end return sValue; end -- measureVector function measureVector(nVectorX, nVectorY, sGridType, nGridSize, nGridHexWidth, nGridHexHeight) local nDiag = 1; if OptionsManager.isOption("HRDD", "variant") then nDiag = 1.5; end local nDistance = 0 if sGridType == "hexrow" or sGridType == "hexcolumn" then local nCol, nRow = 0, 0 if sGridType == "hexcolumn" then nCol = nVectorX / (nGridHexWidth*3) nRow = (nVectorY / (nGridHexHeight*2)) - (nCol * 0.5) else nRow = nVectorY / (nGridHexWidth*3) nCol = (nVectorX / (nGridHexHeight*2)) - (nRow * 0.5) end if ((nRow >= 0 and nCol >= 0) or (nRow < 0 and nCol < 0)) then nDistance = math.abs(nCol) + math.abs(nRow) else nDistance = math.max(math.abs(nCol), math.abs(nRow)) end else -- if sGridType == "square" then local nDiagonals = 0 local nStraights = 0 local nGridX = math.abs(nVectorX / nGridSize) local nGridY = math.abs(nVectorY / nGridSize) if nGridX > nGridY then nDiagonals = nDiagonals + nGridY nStraights = nStraights + nGridX - nGridY else nDiagonals = nDiagonals + nGridX nStraights = nStraights + nGridY - nGridX end nDistance = nDiagonals * nDiag + nStraights end return nDistance end -- when measuring a vector distance function onMeasureVector(token, aVector) if hasGrid() then local sGridType = getGridType() local nGridSize = getGridSize() local nDistance = 0 if sGridType == "hexrow" or sGridType == "hexcolumn" then local nGridHexWidth, nGridHexHeight = getGridHexElementDimensions() for i = 1, #aVector do local nVector = measureVector(aVector[i].x, aVector[i].y, sGridType, nGridSize, nGridHexWidth, nGridHexHeight) nDistance = nDistance + nVector end else -- if sGridType == "square" then for i = 1, #aVector do local nVector = measureVector(aVector[i].x, aVector[i].y, sGridType, nGridSize) nDistance = nDistance + nVector end end if getUnitControlisValid() then --return (nDistance * getUnitControlValue()) .. getUnitControlLabel(); return (UtilityManagerADND.round(nDistance * getUnitControlValue())) .. getUnitControlLabel() else return "" end else return "" end end -- when measuring a pointer distance function onMeasurePointer(nLength, sPointerType, nStartX, nStartY, nEndX, nEndY) if hasGrid() then local sGridType = getGridType() local nGridSize = getGridSize() if sGridType == "hexrow" or sGridType == "hexcolumn" then local nGridHexWidth, nGridHexHeight = getGridHexElementDimensions() nDistance = measureVector(nEndX - nStartX, nEndY - nStartY, sGridType, nGridSize, nGridHexWidth, nGridHexHeight) else -- if sGridType == "square" then nDistance = measureVector(nEndX - nStartX, nEndY - nStartY, sGridType, nGridSize) end if getUnitControlisValid() then return (UtilityManagerADND.round(nDistance * getUnitControlValue())) .. getUnitControlLabel() else return "" end else return "" end end
It now looks like this. If I updated the MUSE extension it would do the same for CoreRPG/etc.
---
Coding the Official AD&D Ruleset
My Twitch Channel for AD&D and FG related streams (See schedule for live days)
My YouTube for FG related Tutorials and AD&D Actual Plays
-
December 2nd, 2019, 08:29 #24
Developer
- Join Date
- Mar 2007
- Posts
- 11,190
It's because you are measuring your own vectors that you were seeing the large numbers; and the half measures.
The built-in measuring and the way the original onMeasureVector was supposed to work before we built it into the client is that it was based on grid squares first, then multiplied by base units.
Regards,
JPGFG Wish List - http://fg2app.idea.informer.com/
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks