4 Commits

15 changed files with 392 additions and 182 deletions

4
.gitignore vendored
View File

@@ -16,4 +16,6 @@ todo
build/
linux_utils/
.claude/
source/version.h
source/version.h
resources.pack
jdd_release/

406
Makefile
View File

@@ -1,215 +1,365 @@
executable = jaildoctors_dilemma
source = $(shell find source -name "*.cpp")
appName = JailDoctor's Dilemma
releaseFolder = jdd_release
# ==============================================================================
# DIRECTORIES
# ==============================================================================
DIR_ROOT := $(dir $(abspath $(MAKEFILE_LIST)))
DIR_SOURCES := $(addsuffix /, $(DIR_ROOT)source)
DIR_BIN := $(addsuffix /, $(DIR_ROOT))
DIR_TOOLS := $(addsuffix /, $(DIR_ROOT)tools)
# Automatic version based on current date (OS-specific)
# ==============================================================================
# TARGET NAMES
# ==============================================================================
TARGET_NAME := jaildoctors_dilemma
TARGET_FILE := $(DIR_BIN)$(TARGET_NAME)
APP_NAME := JailDoctor's Dilemma
RELEASE_FOLDER := jdd_release
RELEASE_FILE := $(RELEASE_FOLDER)/$(TARGET_NAME)
RESOURCE_FILE := release/jdd.res
# ==============================================================================
# PACKING TOOL
# ==============================================================================
ifeq ($(OS),Windows_NT)
PACK_TOOL := $(DIR_TOOLS)pack_resources/pack_resources.exe
PACK_CXX := $(CXX)
else
PACK_TOOL := $(DIR_TOOLS)pack_resources/pack_resources
PACK_CXX := $(CXX)
endif
PACK_SOURCES := $(DIR_TOOLS)pack_resources/pack_resources.cpp source/core/resources/resource_pack.cpp
PACK_INCLUDES := -Isource
# ==============================================================================
# VERSION (automatic based on date)
# ==============================================================================
ifeq ($(OS),Windows_NT)
VERSION := $(shell powershell -Command "Get-Date -Format 'yyyy-MM-dd'")
else
VERSION := $(shell date +%Y-%m-%d)
endif
# Release names
windowsRelease = $(executable)-$(VERSION)-win32-x64.zip
macosIntelRelease = $(executable)-$(VERSION)-macos-intel.dmg
macosAppleSiliconRelease = $(executable)-$(VERSION)-macos-apple-silicon.dmg
linuxRelease = $(executable)-$(VERSION)-linux.tar.gz
# ==============================================================================
# WINDOWS-SPECIFIC VARIABLES
# ==============================================================================
ifeq ($(OS),Windows_NT)
WIN_TARGET_FILE := $(DIR_BIN)$(APP_NAME)
WIN_RELEASE_FILE := $(RELEASE_FOLDER)/$(APP_NAME)
else
WIN_TARGET_FILE := $(TARGET_FILE)
WIN_RELEASE_FILE := $(RELEASE_FILE)
endif
# Specify the C++ standard
cpp_standard = c++20
# ==============================================================================
# RELEASE NAMES
# ==============================================================================
WINDOWS_RELEASE := $(TARGET_NAME)-$(VERSION)-win32-x64.zip
MACOS_INTEL_RELEASE := $(TARGET_NAME)-$(VERSION)-macos-intel.dmg
MACOS_APPLE_SILICON_RELEASE := $(TARGET_NAME)-$(VERSION)-macos-apple-silicon.dmg
LINUX_RELEASE := $(TARGET_NAME)-$(VERSION)-linux.tar.gz
# Resource packing tool
packTool = tools/pack_resources/pack_resources
packToolSource = tools/pack_resources/pack_resources.cpp source/core/resources/resource_pack.cpp
# ==============================================================================
# SOURCE FILES
# ==============================================================================
APP_SOURCES := \
source/main.cpp \
source/core/audio/audio.cpp \
source/core/input/input.cpp \
source/core/input/mouse.cpp \
source/core/input/global_inputs.cpp \
source/core/rendering/screen.cpp \
source/core/rendering/surface.cpp \
source/core/rendering/surface_sprite.cpp \
source/core/rendering/surface_animated_sprite.cpp \
source/core/rendering/surface_moving_sprite.cpp \
source/core/rendering/text.cpp \
source/core/rendering/texture.cpp \
source/core/rendering/gif.cpp \
source/core/rendering/opengl/opengl_shader.cpp \
source/core/resources/asset.cpp \
source/core/resources/resource.cpp \
source/core/resources/resource_helper.cpp \
source/core/resources/resource_loader.cpp \
source/core/resources/resource_pack.cpp \
source/core/system/director.cpp \
source/core/system/debug.cpp \
source/core/system/global_events.cpp \
source/game/options.cpp \
source/game/entities/player.cpp \
source/game/entities/enemy.cpp \
source/game/entities/item.cpp \
source/game/gameplay/room.cpp \
source/game/gameplay/scoreboard.cpp \
source/game/gameplay/cheevos.cpp \
source/game/gameplay/item_tracker.cpp \
source/game/gameplay/room_tracker.cpp \
source/game/gameplay/stats.cpp \
source/game/scenes/logo.cpp \
source/game/scenes/loading_screen.cpp \
source/game/scenes/title.cpp \
source/game/scenes/game.cpp \
source/game/scenes/game_over.cpp \
source/game/scenes/ending.cpp \
source/game/scenes/ending2.cpp \
source/game/scenes/credits.cpp \
source/game/ui/notifier.cpp \
source/utils/utils.cpp \
source/utils/delta_timer.cpp \
source/external/jail_audio.cpp
# Build the resource packing tool
pack_tool:
@echo "Building pack_resources tool..."
@cd tools/pack_resources && $(MAKE)
# ==============================================================================
# INCLUDES
# ==============================================================================
INCLUDES := -Isource
# Create resources.pack from data directory
resources.pack: pack_tool
@echo "Creating resources.pack..."
@$(packTool) data resources.pack
# ==============================================================================
# COMPILER FLAGS (OS-specific)
# ==============================================================================
CPP_STANDARD := c++20
ifeq ($(OS),Windows_NT)
FixPath = $(subst /,\\,$1)
CXXFLAGS := -std=$(CPP_STANDARD) -Wall -Os -ffunction-sections -fdata-sections \
-Wl,--gc-sections -static-libstdc++ -static-libgcc \
-Wl,-subsystem,windows -DWINDOWS_BUILD
CXXFLAGS_DEBUG := -std=$(CPP_STANDARD) -Wall -g -D_DEBUG -DWINDOWS_BUILD
LDFLAGS := -lmingw32 -lws2_32 -lSDL3 -lopengl32
RM := del /Q
MKDIR := mkdir
else
FixPath = $1
CXXFLAGS := -std=$(CPP_STANDARD) -Wall -Os -ffunction-sections -fdata-sections
CXXFLAGS_DEBUG := -std=$(CPP_STANDARD) -Wall -g -D_DEBUG
LDFLAGS := -lSDL3
RMFILE := rm -f
RMDIR := rm -rdf
MKDIR := mkdir -p
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
CXXFLAGS += -DLINUX_BUILD
LDFLAGS += -lGL
endif
ifeq ($(UNAME_S),Darwin)
CXXFLAGS += -Wno-deprecated -DMACOS_BUILD
CXXFLAGS_DEBUG += -Wno-deprecated -DMACOS_BUILD
LDFLAGS += -framework OpenGL
# Configurar arquitectura (por defecto arm64)
CXXFLAGS += -arch arm64
CXXFLAGS_DEBUG += -arch arm64
endif
endif
# ==============================================================================
# REGLAS PARA HERRAMIENTA DE EMPAQUETADO Y RESOURCES.PACK
# ==============================================================================
$(PACK_TOOL): FORCE
@echo "Compilando herramienta de empaquetado..."
$(PACK_CXX) -std=$(CPP_STANDARD) -Wall -Os $(PACK_INCLUDES) $(PACK_SOURCES) -o $(PACK_TOOL)
@echo "✓ Herramienta de empaquetado lista: $(PACK_TOOL)"
pack_tool: $(PACK_TOOL)
resources.pack: $(PACK_TOOL)
@echo "Generando resources.pack desde directorio data/..."
$(PACK_TOOL) data resources.pack
@echo "✓ resources.pack generado exitosamente"
# ==============================================================================
# COMPILACIÓN PARA WINDOWS
# ==============================================================================
windows:
@echo off
g++ $(source) -Isource -std=$(cpp_standard) -Wall -Os -lmingw32 -lws2_32 -lSDL3main -lSDL3 -lopengl32 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(executable).exe"
strip -s -R .comment -R .gnu.version "$(executable).exe" --strip-unneeded
@echo Compilando para Windows con nombre: "$(WIN_TARGET_FILE).exe"
windres release/jdd.rc -O coff -o $(RESOURCE_FILE)
g++ $(APP_SOURCES) $(RESOURCE_FILE) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(WIN_TARGET_FILE).exe"
strip -s -R .comment -R .gnu.version "$(WIN_TARGET_FILE).exe" --strip-unneeded
windows_debug:
@echo off
g++ $(source) -Isource -D DEBUG -std=$(cpp_standard) -Wall -Os -lmingw32 -lws2_32 -lSDL3main -lSDL3 -lopengl32 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(executable)_debug.exe"
strip -s -R .comment -R .gnu.version "$(executable)_debug.exe" --strip-unneeded
@echo Compilando version debug para Windows: "$(WIN_TARGET_FILE)_debug.exe"
g++ $(APP_SOURCES) $(INCLUDES) -DDEBUG -DVERBOSE $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(WIN_TARGET_FILE)_debug.exe"
windows_release:
@echo off
# Build packing tool and create resources.pack
@$(MAKE) pack_tool
@$(MAKE) resources.pack
@echo off
@echo Creando release para Windows - Version: $(VERSION)
# Generate version.h from version.h.in
@echo "Generating version.h..."
@echo "Generando version.h..."
@powershell -Command "$$GIT_HASH = (git rev-parse --short=7 HEAD 2>$$null); if (-not $$GIT_HASH) { $$GIT_HASH = 'unknown' }; (Get-Content source/version.h.in) -replace '@GIT_HASH@', $$GIT_HASH | Set-Content source/version.h"
# Create release folder
powershell if (Test-Path "$(releaseFolder)") {Remove-Item "$(releaseFolder)" -Recurse -Force}
powershell if (-not (Test-Path "$(releaseFolder)")) {New-Item "$(releaseFolder)" -ItemType Directory}
# Crea carpeta temporal 'RELEASE_FOLDER'
powershell if (Test-Path "$(RELEASE_FOLDER)") {Remove-Item "$(RELEASE_FOLDER)" -Recurse -Force}
powershell if (-not (Test-Path "$(RELEASE_FOLDER)")) {New-Item "$(RELEASE_FOLDER)" -ItemType Directory}
# Copy resources.pack instead of data folder
powershell Copy-Item "resources.pack" -Destination "$(releaseFolder)"
# Copia el archivo 'resources.pack'
powershell Copy-Item -Path "resources.pack" -Destination "$(RELEASE_FOLDER)"
# Copy root files
powershell Copy-Item "LICENSE" -Destination "$(releaseFolder)"
powershell Copy-Item "README.md" -Destination "$(releaseFolder)"
powershell Copy-Item "gamecontrollerdb.txt" -Destination "$(releaseFolder)"
powershell Copy-Item "release\*.dll" -Destination "$(releaseFolder)"
# Copia los ficheros que están en la raíz del proyecto
powershell Copy-Item "LICENSE" -Destination "$(RELEASE_FOLDER)"
powershell Copy-Item "README.md" -Destination "$(RELEASE_FOLDER)"
powershell Copy-Item "gamecontrollerdb.txt" -Destination "$(RELEASE_FOLDER)"
powershell Copy-Item "release\*.dll" -Destination "$(RELEASE_FOLDER)"
# Build with RELEASE_BUILD flag (include jdd.res for icon)
g++ $(source) release/jdd.res -Isource -D RELEASE_BUILD -std=$(cpp_standard) -Wall -Os -lmingw32 -lws2_32 -lSDL3main -lSDL3 -lopengl32 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(releaseFolder)/$(executable).exe"
strip -s -R .comment -R .gnu.version "$(releaseFolder)/$(executable).exe" --strip-unneeded
# Compila (con icono)
windres release/jdd.rc -O coff -o $(RESOURCE_FILE)
g++ $(APP_SOURCES) $(RESOURCE_FILE) $(INCLUDES) -DRELEASE_BUILD $(CXXFLAGS) $(LDFLAGS) -o "$(WIN_RELEASE_FILE).exe"
strip -s -R .comment -R .gnu.version "$(WIN_RELEASE_FILE).exe" --strip-unneeded
# Create ZIP
powershell if (Test-Path $(windowsRelease)) {Remove-Item $(windowsRelease)}
powershell Compress-Archive -Path "$(releaseFolder)"/* -DestinationPath $(windowsRelease)
# Crea el fichero .zip
powershell if (Test-Path "$(WINDOWS_RELEASE)") {Remove-Item "$(WINDOWS_RELEASE)"}
powershell Compress-Archive -Path "$(RELEASE_FOLDER)"/* -DestinationPath "$(WINDOWS_RELEASE)"
@echo Release creado: $(WINDOWS_RELEASE)
# Remove folder
powershell if (Test-Path "$(releaseFolder)") {Remove-Item "$(releaseFolder)" -Recurse -Force}
# Elimina la carpeta temporal 'RELEASE_FOLDER'
powershell if (Test-Path "$(RELEASE_FOLDER)") {Remove-Item "$(RELEASE_FOLDER)" -Recurse -Force}
# ==============================================================================
# COMPILACIÓN PARA MACOS
# ==============================================================================
macos:
clang++ $(source) -Isource -std=$(cpp_standard) -Wall -Os -lSDL3 -framework OpenGL -Wno-deprecated -ffunction-sections -fdata-sections -o "$(executable)"
@echo "Compilando para macOS: $(TARGET_NAME)"
clang++ $(APP_SOURCES) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(TARGET_FILE)"
macos_debug:
clang++ $(source) -Isource -D DEBUG -std=$(cpp_standard) -Wall -Os -lSDL3 -framework OpenGL -Wno-deprecated -ffunction-sections -fdata-sections -o "$(executable)_debug"
@echo "Compilando version debug para macOS: $(TARGET_NAME)_debug"
clang++ $(APP_SOURCES) $(INCLUDES) -DDEBUG -DVERBOSE $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug"
macos_release:
# Build packing tool and create resources.pack
@$(MAKE) pack_tool
@$(MAKE) resources.pack
@echo "Creating macOS release - Version: $(VERSION)"
@echo "Creando release para macOS - Version: $(VERSION)"
# Verificar e instalar create-dmg si es necesario
@which create-dmg > /dev/null || (echo "Instalando create-dmg..." && brew install create-dmg)
# Generate version.h from version.h.in
@echo "Generating version.h..."
@echo "Generando version.h..."
@GIT_HASH=$$(git rev-parse --short=7 HEAD 2>/dev/null || echo "unknown"); \
sed "s/@GIT_HASH@/$$GIT_HASH/g" source/version.h.in > source/version.h
# Verify and install create-dmg if necessary
@which create-dmg > /dev/null || (echo "Installing create-dmg..." && brew install create-dmg)
# Elimina datos de compilaciones anteriores
$(RMDIR) "$(RELEASE_FOLDER)"
$(RMDIR) Frameworks
$(RMFILE) tmp.dmg
$(RMFILE) "$(MACOS_INTEL_RELEASE)"
$(RMFILE) "$(MACOS_APPLE_SILICON_RELEASE)"
# Remove data and possible data from previous builds
rm -rdf "$(releaseFolder)"
rm -rdf Frameworks
rm -f tmp.dmg
rm -f "$(macosIntelRelease)"
rm -f "$(macosAppleSiliconRelease)"
# Crea la carpeta temporal para hacer el trabajo y las carpetas obligatorias para crear una app de macOS
$(MKDIR) "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Frameworks"
$(MKDIR) "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/MacOS"
$(MKDIR) "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources"
$(MKDIR) Frameworks
# Create folders
mkdir -p "$(releaseFolder)/$(appName).app/Contents/Frameworks"
mkdir -p "$(releaseFolder)/$(appName).app/Contents/MacOS"
mkdir -p "$(releaseFolder)/$(appName).app/Contents/Resources"
mkdir -p Frameworks
# Copy resources.pack instead of data folder
cp resources.pack "$(releaseFolder)/$(appName).app/Contents/Resources"
cp gamecontrollerdb.txt "$(releaseFolder)/$(appName).app/Contents/Resources"
cp -R release/frameworks/SDL3.xcframework/macos-arm64_x86_64/SDL3.framework "$(releaseFolder)/$(appName).app/Contents/Frameworks"
# Copia carpetas y ficheros
cp resources.pack "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources"
cp gamecontrollerdb.txt "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources"
cp -R release/frameworks/SDL3.xcframework/macos-arm64_x86_64/SDL3.framework "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Frameworks"
cp -R release/frameworks/SDL3.xcframework/macos-arm64_x86_64/SDL3.framework Frameworks
cp release/*.icns "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources"
cp release/Info.plist "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents"
cp LICENSE "$(RELEASE_FOLDER)"
cp README.md "$(RELEASE_FOLDER)"
# Copy files
cp release/*.icns "$(releaseFolder)/$(appName).app/Contents/Resources"
cp release/Info.plist "$(releaseFolder)/$(appName).app/Contents"
cp LICENSE "$(releaseFolder)"
cp README.md "$(releaseFolder)"
# Compila la versión para procesadores Intel
clang++ $(APP_SOURCES) $(INCLUDES) -DMACOS_BUNDLE -DRELEASE_BUILD -std=$(CPP_STANDARD) -Wall -Os -framework SDL3 -F ./Frameworks -framework OpenGL -Wno-deprecated -ffunction-sections -fdata-sections -o "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/MacOS/$(TARGET_NAME)" -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.15
# Build INTEL with RELEASE_BUILD flag
clang++ $(source) -Isource -D MACOS_BUNDLE -D RELEASE_BUILD -std=$(cpp_standard) -Wall -Os -framework SDL3 -F ./Frameworks -framework OpenGL -Wno-deprecated -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.15
# Firma la aplicación
codesign --deep --force --sign - --timestamp=none "$(RELEASE_FOLDER)/$(APP_NAME).app"
# Code sign the Intel application
codesign --deep --force --sign - --timestamp=none "$(releaseFolder)/$(appName).app"
# Build INTEL DMG with create-dmg
@echo "Creating Intel DMG with 96x96 icons..."
# Empaqueta el .dmg de la versión Intel con create-dmg
@echo "Creando DMG Intel con iconos de 96x96..."
create-dmg \
--volname "$(appName)" \
--volname "$(APP_NAME)" \
--window-pos 200 120 \
--window-size 720 300 \
--icon-size 96 \
--text-size 12 \
--icon "$(appName).app" 278 102 \
--icon "$(APP_NAME).app" 278 102 \
--icon "LICENSE" 441 102 \
--icon "README.md" 604 102 \
--app-drop-link 115 102 \
--hide-extension "$(appName).app" \
"$(macosIntelRelease)" \
"$(releaseFolder)" || true
@echo "Intel release created: $(macosIntelRelease)"
--hide-extension "$(APP_NAME).app" \
"$(MACOS_INTEL_RELEASE)" \
"$(RELEASE_FOLDER)" || true
@echo "Release Intel creado: $(MACOS_INTEL_RELEASE)"
# Build APPLE SILICON with RELEASE_BUILD flag
clang++ $(source) -Isource -D MACOS_BUNDLE -D RELEASE_BUILD -std=$(cpp_standard) -Wall -Os -framework SDL3 -F ./Frameworks -framework OpenGL -Wno-deprecated -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target arm64-apple-macos11
# Compila la versión para procesadores Apple Silicon
clang++ $(APP_SOURCES) $(INCLUDES) -DMACOS_BUNDLE -DRELEASE_BUILD -std=$(CPP_STANDARD) -Wall -Os -framework SDL3 -F ./Frameworks -framework OpenGL -Wno-deprecated -ffunction-sections -fdata-sections -o "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/MacOS/$(TARGET_NAME)" -rpath @executable_path/../Frameworks/ -target arm64-apple-macos11
# Code sign the Apple Silicon application
codesign --deep --force --sign - --timestamp=none "$(releaseFolder)/$(appName).app"
# Firma la aplicación
codesign --deep --force --sign - --timestamp=none "$(RELEASE_FOLDER)/$(APP_NAME).app"
# Build APPLE SILICON DMG with create-dmg
@echo "Creating Apple Silicon DMG with 96x96 icons..."
# Empaqueta el .dmg de la versión Apple Silicon con create-dmg
@echo "Creando DMG Apple Silicon con iconos de 96x96..."
create-dmg \
--volname "$(appName)" \
--volname "$(APP_NAME)" \
--window-pos 200 120 \
--window-size 720 300 \
--icon-size 96 \
--text-size 12 \
--icon "$(appName).app" 278 102 \
--icon "$(APP_NAME).app" 278 102 \
--icon "LICENSE" 441 102 \
--icon "README.md" 604 102 \
--app-drop-link 115 102 \
--hide-extension "$(appName).app" \
"$(macosAppleSiliconRelease)" \
"$(releaseFolder)" || true
@echo "Apple Silicon release created: $(macosAppleSiliconRelease)"
--hide-extension "$(APP_NAME).app" \
"$(MACOS_APPLE_SILICON_RELEASE)" \
"$(RELEASE_FOLDER)" || true
@echo "Release Apple Silicon creado: $(MACOS_APPLE_SILICON_RELEASE)"
# Remove data
rm -rdf Frameworks
rm -rdf "$(releaseFolder)"
# Elimina las carpetas temporales
$(RMDIR) Frameworks
$(RMDIR) "$(RELEASE_FOLDER)"
# ==============================================================================
# COMPILACIÓN PARA LINUX
# ==============================================================================
linux:
g++ $(source) -Isource -std=$(cpp_standard) -Wall -Os -lSDL3 -lGL -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)"
strip -s -R .comment -R .gnu.version "$(executable)" --strip-unneeded
@echo "Compilando para Linux: $(TARGET_NAME)"
g++ $(APP_SOURCES) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(TARGET_FILE)"
strip -s -R .comment -R .gnu.version "$(TARGET_FILE)" --strip-unneeded
linux_debug:
g++ $(source) -Isource -D DEBUG -std=$(cpp_standard) -Wall -Os -lSDL3 -lGL -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)_debug"
strip -s -R .comment -R .gnu.version "$(executable)_debug" --strip-unneeded
@echo "Compilando version debug para Linux: $(TARGET_NAME)_debug"
g++ $(APP_SOURCES) $(INCLUDES) -DDEBUG -DVERBOSE $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug"
linux_release:
# Build packing tool and create resources.pack
@$(MAKE) pack_tool
@$(MAKE) resources.pack
@echo "Creando release para Linux - Version: $(VERSION)"
# Generate version.h from version.h.in
@echo "Generating version.h..."
@echo "Generando version.h..."
@GIT_HASH=$$(git rev-parse --short=7 HEAD 2>/dev/null || echo "unknown"); \
sed "s/@GIT_HASH@/$$GIT_HASH/g" source/version.h.in > source/version.h
# Remove data
rm -rdf "$(releaseFolder)"
# Elimina carpetas previas
$(RMDIR) "$(RELEASE_FOLDER)"
# Create folders
mkdir -p "$(releaseFolder)"
# Crea la carpeta temporal para realizar el lanzamiento
$(MKDIR) "$(RELEASE_FOLDER)"
# Copy resources.pack instead of data folder
cp resources.pack "$(releaseFolder)"
cp LICENSE "$(releaseFolder)"
cp README.md "$(releaseFolder)"
cp gamecontrollerdb.txt "$(releaseFolder)"
# Copia ficheros
cp resources.pack "$(RELEASE_FOLDER)"
cp LICENSE "$(RELEASE_FOLDER)"
cp README.md "$(RELEASE_FOLDER)"
cp gamecontrollerdb.txt "$(RELEASE_FOLDER)"
# Build with RELEASE_BUILD flag
g++ $(source) -Isource -D RELEASE_BUILD -std=$(cpp_standard) -Wall -Os -lSDL3 -lGL -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(releaseFolder)/$(executable)"
strip -s -R .comment -R .gnu.version "$(releaseFolder)/$(executable)" --strip-unneeded
# Compila
g++ $(APP_SOURCES) $(INCLUDES) -DRELEASE_BUILD $(CXXFLAGS) $(LDFLAGS) -o "$(RELEASE_FILE)"
strip -s -R .comment -R .gnu.version "$(RELEASE_FILE)" --strip-unneeded
# Pack files
rm -f "$(linuxRelease)"
cd "$(releaseFolder)" && tar -czvf "../$(linuxRelease)" *
# Empaqueta ficheros
$(RMFILE) "$(LINUX_RELEASE)"
tar -czvf "$(LINUX_RELEASE)" -C "$(RELEASE_FOLDER)" .
@echo "Release creado: $(LINUX_RELEASE)"
# Remove data
rm -rdf "$(releaseFolder)"
# Elimina la carpeta temporal
$(RMDIR) "$(RELEASE_FOLDER)"
# ==============================================================================
# REGLAS ESPECIALES
# ==============================================================================
FORCE:
.PHONY: windows windows_debug windows_release macos macos_debug macos_release linux linux_debug linux_release pack_tool resources.pack

Binary file not shown.

Binary file not shown.

View File

@@ -30,10 +30,14 @@ auto loadAnimationsFromFile(const std::string& file_path) -> Animations {
std::vector<std::string> buffer;
std::string line;
while (std::getline(stream, line)) {
if (!line.empty()) {
buffer.push_back(line);
}
}
// Eliminar \r de Windows line endings
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
if (!line.empty()) {
buffer.push_back(line);
}
}
return buffer;
}

View File

@@ -41,17 +41,37 @@ auto loadTextFile(const std::string& file_path) -> std::shared_ptr<TextFile> {
// Lee los dos primeros valores del fichero
std::getline(stream, buffer);
// Remove Windows line ending if present
if (!buffer.empty() && buffer.back() == '\r') {
buffer.pop_back();
}
std::getline(stream, buffer);
// Remove Windows line ending if present
if (!buffer.empty() && buffer.back() == '\r') {
buffer.pop_back();
}
tf->box_width = std::stoi(buffer);
std::getline(stream, buffer);
// Remove Windows line ending if present
if (!buffer.empty() && buffer.back() == '\r') {
buffer.pop_back();
}
std::getline(stream, buffer);
// Remove Windows line ending if present
if (!buffer.empty() && buffer.back() == '\r') {
buffer.pop_back();
}
tf->box_height = std::stoi(buffer);
// lee el resto de datos del fichero
auto index = 32;
auto line_read = 0;
while (std::getline(stream, buffer)) {
// Remove Windows line ending if present
if (!buffer.empty() && buffer.back() == '\r') {
buffer.pop_back();
}
// Almacena solo las lineas impares
if (line_read % 2 == 1) {
tf->offset[index++].w = std::stoi(buffer);

View File

@@ -8,19 +8,19 @@
#include <stdexcept> // Para runtime_error
#include <utility>
#include "core/rendering/screen.hpp" // Para Screen
#include "core/rendering/text.hpp" // Para Text, loadTextFile
#include "core/resources/asset.hpp" // Para AssetType, Asset
#include "core/rendering/screen.hpp" // Para Screen
#include "core/rendering/text.hpp" // Para Text, loadTextFile
#include "core/resources/asset.hpp" // Para AssetType, Asset
#include "core/resources/resource_helper.hpp" // Para ResourceHelper
#include "external/jail_audio.h" // Para JA_DeleteMusic, JA_DeleteSound, JA_Loa...
#include "game/gameplay/room.hpp" // Para RoomData, loadRoomFile, loadRoomTileFile
#include "game/options.hpp" // Para Options, OptionsGame, options
#include "game/defaults.hpp" // Para GameDefaults::VERSION
#include "utils/defines.hpp" // Para WINDOW_CAPTION
#include "utils/utils.hpp" // Para getFileName, printWithDots, PaletteColor
#include "version.h" // Para Version::GIT_HASH
struct JA_Music_t; // lines 17-17
struct JA_Sound_t; // lines 18-18
#include "external/jail_audio.h" // Para JA_DeleteMusic, JA_DeleteSound, JA_Loa...
#include "game/defaults.hpp" // Para GameDefaults::VERSION
#include "game/gameplay/room.hpp" // Para RoomData, loadRoomFile, loadRoomTileFile
#include "game/options.hpp" // Para Options, OptionsGame, options
#include "utils/defines.hpp" // Para WINDOW_CAPTION
#include "utils/utils.hpp" // Para getFileName, printWithDots, PaletteColor
#include "version.h" // Para Version::GIT_HASH
struct JA_Music_t; // lines 17-17
struct JA_Sound_t; // lines 18-18
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
Resource* Resource::resource = nullptr;
@@ -406,21 +406,23 @@ void Resource::calculateTotal() {
// Muestra el progreso de carga
void Resource::renderProgress() {
constexpr float X_PADDING = 10;
constexpr float Y_PADDING = 10;
constexpr float BAR_HEIGHT = 10;
constexpr float X_PADDING = 60.0F;
constexpr float Y_PADDING = 10.0F;
constexpr float BAR_HEIGHT = 5.0F;
const float BAR_POSITION = Options::game.height - BAR_HEIGHT - Y_PADDING;
Screen::get()->start();
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
auto surface = Screen::get()->getRendererSurface();
const Uint8 TEXT_COLOR = static_cast<Uint8>(PaletteColor::WHITE);
const Uint8 TEXT_COLOR = static_cast<Uint8>(PaletteColor::BRIGHT_WHITE);
const Uint8 BAR_COLOR = static_cast<Uint8>(PaletteColor::WHITE);
const int TEXT_HEIGHT = loading_text_->getCharacterSize();
const int CENTER_X = Options::game.width / 2;
const int CENTER_Y = Options::game.height / 2;
// Draw APP_NAME centered above center
const std::string APP_NAME = WINDOW_CAPTION;
const std::string APP_NAME = spaceBetweenLetters(Version::APP_NAME);
loading_text_->writeColored(
CENTER_X - (loading_text_->lenght(APP_NAME) / 2),
CENTER_Y - TEXT_HEIGHT,
@@ -437,13 +439,13 @@ void Resource::renderProgress() {
// Draw progress bar border
const float WIRED_BAR_WIDTH = Options::game.width - (X_PADDING * 2);
SDL_FRect rect_wired = {X_PADDING, BAR_POSITION, WIRED_BAR_WIDTH, X_PADDING};
surface->drawRectBorder(&rect_wired, TEXT_COLOR);
SDL_FRect rect_wired = {X_PADDING, BAR_POSITION, WIRED_BAR_WIDTH, BAR_HEIGHT};
surface->drawRectBorder(&rect_wired, BAR_COLOR);
// Draw progress bar fill
const float FULL_BAR_WIDTH = WIRED_BAR_WIDTH * count_.getPercentage();
SDL_FRect rect_full = {X_PADDING, BAR_POSITION, FULL_BAR_WIDTH, X_PADDING};
surface->fillRect(&rect_full, TEXT_COLOR);
SDL_FRect rect_full = {X_PADDING, BAR_POSITION, FULL_BAR_WIDTH, BAR_HEIGHT};
surface->fillRect(&rect_full, BAR_COLOR);
Screen::get()->render();
}

View File

@@ -6,6 +6,7 @@
#include <string>
#include <vector>
#include <cstdint>
namespace jdd {
namespace ResourceHelper {

View File

@@ -62,11 +62,6 @@ constexpr bool SOUND_ENABLED = true; // Sonido habilitado por defecto
constexpr bool NOTIFICATION_SOUND = true; // Sonido de las notificaciones por defecto
const Uint8 NOTIFICATION_COLOR = static_cast<Uint8>(PaletteColor::BLUE); // Color de las notificaciones por defecto
// =============================================================================
// CONTROL
// =============================================================================
constexpr Options::ControlScheme CONTROL_SCHEME = Options::ControlScheme::CURSOR; // Control por defecto
// =============================================================================
// OTHER
// =============================================================================

View File

@@ -962,15 +962,28 @@ auto Room::loadRoomTileFile(const std::string& file_path, bool verbose) -> std::
if (line.find("data encoding") != std::string::npos) {
// Lee la primera linea
std::getline(stream, line);
// Trim line to handle Windows line endings
line.erase(0, line.find_first_not_of(" \t\r\n"));
line.erase(line.find_last_not_of(" \t\r\n") + 1);
while (line != "</data>") { // Procesa lineas mientras haya
std::stringstream ss(line);
std::string tmp;
while (getline(ss, tmp, ',')) {
tile_map_file.push_back(std::stoi(tmp) - 1);
// Trim whitespace (including \r, \n, spaces, tabs)
tmp.erase(0, tmp.find_first_not_of(" \t\r\n"));
tmp.erase(tmp.find_last_not_of(" \t\r\n") + 1);
// Skip empty strings (from trailing commas)
if (!tmp.empty()) {
tile_map_file.push_back(std::stoi(tmp) - 1);
}
}
// Lee la siguiente linea
std::getline(stream, line);
// Trim line to handle Windows line endings
line.erase(0, line.find_first_not_of(" \t\r\n"));
line.erase(line.find_last_not_of(" \t\r\n") + 1);
}
}
}
@@ -1009,6 +1022,10 @@ auto Room::loadRoomFile(const std::string& file_path, bool verbose) -> Data {
// Procesa el fichero linea a linea
while (std::getline(stream, line)) {
// Remove Windows line ending if present
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
// Si la linea contiene el texto [enemy] se realiza el proceso de carga de un enemigo
if (line == "[enemy]") {
room.enemies.push_back(loadEnemyFromFile(stream, FILE_NAME, verbose));
@@ -1062,6 +1079,10 @@ auto Room::loadEnemyFromFile(std::istream& file, const std::string& file_name, b
std::string line;
do {
std::getline(file, line);
// Remove Windows line ending if present
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
auto [key, value] = parseKeyValue(line);
if (!setEnemy(&enemy, key, value)) {
@@ -1082,6 +1103,10 @@ auto Room::loadItemFromFile(std::istream& file, const std::string& file_name, bo
std::string line;
do {
std::getline(file, line);
// Remove Windows line ending if present
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
auto [key, value] = parseKeyValue(line);
if (!setItem(&item, key, value)) {

View File

@@ -104,6 +104,10 @@ auto Stats::loadFromFile(const std::string& file_path, std::vector<StatsData>& l
std::string line;
// Procesa el fichero linea a linea
while (std::getline(file, line)) {
// Remove Windows line ending if present
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
// Comprueba que la linea no sea un comentario
if (line.substr(0, 1) != "#") {
StatsData stat;

View File

@@ -183,14 +183,6 @@ auto saveToFile(const std::string& file_path) -> bool {
auto setOptions(const std::string& var, const std::string& value) -> bool {
static const std::unordered_map<std::string, std::function<void(const std::string&)>> OPTION_HANDLERS = {
{"version", [](const std::string& v) { version = v; }},
{"keys", [](const std::string& v) {
int val = safeStoi(v, static_cast<int>(GameDefaults::CONTROL_SCHEME));
if (val == static_cast<int>(ControlScheme::CURSOR) || val == static_cast<int>(ControlScheme::OPQA) || val == static_cast<int>(ControlScheme::WASD)) {
keys = static_cast<ControlScheme>(val);
} else {
keys = GameDefaults::CONTROL_SCHEME;
}
}},
{"window.zoom", [](const std::string& v) {
int val = safeStoi(v, GameDefaults::WINDOW_ZOOM);
if (val > 0) {

View File

@@ -88,9 +88,9 @@ struct Stats {
// Estructura con opciones de la ventana
struct Window {
std::string caption{WINDOW_CAPTION}; // Texto que aparece en la barra de título de la ventana
int zoom{GameDefaults::WINDOW_ZOOM}; // Zoom de la ventana
int max_zoom{GameDefaults::WINDOW_ZOOM}; // Máximo tamaño de zoom para la ventana
std::string caption{WINDOW_CAPTION}; // Texto que aparece en la barra de título de la ventana
int zoom{GameDefaults::WINDOW_ZOOM}; // Zoom de la ventana
int max_zoom{GameDefaults::WINDOW_ZOOM}; // Máximo tamaño de zoom para la ventana
// Constructor por defecto
Window() = default;
@@ -206,16 +206,16 @@ struct Game {
};
// --- Variables globales (inline C++17+) ---
inline std::string version{}; // Versión del fichero de configuración. Sirve para saber si las opciones son compatibles
inline bool console{false}; // Indica si ha de mostrar información por la consola de texto
inline Cheat cheats{}; // Contiene trucos y ventajas para el juego
inline Game game{}; // Opciones de juego
inline Video video{}; // Opciones de video
inline Stats stats{}; // Datos con las estadisticas de juego
inline Notification notifications{}; // Opciones relativas a las notificaciones;
inline Window window{}; // Opciones relativas a la ventana
inline Audio audio{}; // Opciones relativas al audio
inline ControlScheme keys{GameDefaults::CONTROL_SCHEME}; // Teclas usadas para jugar
inline std::string version{}; // Versión del fichero de configuración. Sirve para saber si las opciones son compatibles
inline bool console{false}; // Indica si ha de mostrar información por la consola de texto
inline Cheat cheats{}; // Contiene trucos y ventajas para el juego
inline Game game{}; // Opciones de juego
inline Video video{}; // Opciones de video
inline Stats stats{}; // Datos con las estadisticas de juego
inline Notification notifications{}; // Opciones relativas a las notificaciones;
inline Window window{}; // Opciones relativas a la ventana
inline Audio audio{}; // Opciones relativas al audio
inline ControlScheme keys{ControlScheme::CURSOR}; // Teclas usadas para jugar
// --- Funciones ---
void init(); // Crea e inicializa las opciones del programa

View File

@@ -449,4 +449,16 @@ void fillTextureWithColor(SDL_Renderer* renderer, SDL_Texture* texture, Uint8 r,
// Restaurar el render target previo
SDL_SetRenderTarget(renderer, previous_target);
}
// Añade espacios entre las letras de un string
auto spaceBetweenLetters(const std::string& input) -> std::string {
std::string result;
for (size_t i = 0; i < input.size(); ++i) {
result += input[i];
if (i != input.size() - 1) {
result += ' ';
}
}
return result;
}

View File

@@ -168,4 +168,7 @@ inline auto toSDLPoint(const SDL_FPoint& fpoint) -> SDL_Point {
.x = static_cast<int>(fpoint.x),
.y = static_cast<int>(fpoint.y)};
return point;
}
}
// Añade espacios entre las letras de un string
auto spaceBetweenLetters(const std::string& input) -> std::string;