class_name CardThreads extends RefCounted ## Card threads: threads that leave a card from its bottom edge rather than ## from one result (LOGIC.md ยง3g). They live on the card's outlet ## (RollTable.outlet), a TableEntry that is never rolled, so every thread ## option (count, Only if, save as, dice, rerolls, inputs, pause) works the ## same way as on a result's thread. ## ## When the card has given its result and that result's own threads have run ## (their whole chains), the card threads run, in order: ## - a plain card thread always runs ("Always"); ## - an "Otherwise" card thread runs only if no thread of the result ran and ## no conditional card thread was true; ## - a card thread with Only if runs when its condition is true, worked out ## at that moment (after the result's chains). ## A loop card's threads run once, after its Afterwards row. ## True when card `t` has card threads to follow after `node` (a chosen row). static func follows(t: RollTable, node: Dictionary) -> bool: return t != null and not t.outlet.pipes.is_empty() and not node.has("pass") ## True when the pipe key belongs to a card thread. static func is_card_key(key: String) -> bool: return key.contains(":" + RollTable.OUTLET_ID + ">") ## Runs the card threads of frame["node"]'s card (a Roller.OP_CARD frame, ## popped once the result's own threads are done). static func run(frame: Dictionary, ctx: RollContext, stack: Array) -> void: var node: Dictionary = frame["node"] var t: RollTable = node["table"] var log: Array = [] var why: Array = [] var plan := RollPipes.pipe_plan(t.outlet, ctx, log, why, bool(frame.get("ran", false))) for fact: Dictionary in why: fact["card"] = true Roller._log(node, log) Roller._why(node, why) RollPipes.push_plan(node, t.outlet, plan, stack, int(frame["depth"]), true)