120 lines
5.2 KiB
GDScript3
120 lines
5.2 KiB
GDScript3
|
|
class_name DemoSpreads
|
||
|
|
extends RefCounted
|
||
|
|
## Small example spreads, one per feature, opened from Help ("Try a demo").
|
||
|
|
## They're built here, opened unsaved, and never listed with the user's
|
||
|
|
## spreads. Each is a spread dictionary (the file format) kept tiny.
|
||
|
|
|
||
|
|
const TITLES := {
|
||
|
|
"threads": "Demo: threads",
|
||
|
|
"deck": "Demo: Deck mode",
|
||
|
|
"repeats": "Demo: rolling more than once",
|
||
|
|
"pause": "Demo: pausing a roll",
|
||
|
|
"costs": "Demo: options that cost",
|
||
|
|
"limits": "Demo: one table adjusting another",
|
||
|
|
"book": "Demo: the Book",
|
||
|
|
"groups": "Demo: groups inside groups",
|
||
|
|
"sheet": "Demo: a sheet",
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
static func has(key: String) -> bool:
|
||
|
|
return TITLES.has(key)
|
||
|
|
|
||
|
|
|
||
|
|
static func build(key: String) -> TowerBoard:
|
||
|
|
var d: Dictionary = _spec(key)
|
||
|
|
d["format_version"] = TowerBoard.FORMAT_VERSION
|
||
|
|
d["id"] = "demo-" + key
|
||
|
|
d["name"] = TITLES.get(key, "Demo")
|
||
|
|
var b := TowerBoard.new()
|
||
|
|
b.load_dict(d)
|
||
|
|
for p in b.book:
|
||
|
|
b.sync_page(p.id)
|
||
|
|
return b
|
||
|
|
|
||
|
|
|
||
|
|
static func _t(id: String, name: String, x: int, y: int, entries: Array, extra: Dictionary = {}) -> Dictionary:
|
||
|
|
var list: Array = []
|
||
|
|
for i in entries.size():
|
||
|
|
var e: Variant = entries[i]
|
||
|
|
list.append(e if e is Dictionary else {"id": "e%d" % i, "text": str(e)})
|
||
|
|
var t := {"id": id, "name": name, "x": x, "y": y, "entries": list}
|
||
|
|
t.merge(extra, true)
|
||
|
|
return t
|
||
|
|
|
||
|
|
|
||
|
|
static func _e(id: String, text: String, extra: Dictionary = {}) -> Dictionary:
|
||
|
|
var e := {"id": id, "text": text}
|
||
|
|
e.merge(extra, true)
|
||
|
|
return e
|
||
|
|
|
||
|
|
|
||
|
|
static func _spec(key: String) -> Dictionary:
|
||
|
|
match key:
|
||
|
|
"threads":
|
||
|
|
return {"tables": [
|
||
|
|
_t("weather", "Weather", 40, 60, [_e("w1", "Clear skies", {"pipes": ["event"]}), _e("w2", "Storm", {"pipes": ["event", "shelter"]})]),
|
||
|
|
_t("event", "Event", 380, 40, ["A traveller waves", "Tracks in the mud", "A lost coin"]),
|
||
|
|
_t("shelter", "Shelter", 380, 300, ["A cave", "An old barn"]),
|
||
|
|
]}
|
||
|
|
"deck":
|
||
|
|
return {"tables": [_t("roles", "Party roles", 40, 60, ["Scout", "Cook", "Map keeper", "Lookout"],
|
||
|
|
{"card_mode": true, "deck_empty": "stop", "deck_empty_text": "Everyone has a role"})]}
|
||
|
|
"repeats":
|
||
|
|
return {"tables": [
|
||
|
|
_t("chest", "Open the chest", 40, 60, [
|
||
|
|
_e("c1", "Coins (add three rolls)", {"pipes": [{"table": "coins", "count": 3, "combine": "sum"}]}),
|
||
|
|
_e("c2", "Best of two gems", {"pipes": [{"table": "gems", "count": 2, "combine": "max"}]}),
|
||
|
|
_e("c3", "Pick one of three trinkets", {"pipes": [{"table": "trinket", "count": 3, "combine": "choose"}]})]),
|
||
|
|
_t("coins", "Coins", 440, 0, ["10", "20", "30", "40", "50", "60"]),
|
||
|
|
_t("gems", "Gems", 440, 360, ["1", "2", "3", "4", "5", "6"], {"dice": "1d6"}),
|
||
|
|
_t("trinket", "Trinket", 440, 720, ["A bent key", "A glass eye", "A tiny bell", "A pressed flower"]),
|
||
|
|
]}
|
||
|
|
"pause":
|
||
|
|
return {"tables": [
|
||
|
|
_t("door", "The old door", 40, 60, [_e("d1", "It creaks open…", {"pipes": [{"table": "inside", "pause": true}]})]),
|
||
|
|
_t("inside", "Inside", 420, 60, ["A dusty library", "A sleeping dragon", "An empty room"]),
|
||
|
|
]}
|
||
|
|
"costs":
|
||
|
|
return {"tables": [
|
||
|
|
_t("pts", "Points", 40, 40, [_e("v", "")], {"kind": "variable", "var_name": "points", "initial": "2"}),
|
||
|
|
_t("loot", "Find loot", 40, 260, ["A rusty sword", "A torn map", "A copper ring"], {"dice": "1d3"}),
|
||
|
|
_t("again", "Happy with it?", 420, 260, [
|
||
|
|
_e("k", "Keep it"),
|
||
|
|
_e("r", "Reroll the loot", {"cost": {"value": "@points", "amount": "1"}, "pipes": ["loot"]})],
|
||
|
|
{"kind": "choice", "choice": "pick", "prompt": "Spend a point to reroll?"}),
|
||
|
|
]}
|
||
|
|
"limits":
|
||
|
|
return {"tables": [
|
||
|
|
_t("feature", "Planet feature", 40, 60, [
|
||
|
|
_e("f1", "Thick haze (atmosphere at least 7)", {"effects": "@atmo_min = 7", "pipes": ["atmo"]}),
|
||
|
|
_e("f2", "Nothing special", {"effects": "@atmo_min = 2", "pipes": ["atmo"]})]),
|
||
|
|
_t("atmo", "Atmosphere", 440, 40, [
|
||
|
|
_e("a1", "Thin", {"range": [2, 6]}), _e("a2", "Standard", {"range": [7, 9]}), _e("a3", "Dense", {"range": [10, 12]})],
|
||
|
|
{"dice": "2d6", "roll_floor": "@atmo_min"}),
|
||
|
|
]}
|
||
|
|
"book":
|
||
|
|
return {"book": [{"id": "p_sword", "name": "Sword of Holy Light",
|
||
|
|
"text": "[b][color=#c99a1c]The Sword of Holy Light[/color][/b]", "details": "Glows near the undead.", "tags": ["weapon"]}],
|
||
|
|
"tables": [
|
||
|
|
_t("goblin", "Goblin loot", 40, 60, ["A bent spoon", _e("s", "", {"page": "p_sword"})]),
|
||
|
|
_t("dragon", "Dragon hoard", 420, 60, ["A mountain of coins", _e("s", "", {"page": "p_sword"})]),
|
||
|
|
]}
|
||
|
|
"groups":
|
||
|
|
return {"groups": [
|
||
|
|
{"id": "g_world", "name": "World", "x": 20, "y": 0, "w": 800, "h": 520, "members": ["region"]},
|
||
|
|
{"id": "g_town", "name": "Town", "x": 60, "y": 230, "w": 700, "h": 260, "members": ["shop", "inn"], "parent": "g_world"}],
|
||
|
|
"tables": [
|
||
|
|
_t("region", "Region", 60, 70, ["Hills", "Coast", "Forest"]),
|
||
|
|
_t("shop", "Shop", 100, 300, ["Bakery", "Smithy"]),
|
||
|
|
_t("inn", "Inn", 420, 300, ["The Grey Goose", "The Lantern"]),
|
||
|
|
]}
|
||
|
|
"sheet":
|
||
|
|
return {"tables": [
|
||
|
|
_t("hero", "New hero", 40, 60, [_e("h", "Roll a hero", {"pipes": [{"table": "name", "save_as": "@name"}, {"table": "job", "save_as": "@job"}, "sheet"]})]),
|
||
|
|
_t("name", "Name", 400, 20, ["Ash", "Briar", "Corin", "Dana"]),
|
||
|
|
_t("job", "Job", 400, 240, ["Baker", "Guard", "Thief", "Bard"]),
|
||
|
|
_t("sheet", "Hero sheet", 760, 60, [_e("s", "[b]Name:[/b] {@name}\n[b]Job:[/b] {@job}")], {"kind": "sheet"}),
|
||
|
|
]}
|
||
|
|
return {"tables": []}
|