Skip to content

Commit a5b542e

Browse files
committed
view-item-info: add some null checks around matinfo.decode()
Also remove unused calls
1 parent 78bc99a commit a5b542e

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

Diff for: changelog.txt

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ that repo.
2525
- `emigration`: fix emigrant logic so unhappy dwarves leave as designed
2626
- `gui/gm-unit`: allow ``+`` and ``-`` to adjust skill values as intended instead of letting the filter intercept the characters
2727
- `dwarf-op`: fixed error when applying the Miner job to dwarves
28+
- `view-item-info`: fixed a couple errors when viewing items without materials
2829

2930
## Misc Improvements
3031
- `devel/query`: inform the user when a query has been truncated due to ``--maxlength`` being hit.

Diff for: view-item-info.lua

+8-7
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ function add_lines_to_list(t1,t2)
6767
end
6868

6969
function GetMatPlant (item)
70-
if dfhack.matinfo.decode(item).mode == "plant" then
71-
return dfhack.matinfo.decode(item).plant
70+
local matinfo = dfhack.matinfo.decode(item)
71+
if matinfo and matinfo.mode == "plant" then
72+
return matinfo.plant
7273
end
7374
end
7475

@@ -78,8 +79,12 @@ end
7879

7980
function GetMatPropertiesStringList (item)
8081
local item = item --as:df.item_actual
81-
local mat = dfhack.matinfo.decode(item).material
8282
local list = {}
83+
local matinfo = dfhack.matinfo.decode(item)
84+
if not matinfo then
85+
return list
86+
end
87+
local mat = matinfo.material
8388
local deg_U = item.temperature.whole
8489
local deg_C = math.floor((deg_U-10000)*5/9)
8590
append(list,"Temperature: "..deg_C.."\248C ("..deg_U.."U)")
@@ -123,7 +128,6 @@ end
123128

124129
function GetArmorPropertiesStringList (item)
125130
local item = item --as:df.item_armorst
126-
local mat = dfhack.matinfo.decode(item).material
127131
local list = {}
128132
append(list,"Armor properties: ")
129133
append(list,"Thickness: "..item.subtype.props.layer_size,1)
@@ -137,7 +141,6 @@ end
137141

138142
function GetShieldPropertiesStringList (item)
139143
local item = item --as:df.item_shieldst
140-
local mat = dfhack.matinfo.decode(item).material
141144
local list = {}
142145
append(list,"Shield properties:")
143146
append(list,"Base block chance: "..item.subtype.blockchance,1)
@@ -149,7 +152,6 @@ function GetShieldPropertiesStringList (item)
149152
end
150153

151154
function GetWeaponPropertiesStringList (item)
152-
local mat = dfhack.matinfo.decode(item).material
153155
local list = {}
154156
if item._type == df.item_toolst and #item.subtype.attacks < 1 then --hint:df.item_toolst
155157
return list
@@ -201,7 +203,6 @@ function GetWeaponPropertiesStringList (item)
201203
end
202204

203205
function GetAmmoPropertiesStringList (item)
204-
local mat = dfhack.matinfo.decode(item).material
205206
local list = {}
206207
if item._type == df.item_toolst and #item.subtype.attacks < 1 then --hint:df.item_toolst
207208
return list

0 commit comments

Comments
 (0)