diff --git a/CLAUDE.md b/CLAUDE.md index 00aa4c0..4ba99eb 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -84,14 +84,19 @@ Pipeline SDL3 GPU portat de `coffee_crisis_arcade_edition`. El canvas 256×192 e - `videoGpuPreferredDriver` (string, buit = auto) - `videoShaderEnabled` (bool) - `videoShaderType` (0=POSTFX, 1=CRTPI) -- **Hotkeys** (provisionals fins que hi hagi menú d'opcions): `F4` activa/desactiva post-procesado · `F5` alterna POSTFX ↔ CRTPI (només si està actiu) · `F6` següent preset (només si està actiu). No hi ha tecla per a preset anterior. +- **Hotkeys** (provisionals fins que hi hagi menú d'opcions): `F4` activa/desactiva post-procesado · `F5` alterna POSTFX ↔ CRTPI (només si està actiu) · `F6` següent preset (només si està actiu) · `F7` següent skin. No hi ha tecla per a preset anterior. - **API** a `Screen`: `setGpuAcceleration`/`toggleGpuAcceleration`/`isGpuAccelerated`, `setShaderEnabled`/`toggleShaderEnabled`/`isShaderEnabled`, `setActiveShader`/`toggleActiveShader`/`getActiveShader`. Presets PostFX/CrtPi i cicle de presets encara **no** estan implementats — arribaran amb la migració a YAML. Per ara, valors per defecte hardcoded. +### Skins + +Els gràfics viuen sota `data/skins//gfx/`. Cada skin té un `skin.yaml` (id, display_name, gfx_dir). `SkinManager` (`core/resources/skin_manager.*`) escaneja manifests al boot, recorda l'skin activa (`Options::settings.skin`) i composa paths per a `Asset::addSkinAware()`. El canvi en calent (F7) és lliure: `Resource::reloadForSkin()` recorre el cache de Texture* i .ani fent `reLoadFromPath`/re-parse, mantenint stable pointer identity perquè els Sprites no s'invaliden. Les skins han de mantenir paritat de basenames i dimensions (recoloreds purs). De moment només es varia el contingut gràfic; logo, fades i altres comportaments són comuns. + ## Data Directory -- `data/gfx/` — PNG spritesheets and `.ani` animation definition files +- `data/skins//gfx/` — PNG spritesheets and `.ani` animation definition files per skin (`classic`, `nes`, ...) +- `data/skins//skin.yaml` — manifest de la skin (id, display_name, gfx_dir) - `data/font/` — bitmap font files - `data/music/` and `data/sound/` — audio assets - `data/lang/` — language files (es_ES, ba_BA, en_UK) diff --git a/data/lang/ba_BA.txt b/data/lang/ba_BA.txt index 5a1d826..e1280a9 100644 --- a/data/lang/ba_BA.txt +++ b/data/lang/ba_BA.txt @@ -302,4 +302,7 @@ Shader Preset ## 101 - NOTIFICACIO HOTKEY -Torna a premer ESC per a eixir \ No newline at end of file +Torna a premer ESC per a eixir + +## 102 - NOTIFICACIO HOTKEY +Skin \ No newline at end of file diff --git a/data/lang/en_UK.txt b/data/lang/en_UK.txt index de41965..71bafff 100644 --- a/data/lang/en_UK.txt +++ b/data/lang/en_UK.txt @@ -302,4 +302,7 @@ Shader Preset ## 101 - HOTKEY NOTIFICATION -Press ESC again to quit \ No newline at end of file +Press ESC again to quit + +## 102 - HOTKEY NOTIFICATION +Skin \ No newline at end of file diff --git a/data/lang/es_ES.txt b/data/lang/es_ES.txt index bb546ce..b6a9bdb 100644 --- a/data/lang/es_ES.txt +++ b/data/lang/es_ES.txt @@ -302,4 +302,7 @@ Shader Preset ## 101 - NOTIFICACION HOTKEY -Vuelve a pulsar ESC para salir \ No newline at end of file +Vuelve a pulsar ESC para salir + +## 102 - NOTIFICACION HOTKEY +Skin \ No newline at end of file diff --git a/data/gfx/balloon1.ani b/data/skins/classic/gfx/balloon1.ani similarity index 100% rename from data/gfx/balloon1.ani rename to data/skins/classic/gfx/balloon1.ani diff --git a/data/gfx/balloon1.png b/data/skins/classic/gfx/balloon1.png similarity index 100% rename from data/gfx/balloon1.png rename to data/skins/classic/gfx/balloon1.png diff --git a/data/gfx/balloon2.ani b/data/skins/classic/gfx/balloon2.ani similarity index 100% rename from data/gfx/balloon2.ani rename to data/skins/classic/gfx/balloon2.ani diff --git a/data/gfx/balloon2.png b/data/skins/classic/gfx/balloon2.png similarity index 100% rename from data/gfx/balloon2.png rename to data/skins/classic/gfx/balloon2.png diff --git a/data/gfx/balloon3.ani b/data/skins/classic/gfx/balloon3.ani similarity index 100% rename from data/gfx/balloon3.ani rename to data/skins/classic/gfx/balloon3.ani diff --git a/data/gfx/balloon3.png b/data/skins/classic/gfx/balloon3.png similarity index 100% rename from data/gfx/balloon3.png rename to data/skins/classic/gfx/balloon3.png diff --git a/data/gfx/balloon4.ani b/data/skins/classic/gfx/balloon4.ani similarity index 100% rename from data/gfx/balloon4.ani rename to data/skins/classic/gfx/balloon4.ani diff --git a/data/gfx/balloon4.png b/data/skins/classic/gfx/balloon4.png similarity index 100% rename from data/gfx/balloon4.png rename to data/skins/classic/gfx/balloon4.png diff --git a/data/gfx/bullet.png b/data/skins/classic/gfx/bullet.png similarity index 100% rename from data/gfx/bullet.png rename to data/skins/classic/gfx/bullet.png diff --git a/data/gfx/game_buildings.png b/data/skins/classic/gfx/game_buildings.png similarity index 100% rename from data/gfx/game_buildings.png rename to data/skins/classic/gfx/game_buildings.png diff --git a/data/gfx/game_clouds.png b/data/skins/classic/gfx/game_clouds.png similarity index 100% rename from data/gfx/game_clouds.png rename to data/skins/classic/gfx/game_clouds.png diff --git a/data/gfx/game_grass.png b/data/skins/classic/gfx/game_grass.png similarity index 100% rename from data/gfx/game_grass.png rename to data/skins/classic/gfx/game_grass.png diff --git a/data/gfx/game_power_meter.png b/data/skins/classic/gfx/game_power_meter.png similarity index 100% rename from data/gfx/game_power_meter.png rename to data/skins/classic/gfx/game_power_meter.png diff --git a/data/gfx/game_sky_colors.png b/data/skins/classic/gfx/game_sky_colors.png similarity index 100% rename from data/gfx/game_sky_colors.png rename to data/skins/classic/gfx/game_sky_colors.png diff --git a/data/gfx/game_text.png b/data/skins/classic/gfx/game_text.png similarity index 100% rename from data/gfx/game_text.png rename to data/skins/classic/gfx/game_text.png diff --git a/data/gfx/intro.png b/data/skins/classic/gfx/intro.png similarity index 100% rename from data/gfx/intro.png rename to data/skins/classic/gfx/intro.png diff --git a/data/gfx/item_clock.ani b/data/skins/classic/gfx/item_clock.ani similarity index 100% rename from data/gfx/item_clock.ani rename to data/skins/classic/gfx/item_clock.ani diff --git a/data/gfx/item_clock.png b/data/skins/classic/gfx/item_clock.png similarity index 100% rename from data/gfx/item_clock.png rename to data/skins/classic/gfx/item_clock.png diff --git a/data/gfx/item_coffee.ani b/data/skins/classic/gfx/item_coffee.ani similarity index 100% rename from data/gfx/item_coffee.ani rename to data/skins/classic/gfx/item_coffee.ani diff --git a/data/gfx/item_coffee.png b/data/skins/classic/gfx/item_coffee.png similarity index 100% rename from data/gfx/item_coffee.png rename to data/skins/classic/gfx/item_coffee.png diff --git a/data/gfx/item_coffee_machine.ani b/data/skins/classic/gfx/item_coffee_machine.ani similarity index 100% rename from data/gfx/item_coffee_machine.ani rename to data/skins/classic/gfx/item_coffee_machine.ani diff --git a/data/gfx/item_coffee_machine.png b/data/skins/classic/gfx/item_coffee_machine.png similarity index 100% rename from data/gfx/item_coffee_machine.png rename to data/skins/classic/gfx/item_coffee_machine.png diff --git a/data/gfx/item_points1_disk.ani b/data/skins/classic/gfx/item_points1_disk.ani similarity index 100% rename from data/gfx/item_points1_disk.ani rename to data/skins/classic/gfx/item_points1_disk.ani diff --git a/data/gfx/item_points1_disk.png b/data/skins/classic/gfx/item_points1_disk.png similarity index 100% rename from data/gfx/item_points1_disk.png rename to data/skins/classic/gfx/item_points1_disk.png diff --git a/data/gfx/item_points2_gavina.ani b/data/skins/classic/gfx/item_points2_gavina.ani similarity index 100% rename from data/gfx/item_points2_gavina.ani rename to data/skins/classic/gfx/item_points2_gavina.ani diff --git a/data/gfx/item_points2_gavina.png b/data/skins/classic/gfx/item_points2_gavina.png similarity index 100% rename from data/gfx/item_points2_gavina.png rename to data/skins/classic/gfx/item_points2_gavina.png diff --git a/data/gfx/item_points3_pacmar.ani b/data/skins/classic/gfx/item_points3_pacmar.ani similarity index 100% rename from data/gfx/item_points3_pacmar.ani rename to data/skins/classic/gfx/item_points3_pacmar.ani diff --git a/data/gfx/item_points3_pacmar.png b/data/skins/classic/gfx/item_points3_pacmar.png similarity index 100% rename from data/gfx/item_points3_pacmar.png rename to data/skins/classic/gfx/item_points3_pacmar.png diff --git a/data/gfx/logo.png b/data/skins/classic/gfx/logo.png similarity index 100% rename from data/gfx/logo.png rename to data/skins/classic/gfx/logo.png diff --git a/data/gfx/menu_game_over.png b/data/skins/classic/gfx/menu_game_over.png similarity index 100% rename from data/gfx/menu_game_over.png rename to data/skins/classic/gfx/menu_game_over.png diff --git a/data/gfx/menu_game_over_end.png b/data/skins/classic/gfx/menu_game_over_end.png similarity index 100% rename from data/gfx/menu_game_over_end.png rename to data/skins/classic/gfx/menu_game_over_end.png diff --git a/data/gfx/player_arounder_body.png b/data/skins/classic/gfx/player_arounder_body.png similarity index 100% rename from data/gfx/player_arounder_body.png rename to data/skins/classic/gfx/player_arounder_body.png diff --git a/data/gfx/player_arounder_death.png b/data/skins/classic/gfx/player_arounder_death.png similarity index 100% rename from data/gfx/player_arounder_death.png rename to data/skins/classic/gfx/player_arounder_death.png diff --git a/data/gfx/player_arounder_fire.png b/data/skins/classic/gfx/player_arounder_fire.png similarity index 100% rename from data/gfx/player_arounder_fire.png rename to data/skins/classic/gfx/player_arounder_fire.png diff --git a/data/gfx/player_arounder_head.png b/data/skins/classic/gfx/player_arounder_head.png similarity index 100% rename from data/gfx/player_arounder_head.png rename to data/skins/classic/gfx/player_arounder_head.png diff --git a/data/gfx/player_arounder_legs.png b/data/skins/classic/gfx/player_arounder_legs.png similarity index 100% rename from data/gfx/player_arounder_legs.png rename to data/skins/classic/gfx/player_arounder_legs.png diff --git a/data/gfx/player_bal1_body.png b/data/skins/classic/gfx/player_bal1_body.png similarity index 100% rename from data/gfx/player_bal1_body.png rename to data/skins/classic/gfx/player_bal1_body.png diff --git a/data/gfx/player_bal1_death.png b/data/skins/classic/gfx/player_bal1_death.png similarity index 100% rename from data/gfx/player_bal1_death.png rename to data/skins/classic/gfx/player_bal1_death.png diff --git a/data/gfx/player_bal1_fire.png b/data/skins/classic/gfx/player_bal1_fire.png similarity index 100% rename from data/gfx/player_bal1_fire.png rename to data/skins/classic/gfx/player_bal1_fire.png diff --git a/data/gfx/player_bal1_head.png b/data/skins/classic/gfx/player_bal1_head.png similarity index 100% rename from data/gfx/player_bal1_head.png rename to data/skins/classic/gfx/player_bal1_head.png diff --git a/data/gfx/player_bal1_legs.png b/data/skins/classic/gfx/player_bal1_legs.png similarity index 100% rename from data/gfx/player_bal1_legs.png rename to data/skins/classic/gfx/player_bal1_legs.png diff --git a/data/gfx/player_body.ani b/data/skins/classic/gfx/player_body.ani similarity index 100% rename from data/gfx/player_body.ani rename to data/skins/classic/gfx/player_body.ani diff --git a/data/gfx/player_death.ani b/data/skins/classic/gfx/player_death.ani similarity index 100% rename from data/gfx/player_death.ani rename to data/skins/classic/gfx/player_death.ani diff --git a/data/gfx/player_fire.ani b/data/skins/classic/gfx/player_fire.ani similarity index 100% rename from data/gfx/player_fire.ani rename to data/skins/classic/gfx/player_fire.ani diff --git a/data/gfx/player_head.ani b/data/skins/classic/gfx/player_head.ani similarity index 100% rename from data/gfx/player_head.ani rename to data/skins/classic/gfx/player_head.ani diff --git a/data/gfx/player_legs.ani b/data/skins/classic/gfx/player_legs.ani similarity index 100% rename from data/gfx/player_legs.ani rename to data/skins/classic/gfx/player_legs.ani diff --git a/data/gfx/title_bg_tile.png b/data/skins/classic/gfx/title_bg_tile.png similarity index 100% rename from data/gfx/title_bg_tile.png rename to data/skins/classic/gfx/title_bg_tile.png diff --git a/data/gfx/title_coffee.png b/data/skins/classic/gfx/title_coffee.png similarity index 100% rename from data/gfx/title_coffee.png rename to data/skins/classic/gfx/title_coffee.png diff --git a/data/gfx/title_crisis.png b/data/skins/classic/gfx/title_crisis.png similarity index 100% rename from data/gfx/title_crisis.png rename to data/skins/classic/gfx/title_crisis.png diff --git a/data/gfx/title_dust.ani b/data/skins/classic/gfx/title_dust.ani similarity index 100% rename from data/gfx/title_dust.ani rename to data/skins/classic/gfx/title_dust.ani diff --git a/data/gfx/title_dust.png b/data/skins/classic/gfx/title_dust.png similarity index 100% rename from data/gfx/title_dust.png rename to data/skins/classic/gfx/title_dust.png diff --git a/data/gfx/title_gradient.png b/data/skins/classic/gfx/title_gradient.png similarity index 100% rename from data/gfx/title_gradient.png rename to data/skins/classic/gfx/title_gradient.png diff --git a/data/skins/classic/skin.yaml b/data/skins/classic/skin.yaml new file mode 100644 index 0000000..302a666 --- /dev/null +++ b/data/skins/classic/skin.yaml @@ -0,0 +1,4 @@ +# Coffee Crisis - Classic skin manifest +name: classic +display_name: "Classic" +gfx_dir: gfx diff --git a/data/skins/nes/gfx/balloon1.ani b/data/skins/nes/gfx/balloon1.ani new file mode 100644 index 0000000..3fbe8c1 --- /dev/null +++ b/data/skins/nes/gfx/balloon1.ani @@ -0,0 +1,37 @@ +frameWidth=8 +frameHeight=8 + +[animation] +name=orange +speed=10 +loop=0 +frames=0,1,2,3,4,5,6,7,8,9 +[/animation] + +[animation] +name=blue +speed=20 +loop=0 +frames=12,13,14,15,16,17,18,19,20,21 +[/animation] + +[animation] +name=green +speed=10 +loop=0 +frames=24,25,26,27,28,29,30,31,32,33 +[/animation] + +[animation] +name=red +speed=20 +loop=0 +frames=36,37,38,39,40,41,42,43,44,45 +[/animation] + +[animation] +name=pop +speed=5 +loop=-1 +frames=48,49,50,51,52,53,54,55,56,57,58,59 +[/animation] \ No newline at end of file diff --git a/data/skins/nes/gfx/balloon1.png b/data/skins/nes/gfx/balloon1.png new file mode 100644 index 0000000..7f1aef9 Binary files /dev/null and b/data/skins/nes/gfx/balloon1.png differ diff --git a/data/skins/nes/gfx/balloon2.ani b/data/skins/nes/gfx/balloon2.ani new file mode 100644 index 0000000..bbc4d86 --- /dev/null +++ b/data/skins/nes/gfx/balloon2.ani @@ -0,0 +1,37 @@ +frameWidth=13 +frameHeight=13 + +[animation] +name=orange +speed=10 +loop=0 +frames=0,1,2,3,4,5,6,7,8,9 +[/animation] + +[animation] +name=blue +speed=20 +loop=0 +frames=12,13,14,15,16,17,18,19,20,21 +[/animation] + +[animation] +name=green +speed=10 +loop=0 +frames=24,25,26,27,28,29,30,31,32,33 +[/animation] + +[animation] +name=red +speed=20 +loop=0 +frames=36,37,38,39,40,41,42,43,44,45 +[/animation] + +[animation] +name=pop +speed=5 +loop=-1 +frames=48,49,50,51,52,53,54,55,56,57,58,59 +[/animation] \ No newline at end of file diff --git a/data/skins/nes/gfx/balloon2.png b/data/skins/nes/gfx/balloon2.png new file mode 100644 index 0000000..8f3356b Binary files /dev/null and b/data/skins/nes/gfx/balloon2.png differ diff --git a/data/skins/nes/gfx/balloon3.ani b/data/skins/nes/gfx/balloon3.ani new file mode 100644 index 0000000..e1fd440 --- /dev/null +++ b/data/skins/nes/gfx/balloon3.ani @@ -0,0 +1,37 @@ +frameWidth=21 +frameHeight=21 + +[animation] +name=orange +speed=10 +loop=0 +frames=0,1,2,3,4,5,6,7,8,9 +[/animation] + +[animation] +name=blue +speed=20 +loop=0 +frames=12,13,14,15,16,17,18,19,20,21 +[/animation] + +[animation] +name=green +speed=10 +loop=0 +frames=24,25,26,27,28,29,30,31,32,33 +[/animation] + +[animation] +name=red +speed=20 +loop=0 +frames=36,37,38,39,40,41,42,43,44,45 +[/animation] + +[animation] +name=pop +speed=5 +loop=-1 +frames=48,49,50,51,52,53,54,55,56,57,58,59 +[/animation] \ No newline at end of file diff --git a/data/skins/nes/gfx/balloon3.png b/data/skins/nes/gfx/balloon3.png new file mode 100644 index 0000000..66ddb4a Binary files /dev/null and b/data/skins/nes/gfx/balloon3.png differ diff --git a/data/skins/nes/gfx/balloon4.ani b/data/skins/nes/gfx/balloon4.ani new file mode 100644 index 0000000..db7e703 --- /dev/null +++ b/data/skins/nes/gfx/balloon4.ani @@ -0,0 +1,44 @@ +frameWidth=37 +frameHeight=37 + +[animation] +name=orange +speed=10 +loop=0 +frames=0,1,2,3,4,5,6,7,8,9 +[/animation] + +[animation] +name=blue +speed=20 +loop=0 +frames=12,13,14,15,16,17,18,19,20,21 +[/animation] + +[animation] +name=green +speed=10 +loop=0 +frames=24,25,26,27,28,29,30,31,32,33 +[/animation] + +[animation] +name=red +speed=20 +loop=0 +frames=36,37,38,39,40,41,42,43,44,45 +[/animation] + +[animation] +name=powerball +speed=10 +loop=0 +frames=10 +[/animation] + +[animation] +name=pop +speed=5 +loop=-1 +frames=48,49,50,51,52,53,54,55,56,57,58,59 +[/animation] \ No newline at end of file diff --git a/data/skins/nes/gfx/balloon4.png b/data/skins/nes/gfx/balloon4.png new file mode 100644 index 0000000..f9b73cc Binary files /dev/null and b/data/skins/nes/gfx/balloon4.png differ diff --git a/data/skins/nes/gfx/bullet.png b/data/skins/nes/gfx/bullet.png new file mode 100644 index 0000000..88aaf65 Binary files /dev/null and b/data/skins/nes/gfx/bullet.png differ diff --git a/data/skins/nes/gfx/game_buildings.png b/data/skins/nes/gfx/game_buildings.png new file mode 100644 index 0000000..4427579 Binary files /dev/null and b/data/skins/nes/gfx/game_buildings.png differ diff --git a/data/skins/nes/gfx/game_clouds.png b/data/skins/nes/gfx/game_clouds.png new file mode 100644 index 0000000..8e45d4d Binary files /dev/null and b/data/skins/nes/gfx/game_clouds.png differ diff --git a/data/skins/nes/gfx/game_grass.png b/data/skins/nes/gfx/game_grass.png new file mode 100644 index 0000000..8c036ad Binary files /dev/null and b/data/skins/nes/gfx/game_grass.png differ diff --git a/data/skins/nes/gfx/game_power_meter.png b/data/skins/nes/gfx/game_power_meter.png new file mode 100644 index 0000000..4fb54a8 Binary files /dev/null and b/data/skins/nes/gfx/game_power_meter.png differ diff --git a/data/skins/nes/gfx/game_sky_colors.png b/data/skins/nes/gfx/game_sky_colors.png new file mode 100644 index 0000000..577b0bc Binary files /dev/null and b/data/skins/nes/gfx/game_sky_colors.png differ diff --git a/data/skins/nes/gfx/game_text.png b/data/skins/nes/gfx/game_text.png new file mode 100644 index 0000000..695b693 Binary files /dev/null and b/data/skins/nes/gfx/game_text.png differ diff --git a/data/skins/nes/gfx/intro.png b/data/skins/nes/gfx/intro.png new file mode 100644 index 0000000..4d0964b Binary files /dev/null and b/data/skins/nes/gfx/intro.png differ diff --git a/data/skins/nes/gfx/item_clock.ani b/data/skins/nes/gfx/item_clock.ani new file mode 100644 index 0000000..5967f69 --- /dev/null +++ b/data/skins/nes/gfx/item_clock.ani @@ -0,0 +1,9 @@ +frameWidth=16 +frameHeight=16 + +[animation] +name=default +speed=10 +loop=0 +frames=0,1 +[/animation] \ No newline at end of file diff --git a/data/skins/nes/gfx/item_clock.png b/data/skins/nes/gfx/item_clock.png new file mode 100644 index 0000000..415ef88 Binary files /dev/null and b/data/skins/nes/gfx/item_clock.png differ diff --git a/data/skins/nes/gfx/item_coffee.ani b/data/skins/nes/gfx/item_coffee.ani new file mode 100644 index 0000000..5967f69 --- /dev/null +++ b/data/skins/nes/gfx/item_coffee.ani @@ -0,0 +1,9 @@ +frameWidth=16 +frameHeight=16 + +[animation] +name=default +speed=10 +loop=0 +frames=0,1 +[/animation] \ No newline at end of file diff --git a/data/skins/nes/gfx/item_coffee.png b/data/skins/nes/gfx/item_coffee.png new file mode 100644 index 0000000..4888ee6 Binary files /dev/null and b/data/skins/nes/gfx/item_coffee.png differ diff --git a/data/skins/nes/gfx/item_coffee_machine.ani b/data/skins/nes/gfx/item_coffee_machine.ani new file mode 100644 index 0000000..465d9e8 --- /dev/null +++ b/data/skins/nes/gfx/item_coffee_machine.ani @@ -0,0 +1,9 @@ +frameWidth=23 +frameHeight=29 + +[animation] +name=default +speed=10 +loop=0 +frames=0,1,2,3 +[/animation] \ No newline at end of file diff --git a/data/skins/nes/gfx/item_coffee_machine.png b/data/skins/nes/gfx/item_coffee_machine.png new file mode 100644 index 0000000..4c68ecf Binary files /dev/null and b/data/skins/nes/gfx/item_coffee_machine.png differ diff --git a/data/skins/nes/gfx/item_points1_disk.ani b/data/skins/nes/gfx/item_points1_disk.ani new file mode 100644 index 0000000..5967f69 --- /dev/null +++ b/data/skins/nes/gfx/item_points1_disk.ani @@ -0,0 +1,9 @@ +frameWidth=16 +frameHeight=16 + +[animation] +name=default +speed=10 +loop=0 +frames=0,1 +[/animation] \ No newline at end of file diff --git a/data/skins/nes/gfx/item_points1_disk.png b/data/skins/nes/gfx/item_points1_disk.png new file mode 100644 index 0000000..ac974d2 Binary files /dev/null and b/data/skins/nes/gfx/item_points1_disk.png differ diff --git a/data/skins/nes/gfx/item_points2_gavina.ani b/data/skins/nes/gfx/item_points2_gavina.ani new file mode 100644 index 0000000..5967f69 --- /dev/null +++ b/data/skins/nes/gfx/item_points2_gavina.ani @@ -0,0 +1,9 @@ +frameWidth=16 +frameHeight=16 + +[animation] +name=default +speed=10 +loop=0 +frames=0,1 +[/animation] \ No newline at end of file diff --git a/data/skins/nes/gfx/item_points2_gavina.png b/data/skins/nes/gfx/item_points2_gavina.png new file mode 100644 index 0000000..cbf4529 Binary files /dev/null and b/data/skins/nes/gfx/item_points2_gavina.png differ diff --git a/data/skins/nes/gfx/item_points3_pacmar.ani b/data/skins/nes/gfx/item_points3_pacmar.ani new file mode 100644 index 0000000..5967f69 --- /dev/null +++ b/data/skins/nes/gfx/item_points3_pacmar.ani @@ -0,0 +1,9 @@ +frameWidth=16 +frameHeight=16 + +[animation] +name=default +speed=10 +loop=0 +frames=0,1 +[/animation] \ No newline at end of file diff --git a/data/skins/nes/gfx/item_points3_pacmar.png b/data/skins/nes/gfx/item_points3_pacmar.png new file mode 100644 index 0000000..f8e5515 Binary files /dev/null and b/data/skins/nes/gfx/item_points3_pacmar.png differ diff --git a/data/skins/nes/gfx/logo.png b/data/skins/nes/gfx/logo.png new file mode 100644 index 0000000..0177885 Binary files /dev/null and b/data/skins/nes/gfx/logo.png differ diff --git a/data/skins/nes/gfx/menu_game_over.png b/data/skins/nes/gfx/menu_game_over.png new file mode 100644 index 0000000..c70d2e8 Binary files /dev/null and b/data/skins/nes/gfx/menu_game_over.png differ diff --git a/data/skins/nes/gfx/menu_game_over_end.png b/data/skins/nes/gfx/menu_game_over_end.png new file mode 100644 index 0000000..5e8fe65 Binary files /dev/null and b/data/skins/nes/gfx/menu_game_over_end.png differ diff --git a/data/skins/nes/gfx/player_arounder_body.png b/data/skins/nes/gfx/player_arounder_body.png new file mode 100644 index 0000000..ec8aa4c Binary files /dev/null and b/data/skins/nes/gfx/player_arounder_body.png differ diff --git a/data/skins/nes/gfx/player_arounder_death.png b/data/skins/nes/gfx/player_arounder_death.png new file mode 100644 index 0000000..a2ee38b Binary files /dev/null and b/data/skins/nes/gfx/player_arounder_death.png differ diff --git a/data/skins/nes/gfx/player_arounder_fire.png b/data/skins/nes/gfx/player_arounder_fire.png new file mode 100644 index 0000000..5da208b Binary files /dev/null and b/data/skins/nes/gfx/player_arounder_fire.png differ diff --git a/data/skins/nes/gfx/player_arounder_head.png b/data/skins/nes/gfx/player_arounder_head.png new file mode 100644 index 0000000..211f287 Binary files /dev/null and b/data/skins/nes/gfx/player_arounder_head.png differ diff --git a/data/skins/nes/gfx/player_arounder_legs.png b/data/skins/nes/gfx/player_arounder_legs.png new file mode 100644 index 0000000..cbc353b Binary files /dev/null and b/data/skins/nes/gfx/player_arounder_legs.png differ diff --git a/data/skins/nes/gfx/player_bal1_body.png b/data/skins/nes/gfx/player_bal1_body.png new file mode 100644 index 0000000..da04d54 Binary files /dev/null and b/data/skins/nes/gfx/player_bal1_body.png differ diff --git a/data/skins/nes/gfx/player_bal1_death.png b/data/skins/nes/gfx/player_bal1_death.png new file mode 100644 index 0000000..07b3248 Binary files /dev/null and b/data/skins/nes/gfx/player_bal1_death.png differ diff --git a/data/skins/nes/gfx/player_bal1_fire.png b/data/skins/nes/gfx/player_bal1_fire.png new file mode 100644 index 0000000..cf0927c Binary files /dev/null and b/data/skins/nes/gfx/player_bal1_fire.png differ diff --git a/data/skins/nes/gfx/player_bal1_head.png b/data/skins/nes/gfx/player_bal1_head.png new file mode 100644 index 0000000..6a8d3d2 Binary files /dev/null and b/data/skins/nes/gfx/player_bal1_head.png differ diff --git a/data/skins/nes/gfx/player_bal1_legs.png b/data/skins/nes/gfx/player_bal1_legs.png new file mode 100644 index 0000000..f1a6a5e Binary files /dev/null and b/data/skins/nes/gfx/player_bal1_legs.png differ diff --git a/data/skins/nes/gfx/player_body.ani b/data/skins/nes/gfx/player_body.ani new file mode 100644 index 0000000..dd893e7 --- /dev/null +++ b/data/skins/nes/gfx/player_body.ani @@ -0,0 +1,176 @@ +frameWidth=24 +frameHeight=24 + +[animation] +name=walk +speed=5 +loop=0 +frames=0,1,2,3 +[/animation] + +[animation] +name=stand +speed=10 +loop=0 +frames=4,5,6,7 +[/animation] + +[animation] +name=walk_1C +speed=5 +loop=0 +frames=8,9,10,11 +[/animation] + +[animation] +name=stand_1C +speed=10 +loop=0 +frames=12,13,14,15 +[/animation] + +[animation] +name=walk_2C +speed=5 +loop=0 +frames=16,17,18,19 +[/animation] + +[animation] +name=stand_2C +speed=10 +loop=0 +frames=20,21,22,23 +[/animation] + + + +[animation] +name=sideshoot +speed=5 +loop=0 +frames=24,25,26,27 +[/animation] + +[animation] +name=centershoot +speed=5 +loop=0 +frames=28,29,30,31 +[/animation] + +[animation] +name=sideshoot_1C +speed=5 +loop=0 +frames=32,33,34,35 +[/animation] + +[animation] +name=centershoot_1C +speed=5 +loop=0 +frames=36,37,38,39 +[/animation] + +[animation] +name=sideshoot_2C +speed=5 +loop=0 +frames=40,41,42,43 +[/animation] + +[animation] +name=centershoot_2C +speed=5 +loop=0 +frames=44,45,46,47 +[/animation] + + + +[animation] +name=walk_pwr +speed=3 +loop=0 +frames=0,1,2,3 +[/animation] + +[animation] +name=stand_pwr +speed=5 +loop=0 +frames=4,5,6,7 +[/animation] + +[animation] +name=walk_1C_pwr +speed=3 +loop=0 +frames=8,9,10,11 +[/animation] + +[animation] +name=stand_1C_pwr +speed=5 +loop=0 +frames=12,13,14,15 +[/animation] + +[animation] +name=walk_2C_pwr +speed=3 +loop=0 +frames=16,17,18,19 +[/animation] + +[animation] +name=stand_2C_pwr +speed=5 +loop=0 +frames=20,21,22,23 +[/animation] + + + +[animation] +name=sideshoot_pwr +speed=2 +loop=0 +frames=24,25,26,27 +[/animation] + +[animation] +name=centershoot_pwr +speed=2 +loop=0 +frames=28,29,30,31 +[/animation] + +[animation] +name=sideshoot_1C_pwr +speed=2 +loop=0 +frames=32,33,34,35 +[/animation] + +[animation] +name=centershoot_1C_pwr +speed=2 +loop=0 +frames=36,37,38,39 +[/animation] + +[animation] +name=sideshoot_2C_pwr +speed=2 +loop=0 +frames=40,41,42,43 +[/animation] + +[animation] +name=centershoot_2C_pwr +speed=2 +loop=0 +frames=44,45,46,47 +[/animation] \ No newline at end of file diff --git a/data/skins/nes/gfx/player_death.ani b/data/skins/nes/gfx/player_death.ani new file mode 100644 index 0000000..2567468 --- /dev/null +++ b/data/skins/nes/gfx/player_death.ani @@ -0,0 +1,9 @@ +frameWidth=24 +frameHeight=24 + +[animation] +name=default +speed=5 +loop=0 +frames=0,1,2,3 +[/animation] \ No newline at end of file diff --git a/data/skins/nes/gfx/player_fire.ani b/data/skins/nes/gfx/player_fire.ani new file mode 100644 index 0000000..8552ba5 --- /dev/null +++ b/data/skins/nes/gfx/player_fire.ani @@ -0,0 +1,9 @@ +frameWidth=28 +frameHeight=32 + +[animation] +name=default +speed=5 +loop=0 +frames=0,1,2,3 +[/animation] \ No newline at end of file diff --git a/data/skins/nes/gfx/player_head.ani b/data/skins/nes/gfx/player_head.ani new file mode 100644 index 0000000..52fc8e0 --- /dev/null +++ b/data/skins/nes/gfx/player_head.ani @@ -0,0 +1,114 @@ +frameWidth=24 +frameHeight=24 + +[animation] +name=walk +speed=5 +loop=0 +frames=0,1,2,3 +[/animation] + +[animation] +name=stand +speed=10 +loop=0 +frames=4,5,6,7 +[/animation] + +[animation] +name=walk_1C +speed=5 +loop=0 +frames=8,9,10,11 +[/animation] + +[animation] +name=stand_1C +speed=10 +loop=0 +frames=12,13,14,15 +[/animation] + +[animation] +name=walk_pwr +speed=5 +loop=0 +frames=16,17,18,19 +[/animation] + +[animation] +name=stand_pwr +speed=10 +loop=0 +frames=20,21,22,23 +[/animation] + +[animation] +name=walk_1C_pwr +speed=5 +loop=0 +frames=24,25,26,27 +[/animation] + +[animation] +name=stand_1C_pwr +speed=10 +loop=0 +frames=28,29,30,31 +[/animation] + +[animation] +name=sideshoot +speed=5 +loop=0 +frames=16,17,18,19 +[/animation] + +[animation] +name=centershoot +speed=5 +loop=0 +frames=20,21,22,23 +[/animation] + +[animation] +name=sideshoot_1C +speed=5 +loop=0 +frames=24,25,26,27 +[/animation] + +[animation] +name=centershoot_1C +speed=5 +loop=0 +frames=28,29,30,31 +[/animation] + +[animation] +name=sideshoot_pwr +speed=2 +loop=0 +frames=16,17,18,19 +[/animation] + +[animation] +name=centershoot_pwr +speed=2 +loop=0 +frames=20,21,22,23 +[/animation] + +[animation] +name=sideshoot_1C_pwr +speed=2 +loop=0 +frames=24,25,26,27 +[/animation] + +[animation] +name=centershoot_1C_pwr +speed=2 +loop=0 +frames=28,29,30,31 +[/animation] \ No newline at end of file diff --git a/data/skins/nes/gfx/player_legs.ani b/data/skins/nes/gfx/player_legs.ani new file mode 100644 index 0000000..9cd6905 --- /dev/null +++ b/data/skins/nes/gfx/player_legs.ani @@ -0,0 +1,16 @@ +frameWidth=24 +frameHeight=24 + +[animation] +name=walk +speed=5 +loop=0 +frames=0,1,2,3 +[/animation] + +[animation] +name=stand +speed=10 +loop=0 +frames=4,5,6,7 +[/animation] \ No newline at end of file diff --git a/data/skins/nes/gfx/title_bg_tile.png b/data/skins/nes/gfx/title_bg_tile.png new file mode 100644 index 0000000..ea06e48 Binary files /dev/null and b/data/skins/nes/gfx/title_bg_tile.png differ diff --git a/data/skins/nes/gfx/title_coffee.png b/data/skins/nes/gfx/title_coffee.png new file mode 100644 index 0000000..b1f9f35 Binary files /dev/null and b/data/skins/nes/gfx/title_coffee.png differ diff --git a/data/skins/nes/gfx/title_crisis.png b/data/skins/nes/gfx/title_crisis.png new file mode 100644 index 0000000..0e4d082 Binary files /dev/null and b/data/skins/nes/gfx/title_crisis.png differ diff --git a/data/skins/nes/gfx/title_dust.ani b/data/skins/nes/gfx/title_dust.ani new file mode 100644 index 0000000..9e655a4 --- /dev/null +++ b/data/skins/nes/gfx/title_dust.ani @@ -0,0 +1,9 @@ +frameWidth=16 +frameHeight=16 + +[animation] +name=default +speed=8 +loop=-1 +frames=0,1,2,3,4,5,6 +[/animation] \ No newline at end of file diff --git a/data/skins/nes/gfx/title_dust.png b/data/skins/nes/gfx/title_dust.png new file mode 100644 index 0000000..3d4a967 Binary files /dev/null and b/data/skins/nes/gfx/title_dust.png differ diff --git a/data/skins/nes/gfx/title_gradient.png b/data/skins/nes/gfx/title_gradient.png new file mode 100644 index 0000000..046b5aa Binary files /dev/null and b/data/skins/nes/gfx/title_gradient.png differ diff --git a/data/skins/nes/skin.yaml b/data/skins/nes/skin.yaml new file mode 100644 index 0000000..4112aaa --- /dev/null +++ b/data/skins/nes/skin.yaml @@ -0,0 +1,4 @@ +# Coffee Crisis - NES skin manifest +name: nes +display_name: "NES" +gfx_dir: gfx diff --git a/source/core/input/global_inputs.cpp b/source/core/input/global_inputs.cpp index d4ebc6c..d817f85 100644 --- a/source/core/input/global_inputs.cpp +++ b/source/core/input/global_inputs.cpp @@ -5,6 +5,8 @@ #include "core/input/input.h" #include "core/locale/lang.h" #include "core/rendering/screen.h" +#include "core/resources/resource.h" +#include "core/resources/skin_manager.hpp" #include "game/options.hpp" #include "utils/utils.h" @@ -18,6 +20,7 @@ namespace GlobalInputs { constexpr int LANG_SHADER = 99; constexpr int LANG_PRESET = 100; constexpr int LANG_EXIT_CONFIRM = 101; + constexpr int LANG_SKIN = 102; constexpr Uint32 NOTIFY_MS = 1500; constexpr Uint32 EXIT_CONFIRM_MS = 2000; @@ -63,6 +66,11 @@ namespace GlobalInputs { Screen::get()->notify(MSG, GREEN, BLACK, NOTIFY_MS); } + void notifySkin() { + const std::string MSG = Lang::get()->getText(LANG_SKIN) + " " + SkinManager::get()->currentDisplayName(); + Screen::get()->notify(MSG, CYAN, BLACK, NOTIFY_MS); + } + void onExit() { const Uint32 NOW = SDL_GetTicks(); if (NOW < exit_window_until_ticks) { @@ -117,6 +125,14 @@ namespace GlobalInputs { return true; } } + if (Input::get()->checkInput(Input::Action::NEXT_SKIN, Input::Repeat::OFF)) { + const std::string NEXT_ID = SkinManager::get()->nextSkinId(); + if (NEXT_ID != SkinManager::get()->current()) { + Resource::get()->reloadForSkin(NEXT_ID); + } + notifySkin(); + return true; + } return false; } diff --git a/source/core/input/global_inputs.hpp b/source/core/input/global_inputs.hpp index b8b4f1d..38ca511 100644 --- a/source/core/input/global_inputs.hpp +++ b/source/core/input/global_inputs.hpp @@ -3,11 +3,11 @@ namespace GlobalInputs { // Gestiona els atalls globals disponibles en qualsevol escena: zoom de // finestra (F1/F2), fullscreen (F3), toggle shader (F4), tipus de shader - // POSTFX↔CRTPI (F5), següent preset (F6) i la confirmació d'eixida amb - // ESC (Action::EXIT) en dues pulsacions. Cada hotkey emet una - // notificació localitzada. Retorna true si ha consumit alguna tecla (per - // si la capa cridant vol suprimir-la del processament específic de - // l'escena). + // POSTFX↔CRTPI (F5), següent preset (F6), següent skin (F7) i la + // confirmació d'eixida amb ESC (Action::EXIT) en dues pulsacions. Cada + // hotkey emet una notificació localitzada. Retorna true si ha consumit + // alguna tecla (per si la capa cridant vol suprimir-la del processament + // específic de l'escena). auto handle() -> bool; // True si la doble pulsació d'ESC s'ha confirmat. Director consulta açò diff --git a/source/core/input/input.h b/source/core/input/input.h index 9989bb8..62ad5a0 100644 --- a/source/core/input/input.h +++ b/source/core/input/input.h @@ -50,6 +50,9 @@ class Input { TOGGLE_SHADER, TOGGLE_SHADER_TYPE, + // Skins + NEXT_SKIN, + // Centinela final (usar para sizing) NUMBER_OF_INPUTS }; @@ -61,12 +64,12 @@ class Input { ~Input(); // Destructor - void update(); // Actualiza el estado del objeto + void update(); // Actualiza el estado del objeto void bindKey(Action input, SDL_Scancode code); // Asigna inputs a teclas void bindGameControllerButton(Action input, SDL_GamepadButton button); // Asigna inputs a botones del mando auto checkInput(Action input, Repeat repeat = Repeat::ON, Device device = Device::ANY, int index = 0) -> bool; // Comprueba si un input esta activo - auto checkAnyInput(Device device = Device::ANY, int index = 0) -> bool; // Comprueba si hay almenos un input activo + auto checkAnyInput(Device device = Device::ANY, int index = 0) -> bool; // Comprueba si hay almenos un input activo auto discoverGameController() -> bool; // Busca si hay un mando conectado @@ -82,9 +85,9 @@ class Input { [[nodiscard]] auto getNumControllers() const -> int; // Obten el numero de mandos conectados auto getControllerName(int index) -> std::string; // Obten el nombre de un mando de juego - void setVerbose(bool value); // Establece si ha de mostrar mensajes - void disableUntil(Disable value); // Deshabilita las entradas durante un periodo de tiempo - void enable(); // Hablita las entradas + void setVerbose(bool value); // Establece si ha de mostrar mensajes + void disableUntil(Disable value); // Deshabilita las entradas durante un periodo de tiempo + void enable(); // Hablita las entradas private: struct KeyBindings { diff --git a/source/core/locale/lang.h b/source/core/locale/lang.h index 578b115..5265872 100644 --- a/source/core/locale/lang.h +++ b/source/core/locale/lang.h @@ -30,7 +30,7 @@ class Lang { static auto nextLanguage(Code c) -> Code; // Devuelve el siguiente idioma del ciclo private: - static constexpr int MAX_TEXT_STRINGS = 110; + static constexpr int MAX_TEXT_STRINGS = 111; std::string text_strings_[MAX_TEXT_STRINGS]; // Vector con los textos diff --git a/source/core/rendering/texture.cpp b/source/core/rendering/texture.cpp index 81b05c1..dbdd450 100644 --- a/source/core/rendering/texture.cpp +++ b/source/core/rendering/texture.cpp @@ -212,6 +212,14 @@ auto Texture::reLoad() -> bool { return loadFromFile(path_, renderer_); } +// Reapunta el path emmagatzemat i recarrega: usat pel SkinManager per a +// fer hot-swap d'skin mantenint estable el punter Texture* (els Sprites +// continuen apuntant al mateix objecte amb contingut actualitzat). +auto Texture::reLoadFromPath(const std::string &new_path) -> bool { + path_ = new_path; + return loadFromFile(path_, renderer_); +} + // Obtiene la textura auto Texture::getSDLTexture() -> SDL_Texture * { return texture_; diff --git a/source/core/rendering/texture.h b/source/core/rendering/texture.h index e9d729e..096f811 100644 --- a/source/core/rendering/texture.h +++ b/source/core/rendering/texture.h @@ -26,13 +26,14 @@ class Texture { void setAlpha(Uint8 alpha); // Establece el alpha para la modulación void render(SDL_Renderer *renderer, int x, int y, const SDL_Rect *clip = nullptr, float zoom_w = 1, float zoom_h = 1, double angle = 0.0, const SDL_Point *center = nullptr, SDL_FlipMode flip = SDL_FLIP_NONE); // Renderiza la textura en un punto específico - void setAsRenderTarget(SDL_Renderer *renderer); // Establece la textura como objetivo de renderizado + void setAsRenderTarget(SDL_Renderer *renderer); // Establece la textura como objetivo de renderizado [[nodiscard]] auto getWidth() const -> int; // Obtiene el ancho de la imagen [[nodiscard]] auto getHeight() const -> int; // Obtiene el alto de la imagen - auto reLoad() -> bool; // Recarga la textura - auto getSDLTexture() -> SDL_Texture *; // Obtiene la textura + auto reLoad() -> bool; // Recarga la textura + auto reLoadFromPath(const std::string &new_path) -> bool; // Reapunta path_ i recarrega (preserva el Texture*) + auto getSDLTexture() -> SDL_Texture *; // Obtiene la textura private: // Objetos y punteros diff --git a/source/core/resources/asset.cpp b/source/core/resources/asset.cpp index 31fd105..b989fb3 100644 --- a/source/core/resources/asset.cpp +++ b/source/core/resources/asset.cpp @@ -6,6 +6,7 @@ #include // for basic_ostream, operator<<, cout, endl #include "core/resources/resource_helper.h" +#include "core/resources/skin_manager.hpp" // Instancia única Asset *Asset::instance = nullptr; @@ -41,6 +42,30 @@ void Asset::add(const std::string &file, Type type, bool required, bool absolute longest_name_ = SDL_max(longest_name_, FILE_NAME.size()); } +// Afegeix un asset gfx skin-aware: el path complet es composa via +// SkinManager (que ja inclou el PREFIX de plataforma) i guardem el +// basename per a poder-lo recomposar quan canviï la skin activa. +void Asset::addSkinAware(const std::string &basename, Type type, bool required) { + Item temp; + temp.file = executable_path_ + SkinManager::get()->gfxPath(basename); + temp.type = type; + temp.required = required; + temp.skin_basename = basename; + file_list_.push_back(temp); + + longest_name_ = SDL_max(longest_name_, basename.size()); +} + +// Recomposa els paths dels items skin-aware amb l'skin actual del +// SkinManager. Cridat per Resource::reloadForSkin després d'un canvi. +void Asset::onSkinChanged() { + for (auto &it : file_list_) { + if (!it.skin_basename.empty()) { + it.file = executable_path_ + SkinManager::get()->gfxPath(it.skin_basename); + } + } +} + // Devuelve el fichero de un elemento de la lista a partir de una cadena auto Asset::get(const std::string &text) -> std::string { for (const auto &f : file_list_) { diff --git a/source/core/resources/asset.h b/source/core/resources/asset.h index e7f44d1..39bd3ea 100644 --- a/source/core/resources/asset.h +++ b/source/core/resources/asset.h @@ -23,9 +23,10 @@ class Asset { // Estructura para definir un item struct Item { - std::string file; // Ruta del fichero desde la raiz del directorio - Type type; // Indica el tipo de recurso - bool required; // Indica si es un fichero que debe de existir + std::string file; // Ruta del fichero desde la raiz del directorio + Type type; // Indica el tipo de recurso + bool required; // Indica si es un fichero que debe de existir + std::string skin_basename; // No buit ⇒ item skin-aware (recomposable via SkinManager) }; // Singleton API @@ -34,6 +35,8 @@ class Asset { static auto get() -> Asset *; // Obtiene el puntero a la instancia void add(const std::string &file, Type type, bool required = true, bool absolute = false); // Añade un elemento a la lista + void addSkinAware(const std::string &basename, Type type, bool required = true); // Afegeix un asset gfx que viu sota la skin activa (recomposable) + void onSkinChanged(); // Recomposa el path dels items skin-aware amb la skin actual auto get(const std::string &text) -> std::string; // Devuelve un elemento de la lista a partir de una cadena [[nodiscard]] auto getAll() const -> const std::vector & { return file_list_; } // Devuelve toda la lista de items registrados auto check() -> bool; // Comprueba que existen todos los elementos diff --git a/source/core/resources/resource.cpp b/source/core/resources/resource.cpp index 6f77bd8..8b83b7b 100644 --- a/source/core/resources/resource.cpp +++ b/source/core/resources/resource.cpp @@ -8,6 +8,8 @@ #include "core/rendering/texture.h" #include "core/resources/asset.h" #include "core/resources/resource_helper.h" +#include "core/resources/skin_manager.hpp" +#include "game/options.hpp" #include "game/ui/menu.h" // Nota: Asset::get() e Input::get() se consultan en preloadAll y al construir @@ -263,3 +265,41 @@ auto Resource::getMenu(const std::string &name) -> Menu * { } return it->second; } + +void Resource::reloadForSkin(const std::string &skin_id) { + if (SkinManager::get() == nullptr || !SkinManager::get()->exists(skin_id)) { + return; + } + + SkinManager::get()->setCurrent(skin_id); + Asset::get()->onSkinChanged(); + + // Recarrega cada textura cachejada des del nou path mantenint pointer + // identity perquè els Sprites no s'invaliden. + for (auto &[bname, tex] : textures_) { + const std::string NEW_PATH = Asset::get()->get(bname); + if (!NEW_PATH.empty()) { + tex->reLoadFromPath(NEW_PATH); + } + } + + // Re-parseja els fitxers .ani de la nova skin. + for (auto &[bname, lines] : animation_lines_) { + const std::string NEW_PATH = Asset::get()->get(bname); + if (NEW_PATH.empty()) { continue; } + auto bytes = ResourceHelper::loadFile(NEW_PATH); + if (bytes.empty()) { continue; } + std::string content(reinterpret_cast(bytes.data()), bytes.size()); + std::stringstream ss(content); + std::vector new_lines; + std::string line; + while (std::getline(ss, line)) { + if (!line.empty() && line.back() == '\r') { line.pop_back(); } + new_lines.push_back(line); + } + lines = std::move(new_lines); + } + + Options::settings.skin = skin_id; + Options::saveToFile(); +} diff --git a/source/core/resources/resource.h b/source/core/resources/resource.h index e41d428..7e0108d 100644 --- a/source/core/resources/resource.h +++ b/source/core/resources/resource.h @@ -31,6 +31,11 @@ class Resource { auto getMenu(const std::string &name) -> Menu *; // name sin extensión: "title", "options", ... auto getDemoBytes() const -> const std::vector & { return demo_bytes_; } + // Recarrega tots els recursos skin-aware (textures + animacions) per a + // l'skin donada. Manté pointer identity dels Texture* perquè els Sprites + // existents continuïn vàlids. + void reloadForSkin(const std::string &skin_id); + private: explicit Resource(SDL_Renderer *renderer); ~Resource(); diff --git a/source/core/resources/skin_manager.cpp b/source/core/resources/skin_manager.cpp new file mode 100644 index 0000000..26fecdd --- /dev/null +++ b/source/core/resources/skin_manager.cpp @@ -0,0 +1,133 @@ +#include "core/resources/skin_manager.hpp" + +#include +#include +#include + +#include "core/resources/resource_helper.h" +#include "core/resources/resource_loader.h" +#include "external/fkyaml_node.hpp" + +SkinManager *SkinManager::instance = nullptr; + +void SkinManager::init(const std::string &executable_path, const std::string &asset_prefix) { + if (instance == nullptr) { + instance = new SkinManager(executable_path, asset_prefix); + instance->scan(); + } +} + +void SkinManager::destroy() { + delete instance; + instance = nullptr; +} + +auto SkinManager::get() -> SkinManager * { + return instance; +} + +SkinManager::SkinManager(std::string executable_path, std::string asset_prefix) + : executable_path_(std::move(executable_path)), + asset_prefix_(std::move(asset_prefix)) { +} + +void SkinManager::scan() { + skins_.clear(); + + // ResourceLoader enumera tant entries del pack com fitxers de + // `data/` en mode fallback. Les claus retornades són relatives a + // `data/` (ex: "skins/classic/skin.yaml"). Buscar manifests + // amb aquest patró és més robust que `std::filesystem` perquè + // funciona igual a release (pack) que a dev (filesystem). + const auto ALL = ResourceLoader::getInstance().getAvailableResources(); + + const std::string PREFIX = "skins/"; + const std::string SUFFIX = "/skin.yaml"; + + for (const auto &key : ALL) { + if (!key.starts_with(PREFIX) || !key.ends_with(SUFFIX)) { continue; } + const std::string ID = key.substr(PREFIX.size(), key.size() - PREFIX.size() - SUFFIX.size()); + if (ID.find('/') != std::string::npos) { continue; } // només top-level dins skins/ + + // ResourceHelper espera un path que contingui "data/" — el construïm + // amb la convenció habitual del projecte. + const std::string FULL_PATH = executable_path_ + asset_prefix_ + "/data/" + key; + auto bytes = ResourceHelper::loadFile(FULL_PATH); + if (bytes.empty()) { + std::cerr << "SkinManager: cannot read manifest " << FULL_PATH << '\n'; + continue; + } + + SkinInfo info; + info.id = ID; + info.display_name = ID; + info.gfx_dir = "gfx"; + + try { + const std::string CONTENT(reinterpret_cast(bytes.data()), bytes.size()); + auto yaml = fkyaml::node::deserialize(CONTENT); + if (yaml.contains("display_name")) { + info.display_name = yaml["display_name"].get_value(); + } + if (yaml.contains("gfx_dir")) { + info.gfx_dir = yaml["gfx_dir"].get_value(); + } + } catch (const fkyaml::exception &e) { + std::cerr << "SkinManager: bad manifest " << FULL_PATH << ": " << e.what() << '\n'; + continue; + } + + skins_.push_back(std::move(info)); + } + + // Ordre alfabètic estable: garanteix que next/prev són deterministes. + std::ranges::sort(skins_, [](const SkinInfo &a, const SkinInfo &b) { return a.id < b.id; }); +} + +auto SkinManager::exists(const std::string &id) const -> bool { + return std::ranges::any_of(skins_, [&](const SkinInfo &s) { return s.id == id; }); +} + +auto SkinManager::currentDisplayName() const -> std::string { + return displayNameOf(current_id_); +} + +auto SkinManager::displayNameOf(const std::string &id) const -> std::string { + const auto IT = std::ranges::find_if(skins_, [&](const SkinInfo &s) { return s.id == id; }); + return (IT != skins_.end()) ? IT->display_name : id; +} + +void SkinManager::setCurrent(const std::string &id) { + if (exists(id)) { + current_id_ = id; + } +} + +auto SkinManager::gfxDirOf(const std::string &id) const -> std::string { + const auto IT = std::ranges::find_if(skins_, [&](const SkinInfo &s) { return s.id == id; }); + return (IT != skins_.end()) ? IT->gfx_dir : std::string("gfx"); +} + +auto SkinManager::gfxPath(const std::string &basename) const -> std::string { + return asset_prefix_ + "/data/skins/" + current_id_ + "/" + gfxDirOf(current_id_) + "/" + basename; +} + +auto SkinManager::nextSkinId() const -> std::string { + if (skins_.empty()) { return current_id_; } + for (size_t i = 0; i < skins_.size(); ++i) { + if (skins_[i].id == current_id_) { + return skins_[(i + 1) % skins_.size()].id; + } + } + return skins_.front().id; +} + +auto SkinManager::prevSkinId() const -> std::string { + if (skins_.empty()) { return current_id_; } + for (size_t i = 0; i < skins_.size(); ++i) { + if (skins_[i].id == current_id_) { + return skins_[(i + skins_.size() - 1) % skins_.size()].id; + } + } + return skins_.front().id; +} diff --git a/source/core/resources/skin_manager.hpp b/source/core/resources/skin_manager.hpp new file mode 100644 index 0000000..b3cc64a --- /dev/null +++ b/source/core/resources/skin_manager.hpp @@ -0,0 +1,66 @@ +#pragma once + +#include +#include + +// Gestor de skins. Una "skin" és un set complet de gràfics (PNGs + .ani) +// emmagatzemat sota `data/skins//gfx/`. El SkinManager: +// +// * descobreix les skins disponibles escanejant `data/skins/*/skin.yaml`, +// * recorda quina skin està activa (`current_id_`), +// * composa els paths perquè Asset/Resource sàpiguen on llegir. +// +// L'arrencada típica és: Director crida `init(executable_path, asset_prefix)` +// (escaneja manifests) i acte seguit `setCurrent(Options::settings.skin)`. +// Després registra els assets via `Asset::addSkinAware("balloon1.png", ...)` +// que utilitza internament `gfxPath()` del SkinManager. +// +// Per al canvi en calent, Resource crida `setCurrent(new_id)`, després +// `Asset::onSkinChanged()` per a actualitzar paths registrats, i recarrega +// cada Texture via `reLoadFromPath`. + +class SkinManager { + public: + struct SkinInfo { + std::string id; // Carpeta dins data/skins/ (ex: "classic") + std::string display_name; // Etiqueta visible a la UI (ex: "Classic") + std::string gfx_dir; // Subcarpeta amb els gfx (default: "gfx") + }; + + // executable_path: acabat amb '/' (típicament SDL_GetBasePath()). + // asset_prefix: prefix relatiu per a paths registrats a Asset + // (ex: "" en Linux/Win, "/../Resources" dins el bundle de macOS). + static void init(const std::string &executable_path, const std::string &asset_prefix); + static void destroy(); + static auto get() -> SkinManager *; + + void scan(); + [[nodiscard]] auto available() const -> const std::vector & { return skins_; } + [[nodiscard]] auto current() const -> const std::string & { return current_id_; } + [[nodiscard]] auto currentDisplayName() const -> std::string; + [[nodiscard]] auto displayNameOf(const std::string &id) const -> std::string; + [[nodiscard]] auto exists(const std::string &id) const -> bool; + + void setCurrent(const std::string &id); + + // Compon el path relatiu d'un gràfic dins la skin activa, amb el format + // que Asset::add espera (relatiu amb prefix de plataforma): + // "/data/skins///" + [[nodiscard]] auto gfxPath(const std::string &basename) const -> std::string; + + // Cíclic. Si només hi ha una skin, retorna la mateixa. + [[nodiscard]] auto nextSkinId() const -> std::string; + [[nodiscard]] auto prevSkinId() const -> std::string; + + private: + SkinManager(std::string executable_path, std::string asset_prefix); + + [[nodiscard]] auto gfxDirOf(const std::string &id) const -> std::string; + + std::string executable_path_; // Acabat amb '/' (per a scan filesystem) + std::string asset_prefix_; // PREFIX per a paths registrats + std::vector skins_; + std::string current_id_{"classic"}; + + static SkinManager *instance; +}; diff --git a/source/core/system/director.cpp b/source/core/system/director.cpp index bb0abef..7dc0112 100644 --- a/source/core/system/director.cpp +++ b/source/core/system/director.cpp @@ -26,6 +26,7 @@ #include "core/resources/asset.h" // for Asset, Asset::Type #include "core/resources/resource.h" #include "core/resources/resource_helper.h" +#include "core/resources/skin_manager.hpp" #include "game/defaults.hpp" // for SECTION_PROG_LOGO, GAMECANVAS_H... #include "game/game.h" // for Game #include "game/options.hpp" // for Options::init, loadFromFile... @@ -106,6 +107,22 @@ Director::Director(int argc, const char *argv[]) { Asset::init(executable_path_); Asset::get()->setVerbose(Options::settings.console); + // Inicialitza el gestor de skins ANTES de registrar assets: setFileList + // composa els paths gfx via SkinManager::gfxPath(). Si la skin del config + // no existeix, caiem a "classic". +#ifdef MACOS_BUNDLE + SkinManager::init(executable_path_, "/../Resources"); +#else + SkinManager::init(executable_path_, ""); +#endif + if (!SkinManager::get()->exists(Options::settings.skin)) { + if (Options::settings.console) { + std::cout << "Skin '" << Options::settings.skin << "' not found, falling back to 'classic'.\n"; + } + Options::settings.skin = "classic"; + } + SkinManager::get()->setCurrent(Options::settings.skin); + // Si falta algún fichero no inicia el programa if (!setFileList()) { exit(EXIT_FAILURE); @@ -184,6 +201,7 @@ Director::~Director() { Resource::destroy(); Asset::destroy(); + SkinManager::destroy(); Input::destroy(); Lang::destroy(); delete section_; @@ -231,6 +249,7 @@ void Director::initInput() { Input::get()->bindKey(Input::Action::TOGGLE_SHADER, SDL_SCANCODE_F4); Input::get()->bindKey(Input::Action::TOGGLE_SHADER_TYPE, SDL_SCANCODE_F5); Input::get()->bindKey(Input::Action::NEXT_SHADER_PRESET, SDL_SCANCODE_F6); + Input::get()->bindKey(Input::Action::NEXT_SKIN, SDL_SCANCODE_F7); // Mando - Movimiento del jugador Input::get()->bindGameControllerButton(Input::Action::UP, SDL_GAMEPAD_BUTTON_DPAD_UP); @@ -363,66 +382,66 @@ auto Director::setFileList() -> bool { Asset::get()->add(PREFIX + "/data/sound/clock.wav", Asset::Type::SOUND); Asset::get()->add(PREFIX + "/data/sound/powerball.wav", Asset::Type::SOUND); - // Texturas - Asset::get()->add(PREFIX + "/data/gfx/balloon1.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/balloon1.ani", Asset::Type::DATA); - Asset::get()->add(PREFIX + "/data/gfx/balloon2.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/balloon2.ani", Asset::Type::DATA); - Asset::get()->add(PREFIX + "/data/gfx/balloon3.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/balloon3.ani", Asset::Type::DATA); - Asset::get()->add(PREFIX + "/data/gfx/balloon4.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/balloon4.ani", Asset::Type::DATA); - Asset::get()->add(PREFIX + "/data/gfx/bullet.png", Asset::Type::BITMAP); + // Texturas (skin-aware: viuen sota data/skins//gfx/) + Asset::get()->addSkinAware("balloon1.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("balloon1.ani", Asset::Type::DATA); + Asset::get()->addSkinAware("balloon2.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("balloon2.ani", Asset::Type::DATA); + Asset::get()->addSkinAware("balloon3.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("balloon3.ani", Asset::Type::DATA); + Asset::get()->addSkinAware("balloon4.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("balloon4.ani", Asset::Type::DATA); + Asset::get()->addSkinAware("bullet.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/game_buildings.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/game_clouds.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/game_grass.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/game_power_meter.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/game_sky_colors.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/game_text.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("game_buildings.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("game_clouds.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("game_grass.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("game_power_meter.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("game_sky_colors.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("game_text.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/intro.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/logo.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/menu_game_over.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/menu_game_over_end.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("intro.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("logo.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("menu_game_over.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("menu_game_over_end.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/item_points1_disk.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/item_points1_disk.ani", Asset::Type::DATA); - Asset::get()->add(PREFIX + "/data/gfx/item_points2_gavina.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/item_points2_gavina.ani", Asset::Type::DATA); - Asset::get()->add(PREFIX + "/data/gfx/item_points3_pacmar.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/item_points3_pacmar.ani", Asset::Type::DATA); - Asset::get()->add(PREFIX + "/data/gfx/item_clock.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/item_clock.ani", Asset::Type::DATA); - Asset::get()->add(PREFIX + "/data/gfx/item_coffee.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/item_coffee.ani", Asset::Type::DATA); - Asset::get()->add(PREFIX + "/data/gfx/item_coffee_machine.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/item_coffee_machine.ani", Asset::Type::DATA); + Asset::get()->addSkinAware("item_points1_disk.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("item_points1_disk.ani", Asset::Type::DATA); + Asset::get()->addSkinAware("item_points2_gavina.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("item_points2_gavina.ani", Asset::Type::DATA); + Asset::get()->addSkinAware("item_points3_pacmar.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("item_points3_pacmar.ani", Asset::Type::DATA); + Asset::get()->addSkinAware("item_clock.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("item_clock.ani", Asset::Type::DATA); + Asset::get()->addSkinAware("item_coffee.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("item_coffee.ani", Asset::Type::DATA); + Asset::get()->addSkinAware("item_coffee_machine.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("item_coffee_machine.ani", Asset::Type::DATA); - Asset::get()->add(PREFIX + "/data/gfx/title_bg_tile.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/title_coffee.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/title_crisis.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/title_dust.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/title_dust.ani", Asset::Type::DATA); - Asset::get()->add(PREFIX + "/data/gfx/title_gradient.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("title_bg_tile.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("title_coffee.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("title_crisis.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("title_dust.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("title_dust.ani", Asset::Type::DATA); + Asset::get()->addSkinAware("title_gradient.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/player_head.ani", Asset::Type::DATA); - Asset::get()->add(PREFIX + "/data/gfx/player_body.ani", Asset::Type::DATA); - Asset::get()->add(PREFIX + "/data/gfx/player_legs.ani", Asset::Type::DATA); - Asset::get()->add(PREFIX + "/data/gfx/player_death.ani", Asset::Type::DATA); - Asset::get()->add(PREFIX + "/data/gfx/player_fire.ani", Asset::Type::DATA); + Asset::get()->addSkinAware("player_head.ani", Asset::Type::DATA); + Asset::get()->addSkinAware("player_body.ani", Asset::Type::DATA); + Asset::get()->addSkinAware("player_legs.ani", Asset::Type::DATA); + Asset::get()->addSkinAware("player_death.ani", Asset::Type::DATA); + Asset::get()->addSkinAware("player_fire.ani", Asset::Type::DATA); - Asset::get()->add(PREFIX + "/data/gfx/player_bal1_head.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/player_bal1_body.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/player_bal1_legs.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/player_bal1_death.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/player_bal1_fire.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("player_bal1_head.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("player_bal1_body.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("player_bal1_legs.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("player_bal1_death.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("player_bal1_fire.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/player_arounder_head.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/player_arounder_body.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/player_arounder_legs.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/player_arounder_death.png", Asset::Type::BITMAP); - Asset::get()->add(PREFIX + "/data/gfx/player_arounder_fire.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("player_arounder_head.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("player_arounder_body.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("player_arounder_legs.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("player_arounder_death.png", Asset::Type::BITMAP); + Asset::get()->addSkinAware("player_arounder_fire.png", Asset::Type::BITMAP); // Fuentes Asset::get()->add(PREFIX + "/data/font/8bithud.png", Asset::Type::FONT); diff --git a/source/game/options.cpp b/source/game/options.cpp index 16cc1d2..fcde0f8 100644 --- a/source/game/options.cpp +++ b/source/game/options.cpp @@ -151,6 +151,7 @@ namespace Options { } settings.language = static_cast(language_int); parseIntField(st, "player_selected", settings.player_selected); + parseStringField(st, "skin", settings.skin); } void loadGameplayFromYaml(const fkyaml::node &yaml) { @@ -322,7 +323,8 @@ namespace Options { file << "settings:\n"; file << " difficulty: " << settings.difficulty << "\n"; file << " language: " << static_cast(settings.language) << "\n"; - file << " player_selected: " << settings.player_selected << "\n\n"; + file << " player_selected: " << settings.player_selected << "\n"; + file << " skin: \"" << settings.skin << "\"\n\n"; // GAMEPLAY file << "# GAMEPLAY\n"; diff --git a/source/game/options.hpp b/source/game/options.hpp index bcf0c11..d6bb551 100644 --- a/source/game/options.hpp +++ b/source/game/options.hpp @@ -78,6 +78,7 @@ namespace Options { bool console = false; int player_selected = 0; std::string config_file; + std::string skin = "classic"; }; struct Gameplay {