Add a game-agnostic BYOG/edit mode

This commit is contained in:
markmental 2026-11-02 15:28:46 -05:00
commit 58360c1fa7
4 changed files with 1213 additions and 101 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
cards/
seasons/
edit/

View file

@ -35,6 +35,38 @@ retrieval, Tables require a table break, Battle Royals require a last-survivor
win, and Cage matches require escape. Other listed match types use pinfall or
submission. Ranking-based non-title matches are not labeled as contender matches.
### BYOG — Bring Your Own Game
**BYOG / Manage Games** on the main menu lets you run cards and seasons for any
federation, not just the built-in WWF games:
- **Create a new game and federation** — name the game, pick the federation and
platform (PlayStation 1, PlayStation 2, or other), name the federation's
three shows, list the roster, edit the suggested match types, and add any
championship/ranking divisions (singles, tag team, or women's). A women's
division asks which roster members are eligible.
- **Copy a built-in WWF game to edit** — clones any built-in game into your own
editable profile; the built-in games themselves stay unchanged.
- **Edit a custom game** — reopen any saved profile.
Show names are WWE branding, so custom federations name their own three shows
during creation (or later via **Show names** in the BYOG editor). The three
slots match the season cycle — the first weekly show, the second weekly show,
and the big event — and default to neutral placeholders ("Weekly Show #1",
"Weekly Show #2", "Big Pay-Per-View") when left untouched. Booked season cards
and random one-off shows use those names, and an event card titled with the
third slot's name counts as a PPV for title weighting and the event rating.
Profiles are stored under `edit/games/<game id>.json` and are validated on
save/launch; invalid files are skipped with a console message so one typo cannot
break the menu. Every custom game is listed alongside the built-ins whenever a
card or season asks for a game, including its federation name. Custom games on
the PlayStation 1 platform get the DuckStation screenshot prompts. Saved cards
and seasons record the game identity and title divisions they were created with,
so old saves keep working (and keep their own divisions) after you edit a
profile. Bases for custom match types default sensibly; enter an explicit base
rating per match type when you want a different number.
When recording a match result, enter its duration in minutes, near-fall count,
and finishers executed. Match ratings use fixed match-type bases, +0.1 points
per full minute (up to +5), +0.2 per near fall, and +0.5 per finisher. The

File diff suppressed because it is too large Load diff

View file

@ -25,6 +25,11 @@ class RosterTests(unittest.TestCase):
class MarkdownTests(unittest.TestCase):
def make_card(self, path: Path) -> dict:
def profile_fields(match_type: str) -> dict:
definition = app.match_type_definition("sd2", match_type)
return {"base_rating": definition["base_rating"],
"valid_outcomes": list(definition["outcomes"])}
return {
"game_id": "sd2",
"show": 'The "Big" Show',
@ -34,16 +39,18 @@ class MarkdownTests(unittest.TestCase):
{"title": "Opener", "type": "Singles", "sides": [["The Rock"], ["Kane"]],
"winner_side": 0, "finish": "pinfall", "promo": None, "image": "",
"ranking_division": None, "title_defense": False, "rivalry_payoff": False,
"match_time_minutes": None, "near_falls": 0, "finishers": 0, "rating": None},
"match_time_minutes": None, "near_falls": 0, "finishers": 0, "rating": None,
**profile_fields("Singles")},
{"title": "", "type": "Tag Team", "sides": [["Edge", "Christian"],
["The Hardy Boyz", "Tazz"]], "winner_side": None, "finish": "", "promo": None,
"image": "", "ranking_division": None, "title_defense": False,
"rivalry_payoff": False, "match_time_minutes": None, "near_falls": 0,
"finishers": 0, "rating": None},
"finishers": 0, "rating": None, **profile_fields("Tag Team")},
{"title": "", "type": "Triple Threat", "sides": [], "winner_side": None,
"finish": "", "promo": None, "image": "", "ranking_division": None,
"title_defense": False, "rivalry_payoff": False, "match_time_minutes": None,
"near_falls": 0, "finishers": 0, "rating": None},
"near_falls": 0, "finishers": 0, "rating": None,
**profile_fields("Triple Threat")},
],
}
@ -753,6 +760,330 @@ class SeasonModeTests(unittest.TestCase):
self.assertEqual(len(after_second["processed_results"]), 3)
class BYOGTests(unittest.TestCase):
def setUp(self):
self._configs = app.CUSTOM_GAME_CONFIGS
self._games = dict(app.GAMES)
self._match_types = dict(app.MATCH_TYPES)
# Point the BYOG directory at a session-local temp dir so custom
# registrations survive refreshes and never touch the real edit/ folder.
self.game_dir = tempfile.TemporaryDirectory()
self.addCleanup(self.game_dir.cleanup)
patcher = patch.object(app, "CUSTOM_GAME_DIR", Path(self.game_dir.name) / "games")
patcher.start()
self.addCleanup(patcher.stop)
def tearDown(self):
app.CUSTOM_GAME_CONFIGS = self._configs
app.GAMES.clear()
app.GAMES.update(self._games)
app.MATCH_TYPES.clear()
app.MATCH_TYPES.update(self._match_types)
def config(self, **overrides) -> dict:
data = {
"game_id": "custom-fantasy-fed-rumble-royale",
"game_title": "Rumble Royale",
"federation_name": "Fantasy Fed",
"platform": "ps1",
"roster": ["Ava Crusher", "Ben Brawler", "Cara Storm", "Dash Vance"],
"match_types": [
{"name": "Scaffold", "sides": [1, 1], "base_rating": 8.5},
{"name": "Tag Tornado", "sides": [2, 2],
"outcomes": ["pinfall", "submission"]},
],
"championships": [
{"name": "Rumble Belt", "kind": "singles"},
{"name": "Fantasy Tag", "kind": "tag"},
{"name": "Fantasy Women", "kind": "women"},
],
"women_roster": ["Cara Storm"],
}
data.update(overrides)
return data
def register(self, data: dict) -> dict:
saved = app.save_custom_game(data, app.CUSTOM_GAME_DIR)
app.refresh_custom_games()
return saved
def filler_match(self, match_type: str, base_rating: float | None = None) -> dict:
sized = {}
for item in app.match_type_definitions(self.config()["game_id"]):
if item["name"] == match_type:
sized = item
break
return {"title": "", "type": match_type, "sides": [], "winner_side": None,
"finish": "", "promo": None, "image": "", "ranking_division": None,
"title_defense": False, "rivalry_payoff": False,
"match_time_minutes": None, "near_falls": 0, "finishers": 0,
"rating": None,
"base_rating": base_rating if base_rating is not None
else (sized.get("base_rating") if sized else app.base_match_rating(match_type)),
"valid_outcomes": list(sized["outcomes"]) if sized
else list(app.STANDARD_MATCH_OUTCOMES)}
def test_validate_custom_game_accepts_and_normalizes_profiles(self):
saved = app.validate_custom_game(self.config())
self.assertEqual(saved["game_id"], "custom-fantasy-fed-rumble-royale")
self.assertEqual(saved["schema_version"], 1)
self.assertEqual(saved["match_types"][0]["base_rating"], 8.5)
self.assertEqual(saved["match_types"][1]["base_rating"],
app.MATCH_BASE_RATINGS["Tag Team"])
self.assertEqual(saved["match_types"][0]["outcomes"],
list(app.STANDARD_MATCH_OUTCOMES))
self.assertEqual(saved["match_types"][1]["outcomes"], ["pinfall", "submission"])
self.assertEqual(saved["championships"][2]["kind"], "women")
def test_validate_custom_game_rejects_invalid_definitions(self):
rejects = [
({"game_id": "sd1"}, "custom definitions cannot overwrite built-in games"),
({"game_id": "Bad ID"}, "game_id must use lowercase"),
({"roster": ["Ava Crusher", "ava crusher"]}, "unique"),
({"roster": ["Solo"]}, "at least two"),
({"women_roster": ["Not Listed"]}, "subset of the roster"),
({"match_types": [{"name": "Tag Tornado", "sides": [3, 3]}]},
"invalid side sizes"),
({"match_types": []}, "at least one match type"),
({"championships": [{"name": "Belt", "kind": "hardcore"}]}, "kind"),
({"platform": "dreamcast"}, "platform must be ps1"),
]
for overrides, message in rejects:
with self.subTest(overrides=overrides):
data = self.config(**overrides)
with self.assertRaises(ValueError) as caught:
app.validate_custom_game(data)
self.assertIn(message, str(caught.exception).lower())
def test_saved_custom_game_registers_in_catalog(self):
saved = self.register(self.config())
self.assertTrue((app.CUSTOM_GAME_DIR / f"{saved['game_id']}.json").is_file())
game_id = saved["game_id"]
self.assertIn(game_id, app.GAMES)
self.assertIn(game_id, app.CUSTOM_GAME_CONFIGS)
self.assertNotIn(game_id, app.BUILTIN_GAME_IDS)
self.assertEqual(app.load_roster(game_id), saved["roster"])
self.assertEqual(app.game_title(game_id), "Rumble Royale")
self.assertEqual(app.game_display_name(game_id),
"Fantasy Fed — Rumble Royale")
self.assertEqual(app.championship_names_for_game(game_id),
["Rumble Belt", "Fantasy Tag", "Fantasy Women"])
self.assertTrue(app.game_has_screenshots(game_id))
self.assertEqual(app.eligible_roster_for_division(game_id, "Fantasy Women"),
["Cara Storm"])
self.assertEqual([item["name"] for item in app.match_type_definitions(game_id)],
["Scaffold", "Tag Tornado"])
def test_custom_game_survives_relaunch_via_refresh(self):
self.register(self.config())
self.assertEqual(app.refresh_custom_games(),
["custom-fantasy-fed-rumble-royale"])
self.assertEqual(app.refresh_custom_games(),
["custom-fantasy-fed-rumble-royale"])
def test_custom_game_card_round_trip_keeps_game_metadata(self):
game_id = self.config()["game_id"]
self.register(self.config())
with tempfile.TemporaryDirectory() as folder:
path = Path(folder) / "card.md"
card = {
"game_id": game_id, "show": "Rumble Night", "date": "2026-11-02",
"matches": [self.filler_match("Scaffold", base_rating=8.5),
self.filler_match("Tag Tornado"),
self.filler_match("Tag Tornado")],
"path": str(path),
}
app.save_card(card)
loaded = app.load_card(path)
self.assertEqual(loaded["game_title"], "Rumble Royale")
self.assertEqual(loaded["federation_name"], "Fantasy Fed")
self.assertEqual([item["name"] for item in loaded["title_definitions"]],
["Rumble Belt", "Fantasy Tag", "Fantasy Women"])
self.assertEqual(loaded["matches"][0]["type"], "Scaffold")
self.assertEqual(loaded["matches"][0]["base_rating"], 8.5)
self.assertEqual(loaded["matches"][1]["valid_outcomes"], ["pinfall", "submission"])
def test_custom_match_base_rating_can_drive_the_match_rating(self):
match = {"type": "Scaffold", "base_rating": 8.5, "match_time_minutes": 12.9,
"near_falls": 2, "finishers": 3, "title_defense": False}
plain = dict(match, base_rating=None)
self.assertEqual(app.calculate_match_rating(match) - app.calculate_match_rating(plain),
8.5 - app.base_match_rating("Scaffold"))
def test_custom_game_season_uses_custom_title_divisions(self):
config = self.config()
game_id = config["game_id"]
self.register(config)
season = app.new_season_state("Fantasy Season", game_id,
champions={"Rumble Belt": ["Ava Crusher"],
"Fantasy Tag": ["Ben Brawler", "Dash Vance"]},
season_id="fantasy-season")
self.assertEqual([item["name"] for item in season["title_definitions"]],
["Rumble Belt", "Fantasy Tag", "Fantasy Women"])
self.assertEqual(set(season["rankings"]),
{"Rumble Belt", "Fantasy Tag", "Fantasy Women"})
self.assertEqual(season["champions"]["Rumble Belt"]["holder"], ["Ava Crusher"])
with contextlib.redirect_stdout(io.StringIO()):
roster = app.load_roster(game_id)
matches = app.build_season_matches(season, "Raw")
self.assertEqual(len(matches), 3)
for match in matches:
self.assertIn(match["ranking_division"], (None, "Rumble Belt", "Fantasy Tag",
"Fantasy Women"))
# A custom division result updates the custom rankings.
match = {"type": "Scaffold", "sides": [["Ava Crusher"], ["Ben Brawler"]],
"winner_side": 0, "ranking_division": "Rumble Belt",
"title_defense": False}
app.record_season_match(season, {"season_show": "Raw"}, match, 0)
table = season["rankings"]["Rumble Belt"]
self.assertEqual(table[app.side_identity(["Ava Crusher"])]["wins"], 1)
self.assertEqual(table[app.side_identity(["Ben Brawler"])]["losses"], 1)
# A successful defense keeps the custom champion on top.
defense = {"type": "Scaffold", "sides": [["Ava Crusher"], ["Cara Storm"]],
"winner_side": 0, "ranking_division": "Rumble Belt",
"title_defense": True}
app.record_season_match(season, {"season_show": "Raw"}, defense, 0)
self.assertEqual(season["champions"]["Rumble Belt"]["holder"], ["Ava Crusher"])
self.assertEqual(season["champions"]["Rumble Belt"]["successful_defenses"], 1)
def test_custom_season_save_round_trip_keeps_title_definitions(self):
self.register(self.config())
season = app.new_season_state("Fantasy Season", self.config()["game_id"],
champions={"Rumble Belt": ["Ava Crusher"]},
season_id="fantasy-save")
with tempfile.TemporaryDirectory() as folder:
with patch.object(app, "SEASON_DIR", Path(folder)):
app.save_season(season)
loaded = app.load_season(season["season_id"])
self.assertEqual(loaded["game_title"], "Rumble Royale")
self.assertEqual(loaded["federation_name"], "Fantasy Fed")
self.assertEqual(loaded["champions"]["Rumble Belt"]["holder"], ["Ava Crusher"])
self.assertEqual([item["name"] for item in loaded["title_definitions"]],
["Rumble Belt", "Fantasy Tag", "Fantasy Women"])
self.assertEqual(loaded["shows"], app.DEFAULT_CUSTOM_SHOWS)
def test_choose_game_lists_builtin_games_then_custom_games(self):
self.register(self.config())
with contextlib.redirect_stdout(io.StringIO()), \
patch.object(app, "ask_choice", return_value=len(app.GAMES) - 1):
self.assertEqual(app.choose_game(), self.config()["game_id"])
CUSTOM_SHOWS = {"Raw": "Fantasy Rampage", "SmackDown": "Fantasy Clash",
"PPV": "Fantasy Super Card"}
def test_shows_validation_accepts_normalizes_and_rejects_bad_values(self):
saved = app.validate_custom_game(self.config(shows=self.CUSTOM_SHOWS))
self.assertEqual(saved["shows"], self.CUSTOM_SHOWS)
# Absent shows fall back to neutral placeholders, never WWE names.
self.assertEqual(app.validate_custom_game(self.config())["shows"],
app.DEFAULT_CUSTOM_SHOWS)
rejects = [
({"shows": ["Fantasy Rampage"]}, "shows must be an object"),
({"shows": {"Raw": " "}}, "non-empty string"),
({"shows": self.CUSTOM_SHOWS | {"Raw": "fantasy clash"}}, "unique"),
({"shows": {"Raw": 3}}, "non-empty string"),
]
for overrides, message in rejects:
with self.subTest(overrides=overrides):
data = self.config(**overrides)
with self.assertRaises(ValueError) as caught:
app.validate_custom_game(data)
self.assertIn(message, str(caught.exception).lower())
def test_game_show_names_resolve_wwe_names_only_for_builtins(self):
self.assertEqual(app.game_show_names("sd1")["SmackDown"],
"Thursday Night SmackDown!")
self.register(self.config())
self.assertEqual(app.game_show_names(self.config()["game_id"]),
app.DEFAULT_CUSTOM_SHOWS)
self.register(self.config(shows=self.CUSTOM_SHOWS))
game_id = self.config()["game_id"]
self.assertEqual(app.game_show_names(game_id), self.CUSTOM_SHOWS)
def test_built_in_clone_prefills_wwe_show_names(self):
profile = app.builtin_game_profile("sd2")
self.assertEqual(profile["shows"]["Raw"], "Monday Night Raw")
copied = app.builtin_profile_for_copy("sd2", "custom-clone-test")
self.assertEqual(copied["shows"], {"Raw": "Monday Night Raw",
"SmackDown": "Thursday Night SmackDown!",
"PPV": "WWF PPV"})
def test_booked_season_cards_use_custom_show_names(self):
game_id = self.register(self.config(shows=self.CUSTOM_SHOWS))["game_id"]
season = app.new_season_state("Show Name Season", game_id, champions={},
season_id="showname-season")
self.assertEqual(season["shows"], self.CUSTOM_SHOWS)
with tempfile.TemporaryDirectory() as folder, \
patch.object(app, "SEASON_DIR", Path(folder) / "seasons"), \
patch.object(app, "CARD_DIR", Path(folder) / "cards"), \
contextlib.redirect_stdout(io.StringIO()):
names = []
for show_number in (1, 2, 3):
season["next_show_number"] = show_number
card = app.book_next_season_show(season)
names.append(card["show"])
season["current_card"] = ""
card["matches"][0]["winner_side"] = 0
season_path = app.season_path(season["season_id"])
# The season save keeps its custom show-name snapshot on disk.
saved = json.loads(season_path.read_text("utf-8"))
self.assertEqual(saved["shows"], self.CUSTOM_SHOWS)
self.assertEqual(names, ["Fantasy Rampage", "Fantasy Clash", "Fantasy Super Card"])
def test_is_ppv_card_matches_custom_ppv_show_name_exactly(self):
self.register(self.config(shows=self.CUSTOM_SHOWS))
game_id = self.config()["game_id"]
event_card = {"game_id": game_id, "show": "Fantasy Super Card"}
weekly_card = {"game_id": game_id, "show": "Fantasy Rampage"}
self.assertTrue(app.is_ppv_card(event_card))
self.assertFalse(app.is_ppv_card(weekly_card))
# Case-insensitive exact match still applies.
self.assertTrue(app.is_ppv_card({"game_id": game_id, "show": "fantasy super card"}))
# Unknown card shows stay non-PPV even with a custom game.
self.assertFalse(app.is_ppv_card({"game_id": game_id, "show": "House Party"}))
def test_one_off_cards_use_game_show_names(self):
game_id = self.register(self.config(shows=self.CUSTOM_SHOWS))["game_id"]
with tempfile.TemporaryDirectory() as folder, \
patch.object(app, "CARD_DIR", Path(folder) / "cards"), \
contextlib.redirect_stdout(io.StringIO()):
with patch.object(app, "choose_game", return_value=game_id):
card = app.create_random_card()
self.assertIn(card["show"], set(self.CUSTOM_SHOWS.values()))
# The create-a-card show prompt defaults to the second weekly slot.
captured = {}
class Stop(Exception):
pass
def fake_ask(prompt, default=None):
captured["default"] = default
raise Stop()
with patch.object(app, "choose_game", return_value=game_id), \
patch.object(app, "ask", fake_ask), \
self.assertRaises(Stop):
app.create_card()
self.assertEqual(captured["default"], "Fantasy Clash")
def test_edit_custom_shows_renames_and_rejects_duplicates(self):
config = {"shows": dict(self.CUSTOM_SHOWS)}
with contextlib.redirect_stdout(io.StringIO()), \
patch.object(app, "ask_choice", side_effect=[0, 3]), \
patch.object(app, "ask", return_value="Fantasy Festival"):
app.edit_custom_shows(config)
self.assertEqual(config["shows"]["Raw"], "Fantasy Festival")
config = {"shows": dict(self.CUSTOM_SHOWS)}
with contextlib.redirect_stdout(io.StringIO()), \
patch.object(app, "ask_choice", side_effect=[1, 3]), \
patch.object(app, "ask", side_effect=["Fantasy Rampage", "Fantasy Zoom"]):
app.edit_custom_shows(config)
self.assertEqual(config["shows"]["SmackDown"], "Fantasy Zoom")
class FlashRenderingTests(unittest.TestCase):
def test_flash_updates_only_changed_rows_not_static_header(self):
card = MarkdownTests().make_card(Path("card.md"))