Each scarecrow carries its own pouch (ResourceStore.pouches by avatar slot; slot 0 is the solo player / host, `pouch` stays slot 0's), with one shared pouch_capacity so a Bigger pouch grows both. The shed stays shared. - Gathering, the shed drop-off, repair, upgrade-in-place, patching, building and buying all act on the acting avatar's slot. The host pays the partner's "place" and "buy" requests from P2's pouch and the shed. - The partner's build mode, build hotbar, shop menus and materials HUD check affordability against P2's pouch (FarmSim.set_local). - Alien Goop goes to the killer's pouch: FarmSim sets EnemySystem.attacker around each avatar's combat step and shots carry their shooter's slot; bomb/turret kills go to the nearest scarecrow. The replica no longer rolls goop locally. - When the partner leaves, their pouch goes into the shed (and is named in the toast); a co-op save continued alone banks P2's pouch at morning. - FarmState.VERSION 7 (resources.partner_pouch) with a v6 migration; CoopSession.PROTOCOL 4. - Tests: per-slot store rules, v6 save migration, and test_coop cases for separate gathering, no cross-banking in the shed, own-pouch paying, shared capacity, goop credit and leaving. test_coop's crowd case now resets the loopback's drop counter so earlier traffic can't change which messages it loses. - Docs: COOP.md and RULES.md no longer say the pouch is shared. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
79 lines
2.4 KiB
GDScript
79 lines
2.4 KiB
GDScript
class_name ResourceHud
|
|
extends Control
|
|
## Top-right materials readout: what the supply shed holds, and what this machine's scarecrow
|
|
## carries in its own pouch (with its capacity). A line flashes when its numbers change.
|
|
|
|
var campaign: CampaignController
|
|
## The avatar slot whose pouch is shown (FarmSim.set_local: the partner's machine shows P2's).
|
|
var slot: int = 0
|
|
|
|
## Set by FarmSim: shows how many structures stand.
|
|
var structures: StructureSystem
|
|
|
|
var _shed: RichTextLabel
|
|
var _pouch: RichTextLabel
|
|
var _built: RichTextLabel
|
|
var _last_shed := ""
|
|
var _last_pouch := ""
|
|
var _flash_shed: float = 0.0
|
|
var _flash_pouch: float = 0.0
|
|
|
|
|
|
func setup(p_campaign: CampaignController) -> void:
|
|
campaign = p_campaign
|
|
|
|
|
|
func _ready() -> void:
|
|
set_anchors_preset(Control.PRESET_FULL_RECT)
|
|
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
_shed = _line(20.0)
|
|
_pouch = _line(52.0)
|
|
_built = _line(84.0)
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
if campaign == null:
|
|
return
|
|
var r := campaign.state.resources
|
|
var shed := "Shed %s" % _amounts(r.shed)
|
|
var total := r.pouch_total(slot)
|
|
var pouch := "Pouch %d/%d %s" % [total, r.pouch_capacity, _amounts(r.pouch_of(slot)) if total > 0 else "empty"]
|
|
if shed != _last_shed:
|
|
_last_shed = shed
|
|
_shed.text = shed
|
|
_flash_shed = 1.0
|
|
if pouch != _last_pouch:
|
|
_last_pouch = pouch
|
|
_pouch.text = pouch
|
|
_flash_pouch = 1.0
|
|
_flash_shed = maxf(_flash_shed - delta * 2.0, 0.0)
|
|
_flash_pouch = maxf(_flash_pouch - delta * 2.0, 0.0)
|
|
if structures != null:
|
|
_built.text = "Built %d structures [B] build" % structures.count()
|
|
_shed.modulate = Color.WHITE.lerp(Color(1.0, 1.0, 0.55), _flash_shed)
|
|
_pouch.modulate = Color.WHITE.lerp(Color(1.0, 1.0, 0.55), _flash_pouch)
|
|
|
|
|
|
func _amounts(d: Dictionary) -> String:
|
|
var parts: Array[String] = []
|
|
for m in ResourceStore.MATERIALS:
|
|
parts.append("[color=#%s]%s %d[/color]" % [GatherNode.COLORS[m].to_html(false), m.capitalize(), int(d.get(m, 0))])
|
|
return " ".join(parts)
|
|
|
|
|
|
func _line(y: float) -> RichTextLabel:
|
|
var l := RichTextLabel.new()
|
|
l.bbcode_enabled = true
|
|
l.fit_content = true
|
|
l.scroll_active = false
|
|
l.autowrap_mode = TextServer.AUTOWRAP_OFF
|
|
l.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
l.add_theme_font_size_override("normal_font_size", 22)
|
|
l.add_theme_color_override("font_outline_color", Color.BLACK)
|
|
l.add_theme_constant_override("outline_size", 6)
|
|
l.set_anchors_preset(Control.PRESET_TOP_RIGHT)
|
|
l.offset_left = -520.0
|
|
l.offset_right = -24.0
|
|
l.offset_top = y
|
|
add_child(l)
|
|
return l
|