Skip to content

Commit

Permalink
Merge pull request #3 from FG-Unofficial-Developers-Guild/contains-ov…
Browse files Browse the repository at this point in the history
…erride

fuzzy matching of item types
  • Loading branch information
bmos authored Sep 18, 2022
2 parents a7f60d5 + a489148 commit a8400b3
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 13 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ This extension has been tested with [FantasyGrounds Unity](https://www.fantasygr
# Features
This extension modifies the item sheet to add some additional features:

* Add GM-only field for tracking notes not visible to players.
* Wand / staff charges field
* Slot field for wondrous items
* Source field for tracking which book the information is from
* Type field visibility fixed
* Add GM-only field added to all items for tracking notes not visible to players.
* Charges fields added for Wands and Staffs.
* Slot field added for Wondrous Items.
* Source field added to all items for tracking an item's sourcebook.
* Activation field for tracking what action is needed for use. Visible for Weapons, Armor, Shields, Staffs, and Wondrous Items.
* Weapon/Shield/Armor detection functions are now 'fuzzy' so "Armor" / "Armors" / "Armor and Defense" / etc will all detect as armor.

All of the type specific fields only display with the appropriate item type, the same as would originally happen with "Weapon" or "Armor" in the Type field. Additionally, I have fixed the problem where "Weapon" would show the additional fields, but "Magic Weapon" would not. Visibility of the type-specific fields depends on "Weapon", "Armor", "Wand", "Staff", or "Wondrous Item" exactly, with capitalization. Otherwise text before or after doesn't matter.
All of the type specific fields only display with the appropriate item type, the same as would originally happen with "Weapon" or "Armor" in the Type field.

# Example Images
![example item sheets](https://user-images.githubusercontent.com/1916835/123555247-872b8b00-d752-11eb-95f0-db22c24091c2.jpg)
Expand Down
6 changes: 3 additions & 3 deletions campaign/record_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<root>
<windowclass name="item_main" merge="join">
<script file="campaign/scripts/item_main.lua" />
<script file="campaign/scripts/item_main_EI.lua" />
<sheetdata>
<label_column name="equipslot_label" insertbefore="divider2">
<static textres="item_label_equipslot" />
Expand Down Expand Up @@ -41,7 +41,7 @@
</label_column>

<number_columnh name="charge" insertbefore="divider4">
<anchored>
<anchored width="45">
<top offset="16" />
</anchored>
<stateframe>
Expand All @@ -62,7 +62,7 @@
</label_fieldtop>

<number_column name="maxcharges">
<anchored>
<anchored width="45">
<top parent="charge" anchor="top" offset="0" />
<left parent="charge" anchor="right" offset="10" />
</anchored>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ function update(...)
maxcharges_label.setVisible(false);
end

if self.updateControl('equipslot', bReadOnly, bID and tTypes['wondrous']) then tSections[4] = true; end
if self.updateControl('equipslot', bReadOnly, bID and tTypes['wondrous%sitem']) then tSections[4] = true; end

if self.updateControl("aura", bReadOnly, bID) then tSections[5] = true; end
if self.updateControl("cl", bReadOnly, bID) then tSections[5] = true; end
if self.updateControl("prerequisites", bReadOnly, bID) then tSections[5] = true; end
if self.updateControl("activation", bReadOnly, bID and (
tTypes['shield'] or tTypes['armor'] or tTypes['staff'] or tTypes['wondrous']
tTypes['shield'] or tTypes['armor'] or tTypes['staff'] or tTypes['wondrous%sitem']
)) then tSections[5] = true; end

tSections[6] = bID;
Expand Down
7 changes: 5 additions & 2 deletions extension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<root version="3.1">
<properties>
<name>Feature: Enhanced Items</name>
<version>4.7</version>
<version>4.8</version>
<author>llisandur</author>
<description>Adds useful fields to various types of items</description>
<ruleset>
Expand All @@ -20,12 +20,15 @@
<loadorder>50</loadorder>
</properties>

<announcement text="https://www.fantasygrounds.com/forums/showthread.php?40602-Extension-Enhanced-Items-v4\rEnhanced Items v4.7\rOriginal extension by sciencephile with updates by jwguy, llisandur, rmilmine, zarestia, and bmos\rAdds useful fields to various types of items." font="emotefont" />
<announcement text="https://www.fantasygrounds.com/forums/showthread.php?40602-Extension-Enhanced-Items-v4\rEnhanced Items v4.8\rOriginal extension by sciencephile with updates by jwguy, llisandur, rmilmine, zarestia, and bmos\rAdds useful fields to various types of items." font="emotefont" />

<base>
<!-- Strings -->
<includefile source="strings/strings.xml" />

<!-- Scripts -->
<script name="ItemManagerEI" file="scripts/manager_item_EI.lua" />

<!-- Campaign Records -->
<includefile source="campaign/record_item.xml" />
</base>
Expand Down
63 changes: 63 additions & 0 deletions scripts/manager_item_EI.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
--
-- Please see the LICENSE.md file included with this distribution for attribution and copyright information.
--

--
-- Please see the LICENSE.md file included with this distribution for attribution and copyright information.
--

-- luacheck: globals ItemManager.isArmor ItemManager.isShield ItemManager.isWeapon

local contains_old;
local function contains(tList, sItem)
if not tList or not sItem then
return false;
end
for i = 1, #tList do
if sItem:match(tList[i]) then -- replace exact string match with string.match
return true;
end
end
return false;
end

local isArmor_old;
local function isArmor(nodeItem, ...)
contains_old = StringManager.contains;
StringManager.contains = contains;
local bReturn = isArmor_old(nodeItem, ...);
StringManager.contains = contains_old;

return bReturn;
end

local isShield_old;
local function isShield(nodeItem, ...)
contains_old = StringManager.contains;
StringManager.contains = contains;
local bReturn = isShield_old(nodeItem, ...);
StringManager.contains = contains_old;

return bReturn;
end

local isWeapon_old;
local function isWeapon(nodeItem, ...)
contains_old = StringManager.contains;
StringManager.contains = contains;
local bReturn = isWeapon_old(nodeItem, ...);
StringManager.contains = contains_old;

return bReturn;
end

function onInit()
isArmor_old = ItemManager.isArmor
ItemManager.isArmor = isArmor;

isShield_old = ItemManager.isShield
ItemManager.isShield = isShield;

isWeapon_old = ItemManager.isWeapon
ItemManager.isWeapon = isWeapon;
end

0 comments on commit a8400b3

Please sign in to comment.