4 Commits

15 changed files with 392 additions and 182 deletions

2
.gitignore vendored
View File

@@ -17,3 +17,5 @@ build/
linux_utils/ linux_utils/
.claude/ .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") # DIRECTORIES
appName = JailDoctor's Dilemma # ==============================================================================
releaseFolder = jdd_release 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) ifeq ($(OS),Windows_NT)
VERSION := $(shell powershell -Command "Get-Date -Format 'yyyy-MM-dd'") VERSION := $(shell powershell -Command "Get-Date -Format 'yyyy-MM-dd'")
else else
VERSION := $(shell date +%Y-%m-%d) VERSION := $(shell date +%Y-%m-%d)
endif endif
# Release names # ==============================================================================
windowsRelease = $(executable)-$(VERSION)-win32-x64.zip # WINDOWS-SPECIFIC VARIABLES
macosIntelRelease = $(executable)-$(VERSION)-macos-intel.dmg # ==============================================================================
macosAppleSiliconRelease = $(executable)-$(VERSION)-macos-apple-silicon.dmg ifeq ($(OS),Windows_NT)
linuxRelease = $(executable)-$(VERSION)-linux.tar.gz 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 # SOURCE FILES
packToolSource = tools/pack_resources/pack_resources.cpp source/core/resources/resource_pack.cpp # ==============================================================================
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: # INCLUDES
@echo "Building pack_resources tool..." # ==============================================================================
@cd tools/pack_resources && $(MAKE) INCLUDES := -Isource
# Create resources.pack from data directory # ==============================================================================
resources.pack: pack_tool # COMPILER FLAGS (OS-specific)
@echo "Creating resources.pack..." # ==============================================================================
@$(packTool) data resources.pack 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: windows:
@echo off @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" @echo Compilando para Windows con nombre: "$(WIN_TARGET_FILE).exe"
strip -s -R .comment -R .gnu.version "$(executable).exe" --strip-unneeded 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: windows_debug:
@echo off @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" @echo Compilando version debug para Windows: "$(WIN_TARGET_FILE)_debug.exe"
strip -s -R .comment -R .gnu.version "$(executable)_debug.exe" --strip-unneeded g++ $(APP_SOURCES) $(INCLUDES) -DDEBUG -DVERBOSE $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(WIN_TARGET_FILE)_debug.exe"
windows_release: windows_release:
@echo off
# Build packing tool and create resources.pack
@$(MAKE) pack_tool @$(MAKE) pack_tool
@$(MAKE) resources.pack @$(MAKE) resources.pack
@echo off
@echo Creando release para Windows - Version: $(VERSION)
# Generate version.h from version.h.in # 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" @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 # Crea carpeta temporal 'RELEASE_FOLDER'
powershell if (Test-Path "$(releaseFolder)") {Remove-Item "$(releaseFolder)" -Recurse -Force} powershell if (Test-Path "$(RELEASE_FOLDER)") {Remove-Item "$(RELEASE_FOLDER)" -Recurse -Force}
powershell if (-not (Test-Path "$(releaseFolder)")) {New-Item "$(releaseFolder)" -ItemType Directory} powershell if (-not (Test-Path "$(RELEASE_FOLDER)")) {New-Item "$(RELEASE_FOLDER)" -ItemType Directory}
# Copy resources.pack instead of data folder # Copia el archivo 'resources.pack'
powershell Copy-Item "resources.pack" -Destination "$(releaseFolder)" powershell Copy-Item -Path "resources.pack" -Destination "$(RELEASE_FOLDER)"
# Copy root files # Copia los ficheros que están en la raíz del proyecto
powershell Copy-Item "LICENSE" -Destination "$(releaseFolder)" powershell Copy-Item "LICENSE" -Destination "$(RELEASE_FOLDER)"
powershell Copy-Item "README.md" -Destination "$(releaseFolder)" powershell Copy-Item "README.md" -Destination "$(RELEASE_FOLDER)"
powershell Copy-Item "gamecontrollerdb.txt" -Destination "$(releaseFolder)" powershell Copy-Item "gamecontrollerdb.txt" -Destination "$(RELEASE_FOLDER)"
powershell Copy-Item "release\*.dll" -Destination "$(releaseFolder)" powershell Copy-Item "release\*.dll" -Destination "$(RELEASE_FOLDER)"
# Build with RELEASE_BUILD flag (include jdd.res for icon) # Compila (con icono)
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" windres release/jdd.rc -O coff -o $(RESOURCE_FILE)
strip -s -R .comment -R .gnu.version "$(releaseFolder)/$(executable).exe" --strip-unneeded 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 # Crea el fichero .zip
powershell if (Test-Path $(windowsRelease)) {Remove-Item $(windowsRelease)} powershell if (Test-Path "$(WINDOWS_RELEASE)") {Remove-Item "$(WINDOWS_RELEASE)"}
powershell Compress-Archive -Path "$(releaseFolder)"/* -DestinationPath $(windowsRelease) powershell Compress-Archive -Path "$(RELEASE_FOLDER)"/* -DestinationPath "$(WINDOWS_RELEASE)"
@echo Release creado: $(WINDOWS_RELEASE)
# Remove folder # Elimina la carpeta temporal 'RELEASE_FOLDER'
powershell if (Test-Path "$(releaseFolder)") {Remove-Item "$(releaseFolder)" -Recurse -Force} powershell if (Test-Path "$(RELEASE_FOLDER)") {Remove-Item "$(RELEASE_FOLDER)" -Recurse -Force}
# ==============================================================================
# COMPILACIÓN PARA MACOS
# ==============================================================================
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: 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: macos_release:
# Build packing tool and create resources.pack
@$(MAKE) pack_tool @$(MAKE) pack_tool
@$(MAKE) resources.pack @$(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 # 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"); \ @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 sed "s/@GIT_HASH@/$$GIT_HASH/g" source/version.h.in > source/version.h
# Verify and install create-dmg if necessary # Elimina datos de compilaciones anteriores
@which create-dmg > /dev/null || (echo "Installing create-dmg..." && brew install create-dmg) $(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 # Crea la carpeta temporal para hacer el trabajo y las carpetas obligatorias para crear una app de macOS
rm -rdf "$(releaseFolder)" $(MKDIR) "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Frameworks"
rm -rdf Frameworks $(MKDIR) "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/MacOS"
rm -f tmp.dmg $(MKDIR) "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources"
rm -f "$(macosIntelRelease)" $(MKDIR) Frameworks
rm -f "$(macosAppleSiliconRelease)"
# Create folders # Copia carpetas y ficheros
mkdir -p "$(releaseFolder)/$(appName).app/Contents/Frameworks" cp resources.pack "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources"
mkdir -p "$(releaseFolder)/$(appName).app/Contents/MacOS" cp gamecontrollerdb.txt "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources"
mkdir -p "$(releaseFolder)/$(appName).app/Contents/Resources" cp -R release/frameworks/SDL3.xcframework/macos-arm64_x86_64/SDL3.framework "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Frameworks"
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"
cp -R release/frameworks/SDL3.xcframework/macos-arm64_x86_64/SDL3.framework 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 # Compila la versión para procesadores Intel
cp release/*.icns "$(releaseFolder)/$(appName).app/Contents/Resources" 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
cp release/Info.plist "$(releaseFolder)/$(appName).app/Contents"
cp LICENSE "$(releaseFolder)"
cp README.md "$(releaseFolder)"
# Build INTEL with RELEASE_BUILD flag # Firma la aplicación
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 codesign --deep --force --sign - --timestamp=none "$(RELEASE_FOLDER)/$(APP_NAME).app"
# Code sign the Intel application # Empaqueta el .dmg de la versión Intel con create-dmg
codesign --deep --force --sign - --timestamp=none "$(releaseFolder)/$(appName).app" @echo "Creando DMG Intel con iconos de 96x96..."
# Build INTEL DMG with create-dmg
@echo "Creating Intel DMG with 96x96 icons..."
create-dmg \ create-dmg \
--volname "$(appName)" \ --volname "$(APP_NAME)" \
--window-pos 200 120 \ --window-pos 200 120 \
--window-size 720 300 \ --window-size 720 300 \
--icon-size 96 \ --icon-size 96 \
--text-size 12 \ --text-size 12 \
--icon "$(appName).app" 278 102 \ --icon "$(APP_NAME).app" 278 102 \
--icon "LICENSE" 441 102 \ --icon "LICENSE" 441 102 \
--icon "README.md" 604 102 \ --icon "README.md" 604 102 \
--app-drop-link 115 102 \ --app-drop-link 115 102 \
--hide-extension "$(appName).app" \ --hide-extension "$(APP_NAME).app" \
"$(macosIntelRelease)" \ "$(MACOS_INTEL_RELEASE)" \
"$(releaseFolder)" || true "$(RELEASE_FOLDER)" || true
@echo "Intel release created: $(macosIntelRelease)" @echo "Release Intel creado: $(MACOS_INTEL_RELEASE)"
# Build APPLE SILICON with RELEASE_BUILD flag # Compila la versión para procesadores Apple Silicon
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 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 # Firma la aplicación
codesign --deep --force --sign - --timestamp=none "$(releaseFolder)/$(appName).app" codesign --deep --force --sign - --timestamp=none "$(RELEASE_FOLDER)/$(APP_NAME).app"
# Build APPLE SILICON DMG with create-dmg # Empaqueta el .dmg de la versión Apple Silicon con create-dmg
@echo "Creating Apple Silicon DMG with 96x96 icons..." @echo "Creando DMG Apple Silicon con iconos de 96x96..."
create-dmg \ create-dmg \
--volname "$(appName)" \ --volname "$(APP_NAME)" \
--window-pos 200 120 \ --window-pos 200 120 \
--window-size 720 300 \ --window-size 720 300 \
--icon-size 96 \ --icon-size 96 \
--text-size 12 \ --text-size 12 \
--icon "$(appName).app" 278 102 \ --icon "$(APP_NAME).app" 278 102 \
--icon "LICENSE" 441 102 \ --icon "LICENSE" 441 102 \
--icon "README.md" 604 102 \ --icon "README.md" 604 102 \
--app-drop-link 115 102 \ --app-drop-link 115 102 \
--hide-extension "$(appName).app" \ --hide-extension "$(APP_NAME).app" \
"$(macosAppleSiliconRelease)" \ "$(MACOS_APPLE_SILICON_RELEASE)" \
"$(releaseFolder)" || true "$(RELEASE_FOLDER)" || true
@echo "Apple Silicon release created: $(macosAppleSiliconRelease)" @echo "Release Apple Silicon creado: $(MACOS_APPLE_SILICON_RELEASE)"
# Remove data # Elimina las carpetas temporales
rm -rdf Frameworks $(RMDIR) Frameworks
rm -rdf "$(releaseFolder)" $(RMDIR) "$(RELEASE_FOLDER)"
# ==============================================================================
# COMPILACIÓN PARA LINUX
# ==============================================================================
linux: linux:
g++ $(source) -Isource -std=$(cpp_standard) -Wall -Os -lSDL3 -lGL -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)" @echo "Compilando para Linux: $(TARGET_NAME)"
strip -s -R .comment -R .gnu.version "$(executable)" --strip-unneeded g++ $(APP_SOURCES) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(TARGET_FILE)"
strip -s -R .comment -R .gnu.version "$(TARGET_FILE)" --strip-unneeded
linux_debug: linux_debug:
g++ $(source) -Isource -D DEBUG -std=$(cpp_standard) -Wall -Os -lSDL3 -lGL -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)_debug" @echo "Compilando version debug para Linux: $(TARGET_NAME)_debug"
strip -s -R .comment -R .gnu.version "$(executable)_debug" --strip-unneeded g++ $(APP_SOURCES) $(INCLUDES) -DDEBUG -DVERBOSE $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug"
linux_release: linux_release:
# Build packing tool and create resources.pack
@$(MAKE) pack_tool @$(MAKE) pack_tool
@$(MAKE) resources.pack @$(MAKE) resources.pack
@echo "Creando release para Linux - Version: $(VERSION)"
# Generate version.h from version.h.in # 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"); \ @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 sed "s/@GIT_HASH@/$$GIT_HASH/g" source/version.h.in > source/version.h
# Remove data # Elimina carpetas previas
rm -rdf "$(releaseFolder)" $(RMDIR) "$(RELEASE_FOLDER)"
# Create folders # Crea la carpeta temporal para realizar el lanzamiento
mkdir -p "$(releaseFolder)" $(MKDIR) "$(RELEASE_FOLDER)"
# Copy resources.pack instead of data folder # Copia ficheros
cp resources.pack "$(releaseFolder)" cp resources.pack "$(RELEASE_FOLDER)"
cp LICENSE "$(releaseFolder)" cp LICENSE "$(RELEASE_FOLDER)"
cp README.md "$(releaseFolder)" cp README.md "$(RELEASE_FOLDER)"
cp gamecontrollerdb.txt "$(releaseFolder)" cp gamecontrollerdb.txt "$(RELEASE_FOLDER)"
# Build with RELEASE_BUILD flag # Compila
g++ $(source) -Isource -D RELEASE_BUILD -std=$(cpp_standard) -Wall -Os -lSDL3 -lGL -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(releaseFolder)/$(executable)" g++ $(APP_SOURCES) $(INCLUDES) -DRELEASE_BUILD $(CXXFLAGS) $(LDFLAGS) -o "$(RELEASE_FILE)"
strip -s -R .comment -R .gnu.version "$(releaseFolder)/$(executable)" --strip-unneeded strip -s -R .comment -R .gnu.version "$(RELEASE_FILE)" --strip-unneeded
# Pack files # Empaqueta ficheros
rm -f "$(linuxRelease)" $(RMFILE) "$(LINUX_RELEASE)"
cd "$(releaseFolder)" && tar -czvf "../$(linuxRelease)" * tar -czvf "$(LINUX_RELEASE)" -C "$(RELEASE_FOLDER)" .
@echo "Release creado: $(LINUX_RELEASE)"
# Remove data # Elimina la carpeta temporal
rm -rdf "$(releaseFolder)" $(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,6 +30,10 @@ auto loadAnimationsFromFile(const std::string& file_path) -> Animations {
std::vector<std::string> buffer; std::vector<std::string> buffer;
std::string line; std::string line;
while (std::getline(stream, line)) { while (std::getline(stream, line)) {
// Eliminar \r de Windows line endings
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
if (!line.empty()) { if (!line.empty()) {
buffer.push_back(line); buffer.push_back(line);
} }

View File

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

View File

@@ -13,9 +13,9 @@
#include "core/resources/asset.hpp" // Para AssetType, Asset #include "core/resources/asset.hpp" // Para AssetType, Asset
#include "core/resources/resource_helper.hpp" // Para ResourceHelper #include "core/resources/resource_helper.hpp" // Para ResourceHelper
#include "external/jail_audio.h" // Para JA_DeleteMusic, JA_DeleteSound, JA_Loa... #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/gameplay/room.hpp" // Para RoomData, loadRoomFile, loadRoomTileFile
#include "game/options.hpp" // Para Options, OptionsGame, options #include "game/options.hpp" // Para Options, OptionsGame, options
#include "game/defaults.hpp" // Para GameDefaults::VERSION
#include "utils/defines.hpp" // Para WINDOW_CAPTION #include "utils/defines.hpp" // Para WINDOW_CAPTION
#include "utils/utils.hpp" // Para getFileName, printWithDots, PaletteColor #include "utils/utils.hpp" // Para getFileName, printWithDots, PaletteColor
#include "version.h" // Para Version::GIT_HASH #include "version.h" // Para Version::GIT_HASH
@@ -406,21 +406,23 @@ void Resource::calculateTotal() {
// Muestra el progreso de carga // Muestra el progreso de carga
void Resource::renderProgress() { void Resource::renderProgress() {
constexpr float X_PADDING = 10; constexpr float X_PADDING = 60.0F;
constexpr float Y_PADDING = 10; constexpr float Y_PADDING = 10.0F;
constexpr float BAR_HEIGHT = 10; constexpr float BAR_HEIGHT = 5.0F;
const float BAR_POSITION = Options::game.height - BAR_HEIGHT - Y_PADDING; const float BAR_POSITION = Options::game.height - BAR_HEIGHT - Y_PADDING;
Screen::get()->start(); Screen::get()->start();
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK)); Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
auto surface = Screen::get()->getRendererSurface(); 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 TEXT_HEIGHT = loading_text_->getCharacterSize();
const int CENTER_X = Options::game.width / 2; const int CENTER_X = Options::game.width / 2;
const int CENTER_Y = Options::game.height / 2; const int CENTER_Y = Options::game.height / 2;
// Draw APP_NAME centered above center // 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( loading_text_->writeColored(
CENTER_X - (loading_text_->lenght(APP_NAME) / 2), CENTER_X - (loading_text_->lenght(APP_NAME) / 2),
CENTER_Y - TEXT_HEIGHT, CENTER_Y - TEXT_HEIGHT,
@@ -437,13 +439,13 @@ void Resource::renderProgress() {
// Draw progress bar border // Draw progress bar border
const float WIRED_BAR_WIDTH = Options::game.width - (X_PADDING * 2); const float WIRED_BAR_WIDTH = Options::game.width - (X_PADDING * 2);
SDL_FRect rect_wired = {X_PADDING, BAR_POSITION, WIRED_BAR_WIDTH, X_PADDING}; SDL_FRect rect_wired = {X_PADDING, BAR_POSITION, WIRED_BAR_WIDTH, BAR_HEIGHT};
surface->drawRectBorder(&rect_wired, TEXT_COLOR); surface->drawRectBorder(&rect_wired, BAR_COLOR);
// Draw progress bar fill // Draw progress bar fill
const float FULL_BAR_WIDTH = WIRED_BAR_WIDTH * count_.getPercentage(); const float FULL_BAR_WIDTH = WIRED_BAR_WIDTH * count_.getPercentage();
SDL_FRect rect_full = {X_PADDING, BAR_POSITION, FULL_BAR_WIDTH, X_PADDING}; SDL_FRect rect_full = {X_PADDING, BAR_POSITION, FULL_BAR_WIDTH, BAR_HEIGHT};
surface->fillRect(&rect_full, TEXT_COLOR); surface->fillRect(&rect_full, BAR_COLOR);
Screen::get()->render(); Screen::get()->render();
} }

View File

@@ -6,6 +6,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <cstdint>
namespace jdd { namespace jdd {
namespace ResourceHelper { 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 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 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 // 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) { if (line.find("data encoding") != std::string::npos) {
// Lee la primera linea // Lee la primera linea
std::getline(stream, line); 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 while (line != "</data>") { // Procesa lineas mientras haya
std::stringstream ss(line); std::stringstream ss(line);
std::string tmp; std::string tmp;
while (getline(ss, tmp, ',')) { while (getline(ss, tmp, ',')) {
// 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); tile_map_file.push_back(std::stoi(tmp) - 1);
} }
}
// Lee la siguiente linea // Lee la siguiente linea
std::getline(stream, line); 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 // Procesa el fichero linea a linea
while (std::getline(stream, line)) { 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 // Si la linea contiene el texto [enemy] se realiza el proceso de carga de un enemigo
if (line == "[enemy]") { if (line == "[enemy]") {
room.enemies.push_back(loadEnemyFromFile(stream, FILE_NAME, verbose)); 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; std::string line;
do { do {
std::getline(file, line); std::getline(file, line);
// Remove Windows line ending if present
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
auto [key, value] = parseKeyValue(line); auto [key, value] = parseKeyValue(line);
if (!setEnemy(&enemy, key, value)) { if (!setEnemy(&enemy, key, value)) {
@@ -1082,6 +1103,10 @@ auto Room::loadItemFromFile(std::istream& file, const std::string& file_name, bo
std::string line; std::string line;
do { do {
std::getline(file, line); std::getline(file, line);
// Remove Windows line ending if present
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
auto [key, value] = parseKeyValue(line); auto [key, value] = parseKeyValue(line);
if (!setItem(&item, key, value)) { 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; std::string line;
// Procesa el fichero linea a linea // Procesa el fichero linea a linea
while (std::getline(file, line)) { 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 // Comprueba que la linea no sea un comentario
if (line.substr(0, 1) != "#") { if (line.substr(0, 1) != "#") {
StatsData stat; 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 { 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 = { static const std::unordered_map<std::string, std::function<void(const std::string&)>> OPTION_HANDLERS = {
{"version", [](const std::string& v) { version = v; }}, {"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) { {"window.zoom", [](const std::string& v) {
int val = safeStoi(v, GameDefaults::WINDOW_ZOOM); int val = safeStoi(v, GameDefaults::WINDOW_ZOOM);
if (val > 0) { if (val > 0) {

View File

@@ -215,7 +215,7 @@ inline Stats stats{}; // Datos con las estad
inline Notification notifications{}; // Opciones relativas a las notificaciones; inline Notification notifications{}; // Opciones relativas a las notificaciones;
inline Window window{}; // Opciones relativas a la ventana inline Window window{}; // Opciones relativas a la ventana
inline Audio audio{}; // Opciones relativas al audio inline Audio audio{}; // Opciones relativas al audio
inline ControlScheme keys{GameDefaults::CONTROL_SCHEME}; // Teclas usadas para jugar inline ControlScheme keys{ControlScheme::CURSOR}; // Teclas usadas para jugar
// --- Funciones --- // --- Funciones ---
void init(); // Crea e inicializa las opciones del programa void init(); // Crea e inicializa las opciones del programa

View File

@@ -450,3 +450,15 @@ void fillTextureWithColor(SDL_Renderer* renderer, SDL_Texture* texture, Uint8 r,
// Restaurar el render target previo // Restaurar el render target previo
SDL_SetRenderTarget(renderer, previous_target); 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

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