P1 iron: nuggets, ore, clay, kiln, smelter, forge, iron tools and arrows, lantern, tool wear and repair
This commit is contained in:
@@ -31,10 +31,27 @@ static func _stack_max(id: String) -> int:
|
||||
var db := (Engine.get_main_loop() as SceneTree).root.get_node_or_null("ItemDB")
|
||||
return db.stack_size(id) if db != null else 50
|
||||
|
||||
## A stack can carry "dur": uses left on a tool or weapon that wears out
|
||||
## (ItemDB "durability"). No "dur" means as new.
|
||||
static func _norm(stack):
|
||||
if stack == null or int(stack.count) <= 0:
|
||||
return null
|
||||
return {"id": String(stack.id), "count": int(stack.count)}
|
||||
var out := {"id": String(stack.id), "count": int(stack.count)}
|
||||
if stack.has("dur"):
|
||||
out.dur = int(stack.dur)
|
||||
return out
|
||||
|
||||
## Adds a whole stack, keeping what's special about it (a worn tool's "dur").
|
||||
## Returns how many didn't fit.
|
||||
func add_stack(stack: Dictionary) -> int:
|
||||
if not stack.has("dur"):
|
||||
return add(String(stack.id), int(stack.count))
|
||||
for i in range(slots.size()):
|
||||
if slots[i] == null:
|
||||
slots[i] = _norm(stack)
|
||||
changed.emit()
|
||||
return 0
|
||||
return int(stack.count)
|
||||
|
||||
func count(id: String) -> int:
|
||||
var n := 0
|
||||
@@ -117,8 +134,8 @@ func quick_move(i: int, other: Inventory) -> void:
|
||||
var s = slots[i]
|
||||
if s == null:
|
||||
return
|
||||
var left := other.add(s.id, s.count)
|
||||
slots[i] = null if left <= 0 else {"id": s.id, "count": left}
|
||||
var left := other.add_stack(s)
|
||||
slots[i] = null if left <= 0 else _norm({"id": s.id, "count": left, "dur": s.dur} if s.has("dur") else {"id": s.id, "count": left})
|
||||
changed.emit()
|
||||
|
||||
## Clicking slot `i` while holding `cursor` (a stack or null). Returns the new
|
||||
@@ -138,7 +155,7 @@ func click(i: int, cursor, right: bool):
|
||||
result = s
|
||||
slots[i] = null
|
||||
elif s == null:
|
||||
if right:
|
||||
if right and cursor.count > 1:
|
||||
slots[i] = {"id": cursor.id, "count": 1}
|
||||
result = _norm({"id": cursor.id, "count": cursor.count - 1})
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user