# PROJECT HANDOFF - Company RPG Training Engine Current version: 1.5.7-animation-asset-loader-hardening Package name: company-rpg-v1.5.7-animation-asset-loader-hardening.zip This file is the main return-to-project document. If a future assistant had only this file, it should understand the current state well enough to generate a similar next package quickly. ## What this project is A browser-based 2D top-down company-management RPG/training simulation engine. It is not one fixed game. It is a scenario engine for workshops. Core modes: - Player view - team plays the scenario on a tile map. - Facilitator Command Center - trainer controls events, messages, cash, indicators and scenario flow. - Projector - room display for ranking/status. - Admin tools - map building, scenario editing, animation building, asset checking, diagnostics, QA. Hosting assumption: - Simple PHP hosting. - No Node build required on server. - Data stored in JSON/SQLite fallback style. - Paid vendor asset folders are not bundled in generated packages. User copies their own assets into assets/vendor. Important user preference: - Always update this PROJECT_HANDOFF.md in every generated package. - Non-technical guides should avoid Polish diacritics where possible because some viewers break them. Use e.g. sciana, podloga, przejscie, druzyna. - Do not bundle full paid asset packs unless explicitly asked. ## What changed in v1.5.7 Added System Diagnostics Center: ```text /admin/tools/system-diagnostics.html api/diagnostics.php docs/SYSTEM_DIAGNOSTICS_CENTER_GUIDE.md ``` Purpose: one central panel to check whether the whole application is healthy before a workshop or after changes. It checks: - backend PHP and key files - writable data folders - version consistency between VERSION and js/config.js - assets and mapping files - sprite mapping - animation definitions - multi-tile frames - missing tilesets - maps - transitions between maps - spawn points - pathfinding reachability - interactionTile issues - scenarios - stages / scenario flow - recurring events - availability windows - sessions/logs - reporting/analytics smoke checks - non-technical docs encoding issues The diagnostics panel has: - global readiness status: READY / READY_WITH_WARNINGS / NOT_READY - critical/error/warning/info counts - category summaries - filter by level/category/text - fix hints - links to related tools - export JSON report - export Markdown report - copy summary to clipboard ## Current main tools Admin: ```text /admin/index.html /admin/login.html /admin/scenarios.html /admin/sessions.html /admin/workshop-check.html ``` Core workshop views: ```text /index.html /join.html /facilitator.html /projector.html /session-summary.html /debrief.html ``` Important admin tools: ```text /admin/tools/system-diagnostics.html <-- new central diagnostics panel /admin/tools/map-builder.html <-- Map Studio /admin/tools/scenario-editor.html /admin/tools/scenario-timeline.html /admin/tools/scenario-flow-control-room.html /admin/tools/playtest-qa.html /admin/tools/animation-builder.html /admin/tools/animation-preview.html /admin/tools/asset-library.html /admin/tools/workshop-analytics.html /admin/tools/interaction-animation-editor.html /admin/tools/balance-analyzer.html ``` ## Current core mechanics Implemented features include: - Tile/grid map movement. - Multi-map transitions. - Double-click testing of map transitions in Map Studio. - Multi-floor maps by treating each floor as a separate map. - Spawn points. - Map network validation. - Dynamic doors with state-based collision. - Hover text for transitions, e.g. Wejscie do serwerowni. - Player/NPC/static object animations. - Animation Builder with multi-tile frame support. - Sprite mapping save via backend with backups. - Asset Library Manager. - NPC patrol/wander movement. - Movement logs for analytics. - Heatmap and spaghetti diagram analytics. - Scenario Editor. - Scenario stages / flow engine. - Recurring events. - Availability windows for actions/purchases/roles/quests. - Room/area entry events. - Facilitator-targeted events/messages/cash/indicator corrections. - Scenario Director / Flow Control Room. - Session summary and debriefing views. - System Diagnostics Center. ## Latest versions context Recent important packages: ```text v1.4.0-animation-builder-asset-workflow v1.4.1-visual-technical-polish v1.5.0-scenario-flow-engine v1.5.1-scenario-flow-control-room v1.5.2-map-builder-studio-advanced v1.5.3-map-studio-multifloor-demo v1.5.4-animation-builder-multitile-frames v1.5.5-animation-preview-diagnostics v1.5.7-animation-asset-loader-hardening ``` ## Current known constraints - Browser-click full manual testing is still needed after generation. - Vendor assets are not bundled, so animation preview may show placeholders unless user copied assets into assets/vendor and rebuilt vendor index. - Diagnostics can detect many issues but does not auto-fix maps/scenarios yet. - SQLite may be unavailable on some hosting. Diagnostics warns if pdo_sqlite is missing. - Pathfinding diagnostics is intentionally approximate. It checks obvious blocked tiles, unreachable interactionTiles and spawns. - Reports/analytics are HTML-first. PDF/Excel premium exports are still future work. ## How to test current package Run locally: ```bash cd company-rpg-v1.5.7-animation-asset-loader-hardening php -S localhost:8080 ``` Login: ```text /admin/login.html admin / admin-change-me ``` Start with: ```text /admin/tools/system-diagnostics.html ``` Then test: ```text /admin/tools/map-builder.html /admin/tools/animation-builder.html /admin/tools/animation-preview.html /admin/tools/asset-library.html /admin/tools/scenario-flow-control-room.html /admin/tools/playtest-qa.html /facilitator.html?code=FIRMA-742 /projector.html?code=FIRMA-742 /admin/tools/workshop-analytics.html ``` ## Recommended next iterations Strong next candidates: 1. v1.5.7-diagnostics-quick-fixes - safe quick repair actions from diagnostics panel - create missing folders - rebuild vendor index - refresh asset manifest - open specific object/map/scenario directly from issue links - diagnostics history snapshots 2. v1.6.0-report-export-premium - client-facing report polish - PDF export - Excel/CSV export bundle - facilitator notes in report - analytics snapshots in report 3. v1.7.0-content-pack-manager - scenario packs - map packs - import/export content packs - starter templates for NIS2/UKSC, backup, cyber/quality, 5S, energy, integrated management systems 4. v1.8.0-advanced-analytics - richer behavior analytics - stage-aware analytics - team comparison over time - object visit funnel - decision timeline by team ## If recreating this package from scratch Start from latest v1.5.5 package, then: 1. Add api/diagnostics.php. 2. Add /admin/tools/system-diagnostics.html. 3. Update /admin/index.html with diagnostics links. 4. Update VERSION and js/config.js to 1.5.7-animation-asset-loader-hardening. 5. Update docs/SYSTEM_DIAGNOSTICS_CENTER_GUIDE.md. 6. Strongly update this PROJECT_HANDOFF.md. 7. Update README, CHANGELOG, ROADMAP, NEXT_STEPS, COMPLETE_APPLICATION_TEST_PLAN. 8. Run PHP syntax checks, JS syntax checks, JSON validation and ZIP integrity. --- # PROJECT HANDOFF - Company RPG / Isoztego Version: v1.5.5-animation-preview-diagnostics Updated: 2026-07-12 This is the main restart file for the project. If a new conversation has only this file, it should be enough to understand the current state and generate a very similar package. ## 1. Project goal We are building a browser-based 2D top-down company-management training simulation engine. The app is not one fixed game. It is a scenario engine for workshops. A facilitator can create sessions, teams can join, players move around company maps, interact with NPCs/objects, make decisions, buy controls/roles, trigger events, and later review reports, debriefing, analytics, heatmaps and spaghetti diagrams. The tone of the training scenarios is often corporate, humorous, slightly absurd and practical. ## 2. Hosting and tech assumptions - Simple web app. - PHP backend is allowed. - No Node build step on hosting. - Works on shared hosting style deployment. - SQLite/JSON-style fallback is acceptable. - Paid vendor assets must not be bundled in generated packages. - User copies vendor asset packs manually into `assets/vendor/`. - Every package must update this file. - Non-technical guides should avoid Polish diacritics because display can break. ## 3. Current package Expected ZIP name: ```text company-rpg-v1.5.5-animation-preview-diagnostics.zip ``` Current version string: ```text 1.5.5-animation-preview-diagnostics ``` ## 4. Main implemented modules ### Player game Files: ```text index.html js/game.js js/asset-loader.js js/actions.js js/events.js js/scenario-flow.js js/session-client.js ``` Implemented: - Top-down grid movement. - Click-to-move. - Keyboard movement. - Pathfinding. - Collision. - Object/NPC interactions. - Context action menus. - Dynamic object states. - Dynamic doors. - Multi-map transitions. - Hover text for transitions/objects. - Room/area entry events. - NPC movement: patrol and wander. - Static object animation, e.g. machines/servers/monitors. - Directional player/NPC animations where sprite mapping supports them. - Multitile sprite rendering from v1.5.5. ### Session / workshop Files: ```text join.html facilitator.html projector.html api/session.php js/session-client.js ``` Implemented: - Session code join flow. - Multiple teams in one session. - Facilitator command center. - Targeted facilitator interventions: - event to everyone / selected / one team - message to everyone / selected / one team - cash correction - indicator correction - Intervention history. - Projector view. - Session summary. - Debriefing. ### Admin and scenario library Files: ```text admin/index.html admin/login.html admin/scenarios.html admin/sessions.html api/scenario.php js/scenario-client.js ``` Implemented: - Admin login. - Scenario library. - Scenario duplicate/export/import basics. - Session creation from scenario. - Map list API. - Backend map save/duplicate actions. ### Scenario Editor Files: ```text admin/tools/scenario-editor.html admin/tools/scenario-editor.js ``` Implemented: - Edit scenario basics. - Map file reference. - Economy/indicators. - Events/choices. - Objects/actions through map linkage. - Purchases/roles. - Quests/goals. - Basic validation. ### Scenario Flow Engine Files: ```text js/scenario-flow.js admin/tools/scenario-timeline.html admin/tools/scenario-flow-control-room.html facilitator.html ``` Implemented: - Stages/chapters of scenario. - Stage-aware event logic. - Recurring events. - Availability windows for actions/purchases/roles/quests. - Scenario timeline view. - Scenario Director in facilitator panel. - Manual stage control. - Freeze/resume auto stage progression. - Pause/resume recurring events. - Debug why an event is blocked. ### Map Studio / Map Builder Files: ```text admin/tools/map-builder.html admin/tools/map-builder.js admin/tools/map-builder.css ``` Implemented: - Map selection by list/cards. - Load map from `data/maps/`. - Save map to library through backend. - Save as / duplicate map. - Auto building generator. - Outdoor hub generator. - Tile painting. - Walls, doors/passages, blockers. - Furniture. - Objects/NPC/machines/systems. - Spawn points. - Multi-map transitions. - Transition presets: doors/exits/stairs/elevator. - Transition hover text shown to player. - Double click transition testing. - Optionally load target map after double click test. - One-way transition support. - Floor/level metadata. - Height/floor editor as design metadata. - Mini map. - Pathfinding preview. - Layer visibility. - Show only problems. - Undo/redo basics. - Object list filters. - Multitile sprite footprint support in preview/collision from v1.5.5. ### Animation tools Files: ```text admin/tools/animation-builder.html admin/tools/animation-preview.html admin/tools/interaction-animation-editor.html api/asset-mapping.php js/asset-loader.js ``` Implemented: - Refresh/rebuild vendor asset index. - Pick tileset/image from `assets/vendor` index. - Build animations by clicking frames. - Save animation to `sprite-mapping.json` with backend backup. - Export animation JSON fragment. - Preview animation. - Interaction/object state animation editor. - From v1.5.5: multitile animation frames. ## 5. v1.5.5 change: multitile animation frames Problem solved: Some sprites are not one tile. A character or machine animation frame may be 2x2, 2x3, 4x2, 6x2 etc. Before v1.5.5, Animation Builder assumed that one clicked cell equals one animation frame. That was wrong for many real asset sheets. Now Animation Builder separates: ```text base tile size - the small grid cell in the source image, e.g. 16x16 frame size - how many base tiles one animation frame uses, e.g. 2x2 or 4x2 render size - how large the graphic is drawn on the map footprint - collision/logical size on the map anchor - how the graphic is attached to the tile ``` New sprite fields: ```json { "baseTileWidth": 16, "baseTileHeight": 16, "frameTileW": 2, "frameTileH": 3, "frameWidth": 32, "frameHeight": 48, "anchor": "bottom-center", "footprint": { "w": 1, "h": 1 } } ``` Important rule: ```text A tall/wide character can have frame 2x3 but footprint 1x1. A machine can have frame 4x2 and footprint 4x2. A tall door can have frame 1x2 and footprint 1x1. ``` Frame coordinates: `tileX` and `tileY` are base-tile coordinates, not pixels. For a 2x2 frame, frames in one row usually start at: ```text 0,0 2,0 4,0 6,0 ``` For a 4x2 machine: ```text 0,0 4,0 8,0 12,0 ``` ## 6. Key files changed in v1.5.5 ```text admin/tools/animation-builder.html admin/tools/animation-preview.html js/asset-loader.js js/game.js admin/tools/map-builder.js data/assets/sprite-mapping.json docs/MULTITILE_ANIMATION_FRAMES_NON_TECH_GUIDE.md docs/ANIMATION_BUILDER_NON_TECH_GUIDE.md docs/CHARACTER_AND_ANIMATION_GUIDE.md docs/DATA_SCHEMA.md docs/CHANGELOG.md docs/NEXT_STEPS.md docs/PROJECT_HANDOFF.md README.md VERSION js/config.js ``` ## 7. Animation Builder details `admin/tools/animation-builder.html` now has: ```text Base tile width / height Frame width in base tiles Frame height in base tiles Calculated frame width / height in pixels Snap to frame grid checkbox Anchor selector Footprint width / height ``` Presets include: ```text Postac 1x1 - 4 kierunki Postac 2x2 - 4 kierunki Wysoka postac 2x3 Maszyna 1x1 Duza maszyna 4x2 Drzwi 1x1 Drzwi wysokie 1x2 ``` Clicking a frame: - Converts browser click to canvas pixel coordinates. - Converts pixel coordinates to base tile coordinates. - Snaps to the top-left of the full frame rectangle when snap is enabled. - Stores `{ tileX, tileY }` in the animation frame list. - The drawn yellow rectangle covers the whole frame, not one tiny tile. ## 8. Renderer details `js/asset-loader.js`: - `normalizeMapping()` supports `baseTileWidth/baseTileHeight/frameTileW/frameTileH`. - `drawMappedImage()` supports `anchor`: - `top-left` - `bottom-center` - `center` - Exposes `spriteFootprint(registry, spriteId)`. `js/game.js`: - `objectFootprint(obj)` checks explicit object `w/h` first. - If `w/h` is missing, it uses sprite mapping `footprint`. - Collision marks the whole footprint as blocked. - Object hit detection detects clicks/hover inside the footprint. - Object drawing passes footprint size to AssetLoader. `admin/tools/map-builder.js`: - Uses sprite footprint for collision preview. - Uses sprite footprint for object selection rectangle. - Draws larger sprites according to their mapping. ## 9. Known limitations - Multitile frame selection assumes regular grid layout. If a sheet has irregular spacing, user may need to turn off snap or still edit JSON manually. - Per-animation playback speed is not implemented yet. Currently one `frameDurationMs` per sprite. - Animation Builder does not yet auto-fill a full row after selecting first frame. - Map Builder does not yet show a detailed sprite footprint editor in the selected object panel; it uses sprite mapping footprint automatically. - There is no visual cutscene system yet. - Full PDF/Excel report export is not implemented yet. ## 10. How to run ```bash php -S localhost:8080 ``` Admin: ```text /admin/login.html admin / admin-change-me ``` Key tools: ```text /admin/tools/animation-builder.html /admin/tools/animation-preview.html /admin/tools/map-builder.html /admin/tools/asset-library.html /admin/tools/scenario-editor.html /admin/tools/scenario-flow-control-room.html /admin/tools/workshop-analytics.html ``` ## 11. Recommended v1.5.5 test flow 1. Copy real vendor assets into `assets/vendor`. 2. Open Animation Builder. 3. Click `Odswiez assets/vendor`. 4. Pick a character sheet that has 2x2 or 2x3 frames. 5. Set base tile to 16x16 if the sheet grid is 16. 6. Set frame size to 2x2 or 2x3. 7. Use preset `Postac 2x2` or `Wysoka postac 2x3`. 8. Click three frames in one row. 9. Save as `test_character_2x2`. 10. Open Animation Preview and test it. 11. Open Map Builder. 12. Put this sprite on an NPC. 13. Confirm the NPC is selected by its footprint. 14. Run game and confirm the sprite renders using anchor/footprint. 15. Repeat with a 4x2 machine and footprint 4x2. ## 12. Presentation notes Show these features if presenting the project: ```text - Player movement and interactions - NPCs and objects - Dynamic doors - Multi-map transitions - Multi-floor maps with stairs/elevator - Room entry events - Facilitator command center - Scenario Director / flow control room - Recurring events - Projector - Session summary and debriefing - Workshop analytics: heatmap and spaghetti - Map Studio - Animation Builder - NEW v1.5.5 multitile animation frames - Asset Library Manager - Playtest QA and validation ``` ## 13. Next strong update candidates ### Option A: v1.5.5 player-experience-polish Focus on the player window: ```text - cleaner HUD - clearer current objective - nicer event modal - action menu grouping - better notification queue - accessible keyboard shortcuts - optional mini-map for player ``` ### Option B: v1.6.0 report-export-premium Focus on post-workshop outputs: ```text - polished report HTML - PDF export - CSV/Excel export - facilitator notes in report - scenario-specific debriefing templates ``` ### Option C: v1.7.0 content-pack-manager Focus on packaging scenarios: ```text - content pack metadata - scenario + maps + animation fragments + guide - import/export whole pack - content pack validation ``` ## v1.5.5 - Animation Preview diagnostics and asset path fix Problem found during testing: pages inside `/admin/tools/` used `CompanyRpgConfig.assetPaths` values such as `data/assets/sprite-mapping.json` as relative URLs. Browser resolved them as `/admin/tools/data/assets/sprite-mapping.json`, causing 404 errors for `tile-mapping.json`, `sprite-mapping.json` and `vendor-index.json`. Fix: `js/asset-loader.js` now resolves all application-relative asset paths from the application root detected from `/js/asset-loader.js`. It also resolves tileset image paths from the same root, so nested admin tools can load assets correctly. Animation Preview was rewritten into a diagnostic view. It now shows resolved paths, sprite count, animated sprite count, loaded image count, selected sprite details, missing tileset warnings, and a refresh button. This means a saved animation should now appear in Animation Preview if it exists in `data/assets/sprite-mapping.json`. If the sprite appears but the image does not, the issue is likely missing `assets/vendor` files or a stale `data/assets/vendor-index.json`. When rebuilding a future package from this handoff, preserve this rule: config paths such as `data/...` and `api/...` are application-root paths, not page-relative paths. Any tool in `/admin/tools/` must resolve them back to project root. --- ## Aktualizacja v1.5.7-animation-asset-loader-hardening ### Dlaczego powstala ta wersja Po v1.5.6 podczas testow wyszedl problem w narzedziach animacji: ```text Animation Builder czasem nie pokazywal obrazka po wyborze tilesetu. Animation Preview pokazywal Sprite mapping: BLAD, Sprite count: 0 i nie widzial animacji. W konsoli byly bledy 404 dla data/assets/sprite-mapping.json, tile-mapping.json albo vendor-index.json oraz bledy wczytywania obrazkow z assets/vendor. ``` Najwazniejsza diagnoza: ```text 1. Czesciowo byly to problemy ze sciezkami z /admin/tools/ do /data/assets/. 2. Drugi problem byl wazniejszy: AssetLoader przechodzil w fallback, gdy nie udalo sie wczytac jednego obrazka vendor. To ukrywalo caly sprite-mapping, mimo ze JSON byl poprawny. ``` ### Co zmieniono #### 1. AssetLoader jest odporniejszy Plik: ```text js/asset-loader.js ``` Zmiany: ```text - mapping JSON wczytuje sie niezaleznie od tego, czy wszystkie obrazki vendor istnieja - brak jednego tilesetu nie rozwala calego registry - registry.enabled zostaje true, jesli mappingi sa poprawne - brakujace obrazy trafiaja do missingImages oraz imageErrors - Animation Preview moze pokazac spriteId, nawet jesli grafiki nie ma fizycznie na serwerze ``` To jest kluczowe, bo zapis animacji do sprite-mapping.json i fizyczne istnienie obrazka w assets/vendor to dwa rozne problemy. Od v1.5.7 aplikacja pokazuje je osobno. #### 2. Animation Preview ma lepsza diagnostyke Plik: ```text admin/tools/animation-preview.html ``` Zmiany: ```text - pokazuje Missing images - pokazuje imageLoaded dla wybranego sprite - pokazuje missingImage path dla wybranego tilesetId - nie ukrywa listy spriteId tylko dlatego, ze brakuje grafiki - komunikat na canvasie mowi: Sprite jest, ale brak obrazka ``` Interpretacja: ```text Sprite mapping OK + Sprite count > 0 = animacje sa w JSON. Missing images > 0 = trzeba ogarnac assets/vendor albo vendor-index. ``` #### 3. Animation Builder lepiej rozroznia zrodla assetow Plik: ```text admin/tools/animation-builder.html ``` Lista tilesetow pokazuje teraz zrodlo: ```text LIVE - plik znaleziony realnie przez api/list-assets.php w assets/vendor INDEX - wpis z data/assets/vendor-index.json MANIFEST - reczny wpis z data/assets/asset-manifest.json ``` W praktyce, po wgraniu assetow na serwer, osoba nietechniczna powinna: ```text 1. Wejsc w Animation Builder. 2. Kliknac Odswiez assets/vendor. 3. Wybrac tileset oznaczony jako [LIVE]. 4. Dopiero wtedy budowac animacje. ``` Wpisy [MANIFEST] moga wskazywac oczekiwana sciezke, ale jesli assety zostaly rozpakowane inaczej, grafika moze sie nie wczytac. Dlatego [LIVE] jest najbezpieczniejszy. ### Nowy poradnik Dodano: ```text docs/ANIMATION_ASSET_LOADING_FIX_GUIDE.md ``` Opisuje: ```text - czemu Preview mogl nie pokazywac animacji - czym roznia sie LIVE / INDEX / MANIFEST - co zrobic po wgraniu nowych assetow do assets/vendor - jak odroznic problem zapisu animacji od problemu brakujacego obrazka ``` ### Jak testowac v1.5.7 1. Uruchom lokalnie: ```bash php -S localhost:8080 ``` 2. Otworz: ```text /admin/tools/animation-preview.html ``` Oczekiwane: ```text Sprite mapping: OK Sprite count > 0 Jesli brakuje vendor assetow, Missing images moze byc > 0, ale lista spriteId nadal powinna dzialac. ``` 3. Otworz: ```text /admin/tools/animation-builder.html ``` 4. Kliknij: ```text Odswiez assets/vendor ``` 5. Jesli na serwerze sa prawdziwe assety, wybierz wpis [LIVE]. Jesli wybierzesz [MANIFEST] i grafika sie nie pokaze, to nie jest blad animacji, tylko brak pliku w dokladnej sciezce z manifestu. 6. Zbuduj prosta animacje, zapisz do sprite-mapping, potem wejdz w Animation Preview i kliknij Odswiez sprite-mapping. ### Znane ograniczenia po v1.5.7 ```text - Jesli vendor assety nie sa fizycznie w paczce ani na serwerze, Preview pokaze spriteId, ale nie pokaze grafiki. - Jesli assety sa rozpakowane w innej strukturze niz asset-manifest.json, wybieraj wpisy [LIVE] z vendor scan. - AssetLoader nie probuje automatycznie zgadywac, ktory realny plik odpowiada staremu tilesetId z manifestu. To celowe, zeby nie podmieniac grafik po cichu. ``` ### Kolejne sensowne kroki ```text v1.5.8 - asset path repair helper: - porownanie tilesetId z manifestu z realnymi plikami vendor - sugestie: ten MANIFEST prawdopodobnie odpowiada temu LIVE - opcja przepisania tilesetId w sprite-mapping albo dodania aliasu tilesetu v1.6.0 - player HUD polish: - lepszy ekran gracza - ladniejsze modale eventow - lepsze menu akcji - czystszy dziennik i cele v1.7.0 - content pack manager: - paczki scenariuszy z mapami, asset mappingiem, briefingiem i debriefingiem ```