Skip to content

Commit

Permalink
styling
Browse files Browse the repository at this point in the history
  • Loading branch information
bmos committed Feb 26, 2024
1 parent 5a4e205 commit 7cb5286
Show file tree
Hide file tree
Showing 9 changed files with 364 additions and 253 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If the item is a suit of armor or a shield, the bonus it grants to AC is halved,
When attacking with a weapon, it will be checked for the "fragile" quality and broken automatically on a natural 1. If the weapon is already broken, the weapon will be destroyed instead.

# Compatibility and Instructions
This extension has been tested with [FantasyGrounds Unity](https://www.fantasygrounds.com/home/FantasyGroundsUnity.php) v4.4.9 (2023-12-18).
This extension has been tested with [FantasyGrounds Unity](https://www.fantasygrounds.com/home/FantasyGroundsUnity.php) v4.5.0 (2024-02-21).

# Features
* Simplifies tracking hitpoints of weapons, armor, and equipment.
Expand Down
14 changes: 9 additions & 5 deletions campaign/scripts/backupitemstat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@
function backupValue()
local nodeItem = window.getDatabaseNode()

local nItemBrokenState = DB.getValue(nodeItem, 'broken')
local nItemBrokenState = DB.getValue(nodeItem, "broken")
local nItemValue = DB.getValue(nodeItem, getName())

if nItemBrokenState == 0 and string.lower(DB.getValue(nodeItem, 'type', '')) == 'armor' then
DB.setValue(nodeItem, getName() .. '.backup', 'number', nItemValue)
if nItemBrokenState == 0 and string.lower(DB.getValue(nodeItem, "type", "")) == "armor" then
DB.setValue(nodeItem, getName() .. ".backup", "number", nItemValue)
end
end

function onInit()
if super and super.onInit then super.onInit() end
if super and super.onInit then
super.onInit()
end

onValueChanged()
end

function onValueChanged()
if super and super.onValueChanged then super.onValueChanged() end
if super and super.onValueChanged then
super.onValueChanged()
end

backupValue()
end
12 changes: 9 additions & 3 deletions campaign/scripts/calculatesave.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,26 @@ function updateSaves()
end

function update(...)
if super and super.update then super.update(...) end
if super and super.update then
super.update(...)
end

updateSaveVisibility()
end

function onValueChanged()
if super and super.onValueChanged then super.onValueChanged() end
if super and super.onValueChanged then
super.onValueChanged()
end

updateSaves()
updateSaveVisibility()
end

function onInit()
if super and super.onInit then super.onInit() end
if super and super.onInit then
super.onInit()
end

onValueChanged()
end
14 changes: 8 additions & 6 deletions campaign/scripts/item_main2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ function HHDVisibility(bReadOnly)
end

function update()
if super and super.update then super.update() end
if super and super.update then
super.update()
end

local nodeRecord = getDatabaseNode()
local bReadOnly = WindowManager.getReadOnlyState(nodeRecord)
local bID = LibraryData.getIDState('item', nodeRecord)
local bID = LibraryData.getIDState("item", nodeRecord)

local sItemSubwindow = type_stats.getValue() -- 'item_main_armor', 'item_main_weapon', or ''

WindowManager.callSafeControlUpdate(self, 'substance', bReadOnly, not bID)
WindowManager.callSafeControlUpdate(self, 'size', bReadOnly)
WindowManager.callSafeControlUpdate(self, 'thickness', bReadOnly)
WindowManager.callSafeControlUpdate(self, "substance", bReadOnly, not bID)
WindowManager.callSafeControlUpdate(self, "size", bReadOnly)
WindowManager.callSafeControlUpdate(self, "thickness", bReadOnly)

if sItemSubwindow == 'item_main_armor' then
if sItemSubwindow == "item_main_armor" then
thickness.setVisible(false)
thickness_label.setVisible(false)
end
Expand Down
16 changes: 11 additions & 5 deletions campaign/scripts/itemdamage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
-- luacheck: globals onDrop onValueChanged setDamageLevel checkDamageLevel update

function onDrop(_, _, draginfo)
if string.find(draginfo.getDescription(), '%[DAMAGE', 1) then
if string.find(draginfo.getDescription(), "%[DAMAGE", 1) then
ItemDurabilityDamage.splitDamageTypes(window.getDatabaseNode(), draginfo.getDescription())
end
end

function setDamageLevel(color, damageLevel)
window.itemdamage.setColor(color)
DB.setValue(window.getDatabaseNode(), 'broken', 'number', damageLevel)
DB.setValue(window.getDatabaseNode(), "broken", "number", damageLevel)
end

function checkDamageLevel()
local nItemHitpoints = window.hitpoints.getValue() or 0
if nItemHitpoints == 0 then return end
if nItemHitpoints == 0 then
return
end

if nItemHitpoints >= 1 then
local nPercentDmg = window.itemdamage.getValue() / nItemHitpoints * 100
Expand All @@ -34,13 +36,17 @@ function checkDamageLevel()
end

function onValueChanged()
if super and super.onValueChanged then super.onValueChanged() end
if super and super.onValueChanged then
super.onValueChanged()
end

checkDamageLevel()
end

function onInit()
if super and super.onInit then super.onInit() end
if super and super.onInit then
super.onInit()
end

onValueChanged()
end
Loading

0 comments on commit 7cb5286

Please sign in to comment.