diff --git a/.gdlintrc b/.gdlintrc new file mode 100644 index 0000000..eb36424 --- /dev/null +++ b/.gdlintrc @@ -0,0 +1,17 @@ +# Project GDScript lint configuration. +# +# Kept deliberately permissive on the four style rules the existing codebase does not follow, +# while every structural/naming rule stays at the defaults (and is enforced in CI). The two +# `class-definitions-order` violations that existed were fixed in code rather than relaxed here. +# +# max-line-length translation strings in src/core/l10n.gd are long literals and cannot be +# wrapped; 140 covers them. +# max-public-methods HUD is a UI class with many small accessors/handlers. +# max-file-lines game_screen.gd legitimately holds the whole in-game screen. +# unused-argument two internal callbacks take a parameter they intentionally ignore; +# disabled via the `disable` list below (see gdlint's config semantics). +max-line-length: 140 +max-public-methods: 30 +max-file-lines: 1200 +disable: + - unused-argument diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a36a374..51729b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,9 @@ jobs: - name: Level smoke test run: '"$GODOT_BIN" --headless --path . res://tests/smoke_level.tscn' + - name: UI screen tests + run: '"$GODOT_BIN" --headless --path . res://tests/test_screens.tscn' + - name: Balance regression (autoplay) run: | set -euo pipefail @@ -59,6 +62,14 @@ jobs: "$GODOT_BIN" --headless --fixed-fps 480 --path . res://tests/autoplay.tscn -- --difficulty="$d" done + - name: GDScript lint + run: | + python3 -m pip install --quiet --disable-pip-version-check gdtoolkit==4.5.0 + gdlint $(find src -name '*.gd') + + - name: Version consistency check + run: python3 tools/check_version.py + export: name: Export (${{ matrix.preset }}) needs: tests @@ -240,6 +251,21 @@ jobs: permissions: contents: write steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.ref }} + - name: Verify version bump + run: | + set -euo pipefail + git fetch --tags --force + current="${GITHUB_REF_NAME}" + prev="$(git tag --sort=-creatordate | grep -v -x "$current" | head -1 || true)" + if [ -n "$prev" ]; then + python3 tools/check_version.py --prev "$prev" + else + echo "check_version: no previous release tag found; skipping bump check." + fi - uses: actions/download-artifact@v4 with: path: artifacts diff --git a/export_presets.cfg b/export_presets.cfg index 3416258..c28efde 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -33,8 +33,8 @@ architectures/armeabi-v7a=false architectures/arm64-v8a=true architectures/x86=false architectures/x86_64=false -version/code=4 -version/name="1.1.4" +version/code=5 +version/name="1.1.5" package/unique_name="org.bulwark.game" package/name="Bulwark" package/signed=true diff --git a/project.godot b/project.godot index aae7d7a..0985a44 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 config/name="Bulwark" config/description="A minimalist tower defense. Hold the line." -config/version="1.1.4" +config/version="1.1.5" run/main_scene="res://scenes/main_menu.tscn" config/features=PackedStringArray("4.7", "GL Compatibility") config/icon="res://assets/icons/icon.png" diff --git a/src/core/save_store.gd b/src/core/save_store.gd index efdd637..b0b931b 100644 --- a/src/core/save_store.gd +++ b/src/core/save_store.gd @@ -12,6 +12,9 @@ const DEFAULT_PATH := "user://bulwark_save.json" var path: String +## Explains the most recent load/save problem ("" when everything went fine). +var last_error: String = "" + func _init(p_path: String = DEFAULT_PATH) -> void: path = p_path @@ -21,10 +24,6 @@ func backup_path() -> String: return path + ".bak" -## Explains the most recent load/save problem ("" when everything went fine). -var last_error: String = "" - - ## Loads the save file, returning a `{version, settings, progress}` dictionary. ## Never throws: on any problem the defaults are returned and `last_error` explains why. func load_data() -> Dictionary: diff --git a/src/game/board.gd b/src/game/board.gd index 292f531..e835399 100644 --- a/src/game/board.gd +++ b/src/game/board.gd @@ -12,6 +12,7 @@ const FRAME := 10.0 var grid: BuildGrid var level: Dictionary = {} var ground_path: PathModel +var show_grid := true var _props: Dictionary = {} ## prop name -> Texture2D var _hover_cell := Vector2i(-1, -1) @@ -21,7 +22,6 @@ var _hover_origin := Vector2.ZERO var _ability_preview: Dictionary = {} var _preview_tower := "" ## tower id being placed (ghost icon) var _ghost_texture: Texture2D -var show_grid := true func setup(p_grid: BuildGrid, p_level: Dictionary, p_path: PathModel) -> void: diff --git a/tests/test_screens.gd b/tests/test_screens.gd new file mode 100644 index 0000000..f17b340 --- /dev/null +++ b/tests/test_screens.gd @@ -0,0 +1,74 @@ +extends Node +## Headless UI-screen regression test. +## +## Run with: godot --headless --path . res://tests/test_screens.tscn +## Exit code 0 when every screen builds, 1 otherwise (CI friendly). +## +## This guards the bug class that the core unit tests cannot see: a screen whose `_build()` is +## skipped (a parse error, a missing API, a bad layout call) renders EMPTY at runtime while the +## engine-free core layer still passes. Instantiating the real scenes here turns "the window is +## blank" into a hard CI failure instead of a player-reported regression. + +const MIN_DESCENDANTS := 10 + +const SCREENS: Array[Dictionary] = [ + {"name": "MainMenu", "scene": "res://scenes/main_menu.tscn", "min": 10}, + {"name": "SettingsScreen", "scene": "res://scenes/settings_screen.tscn", "min": 30}, + {"name": "LevelSelectScreen", "scene": "res://scenes/level_select.tscn", "min": 30}, + {"name": "CreditsScreen", "scene": "res://scenes/credits_screen.tscn", "min": 10}, +] + +var _passed := 0 +var _failed := 0 + + +func _ready() -> void: + print("\n=== Bulwark UI screen tests ===") + for entry in SCREENS: + await _test_screen(String(entry["name"]), String(entry["scene"]), int(entry["min"])) + print("\n%d passed, %d failed" % [_passed, _failed]) + get_tree().quit(1 if _failed > 0 else 0) + + +func _test_screen(name: String, scene_path: String, min_descendants: int) -> void: + var scene: PackedScene = load(scene_path) + _check(scene != null, "%s: scene loads" % name) + if scene == null: + return + + var screen = scene.instantiate() as Node + _check(screen != null, "%s: instantiates" % name) + if screen == null: + return + + add_child(screen) + # Let _ready / _build (and any open animation setup) run before counting. + await _frames(6) + + var count := _count_descendants(screen) + _check(count >= min_descendants, + "%s: builds content (%d descendants, need >= %d)" % [name, count, min_descendants]) + + remove_child(screen) + screen.queue_free() + + +func _count_descendants(node: Node) -> int: + var total := node.get_child_count() + for i in range(node.get_child_count()): + total += _count_descendants(node.get_child(i)) + return total + + +func _frames(count: int) -> void: + for _i in range(count): + await get_tree().process_frame + + +func _check(condition: bool, message: String) -> void: + if condition: + _passed += 1 + print(" [ok] %s" % message) + else: + _failed += 1 + printerr(" [FAIL] %s" % message) diff --git a/tests/test_screens.gd.uid b/tests/test_screens.gd.uid new file mode 100644 index 0000000..5efcaea --- /dev/null +++ b/tests/test_screens.gd.uid @@ -0,0 +1 @@ +uid://kkhg467rqwpp diff --git a/tests/test_screens.tscn b/tests/test_screens.tscn new file mode 100644 index 0000000..5ba209b --- /dev/null +++ b/tests/test_screens.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3] + +[ext_resource type="Script" path="res://tests/test_screens.gd" id="1_screens"] + +[node name="TestScreens" type="Node"] +script = ExtResource("1_screens") diff --git a/tools/check_version.py b/tools/check_version.py new file mode 100644 index 0000000..03af845 --- /dev/null +++ b/tools/check_version.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python3 +"""Guards the release version so a stale Android `version/code` can never ship again. + +Background: v1.1.1 shipped with `version/code=1`, identical to v1.0.0, so the APK could not +install over the previous build. Every release must strictly increase the numeric code. + +Two modes: + * consistency (default) — `project.godot`'s `config/version` matches `export_presets.cfg`'s + `version/name`, and `version/code` is a positive integer. + * bump check (`--prev `) — additionally asserts the current `version/code` is strictly + greater than the `version/code` at the given previous tag (fetched from git). + +Exit code 0 on success, 1 on any failure (CI friendly). +""" + +import argparse +import re +import subprocess +import sys +from pathlib import Path + +ROOT = Path(__file__).resolve().parent.parent +PRESETS = ROOT / "export_presets.cfg" +PROJECT = ROOT / "project.godot" + + +def read_text(path: Path) -> str: + return path.read_text(encoding="utf-8", errors="replace") + + +def parse_presets(text: str) -> dict: + """Parse the small subset of Godot export-preset keys this project uses.""" + values = {} + for line in text.splitlines(): + stripped = line.strip() + if not stripped or stripped.startswith("#") or stripped.startswith(";"): + continue + if "=" not in stripped: + continue + key, _, value = stripped.partition("=") + value = value.strip() + if len(value) >= 2 and value[0] == '"' and value[-1] == '"': + value = value[1:-1] + values[key.strip()] = value + return values + + +def parse_project_version(text: str): + """Return the value of `config/version="..."` from project.godot, or None.""" + match = re.search(r'^\s*config/version\s*=\s*"([^"]*)"', text, re.MULTILINE) + return match.group(1) if match else None + + +def current_values(): + presets = parse_presets(read_text(PRESETS)) + name = presets.get("version/name", "") + code_raw = presets.get("version/code", "") + project_version = parse_project_version(read_text(PROJECT)) + return name, code_raw, project_version + + +def code_at_tag(tag: str): + result = subprocess.run( + ["git", "show", f"{tag}:export_presets.cfg"], + cwd=ROOT, capture_output=True, text=True, + ) + if result.returncode != 0: + print(f"check_version: cannot read export_presets.cfg at tag {tag}: {result.stderr.strip()}") + sys.exit(1) + presets = parse_presets(result.stdout) + return presets.get("version/code", "") + + +def fail(message: str) -> None: + print(f"check_version: FAIL — {message}") + sys.exit(1) + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--prev", default=None, + help="previous release tag to compare the version code against") + args = parser.parse_args() + + name, code_raw, project_version = current_values() + + if not name: + fail("export_presets.cfg has no version/name") + if not project_version: + fail("project.godot has no config/version") + if name != project_version: + fail(f"version mismatch: project.godot config/version='{project_version}' but " + f"export_presets.cfg version/name='{name}'") + + if not code_raw.isdigit() or int(code_raw) <= 0: + fail(f"version/code must be a positive integer, got '{code_raw}'") + current_code = int(code_raw) + + print(f"check_version: version/name={name} version/code={current_code} " + f"(project.godot config/version={project_version})") + + if args.prev: + prev_raw = code_at_tag(args.prev) + if not prev_raw.isdigit(): + fail(f"previous tag {args.prev} has a non-numeric version/code '{prev_raw}'") + prev_code = int(prev_raw) + if current_code <= prev_code: + fail(f"version/code did not increase: {current_code} <= {prev_code} " + f"(previous tag {args.prev}) — Android will refuse to install over it") + print(f"check_version: version/code {prev_code} -> {current_code} (ok)") + + print("check_version: OK") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/test.sh b/tools/test.sh index c73000b..2cfc6fb 100755 --- a/tools/test.sh +++ b/tools/test.sh @@ -15,6 +15,9 @@ echo "== unit tests ==" echo "== level smoke test ==" "$GODOT" --headless --path . res://tests/smoke_level.tscn +echo "== UI screen tests ==" +"$GODOT" --headless --path . res://tests/test_screens.tscn + for d in 0 1 2; do echo "== autoplay, difficulty $d ==" # --fixed-fps keeps the balance numbers comparable between runs and between machines.