diff --git a/.gitignore b/.gitignore index 68db7eb..cdddd9d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,9 @@ build build_rel +build_web +emsdk +deploy_web +butler screenshots build.bat run.bat diff --git a/CMakeLists.txt b/CMakeLists.txt index a7ee023..c1684b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ if(MSVC) endif() if (EMSCRIPTEN) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s INITIAL_MEMORY=268435456 -s FORCE_FILESYSTEM=1 --preload-file ${CMAKE_SOURCE_DIR}/art@art/") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s INITIAL_MEMORY=268435456 -s FORCE_FILESYSTEM=1 --preload-file ${CMAKE_SOURCE_DIR}/art@art/ --shell-file ${CMAKE_SOURCE_DIR}/web/eco2d.html") set(CMAKE_EXECUTABLE_SUFFIX ".html") # This line is used to set your executable to build with the emscripten html template so that you can directly open it. set(CMAKE_COMPILE_WARNING_AS_ERROR OFF) set(CMAKE_CXX_) diff --git a/code/game/src/platform_raylib.c b/code/game/src/platform_raylib.c index 55a0b2c..a8523b6 100644 --- a/code/game/src/platform_raylib.c +++ b/code/game/src/platform_raylib.c @@ -13,8 +13,8 @@ #include "debug_ui.h" #include "utils/raylib_helpers.h" -static uint16_t screenWidth = 1600; -static uint16_t screenHeight = 900; +static uint16_t screenWidth = 1024; +static uint16_t screenHeight = 768; static float target_zoom = 1.5f; static bool request_shutdown; @@ -29,9 +29,11 @@ void platform_init() { SetTraceLogLevel(LOG_ERROR); InitWindow(screenWidth, screenHeight, "eco2d"); SetWindowState(/*FLAG_WINDOW_UNDECORATED|*/FLAG_WINDOW_MAXIMIZED|FLAG_WINDOW_RESIZABLE|FLAG_MSAA_4X_HINT); - + +#if !defined(PLATFORM_WEB) screenWidth = (uint16_t)GetScreenWidth(); screenHeight = (uint16_t)GetScreenHeight(); +#endif // ToggleFullscreen(); // SetTargetFPS(60.0); diff --git a/deploy_web.sh b/deploy_web.sh new file mode 100755 index 0000000..4e0eefc --- /dev/null +++ b/deploy_web.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +set -xe + +if [ ! -d "build_web" ]; then + echo "Build directory not found. Run setup_web.sh first." + exit 1 +fi + +if [ ! -d "butler" ]; then + mkdir butler + wget https://broth.itch.ovh/butler/linux-amd64/LATEST/archive/default -O butler.zip + mv butler.zip butler/ + pushd butler/ + unzip butler.zip + rm -rf butler.zip + chmod +x ./butler + ./butler -V + popd +fi + +# Build web +if [ -f "build_web/eco2d.html" ]; then + rm -rf build_web/eco2d.html +fi +cmake --build build_web + +# Package all assets +if [ ! -f "build_web/eco2d.html" ]; then + echo "Build data not found. Compilation errors?" + exit 1 +fi + +mkdir deploy_web +cp build_web/eco2d.* deploy_web/ +pushd deploy_web/ + mv eco2d.html index.html +popd + +# Deploy to itch.io +./butler/butler push deploy_web/ zaklaus/eco2d:html-latest + +# Teardown +rm -rf deploy_web diff --git a/run_web.sh b/run_web.sh new file mode 100755 index 0000000..d988bde --- /dev/null +++ b/run_web.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -xe + +python -m http.server --directory build_web --bind 127.0.0.1 diff --git a/setup_web.sh b/setup_web.sh new file mode 100755 index 0000000..d2d5a5d --- /dev/null +++ b/setup_web.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -xe + +# Setup emsdk +if [ ! -d "emsdk" ]; then + wget https://github.com/emscripten-core/emsdk/archive/refs/heads/main.zip -O emscripten.zip + unzip emscripten.zip + mv emsdk-main emsdk + rm -rf emscripten.zip +fi + +source ./emsdk/emsdk_env.sh +emsdk update +emsdk install latest +emsdk activate latest +source ./emsdk/emsdk_env.sh + +# Setup web build +emcmake cmake -S . -B build_web -DCMAKE_BUILD_TYPE=Debug -DPLATFORM=Web diff --git a/web/eco2d.html b/web/eco2d.html new file mode 100644 index 0000000..693f771 --- /dev/null +++ b/web/eco2d.html @@ -0,0 +1,85 @@ + + + + + + + eco2d web game + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + {{{ SCRIPT }}} + +