Compare commits
108
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31ee7989de | ||
|
|
3948607b1e | ||
|
|
6c180372fe | ||
|
|
fed04b66b8 | ||
|
|
a4ca718070 | ||
|
|
8dbd3e1dd2 | ||
|
|
7a9a2b9832 | ||
|
|
e8757c33e3 | ||
|
|
b498a12458 | ||
|
|
c9f098693c | ||
|
|
7aeffac9fc | ||
|
|
37e7e95ace | ||
|
|
e3f56c4d12 | ||
|
|
3675ec634f | ||
|
|
d8273a225c | ||
|
|
c1c8174b27 | ||
|
|
5697f5c064 | ||
|
|
3ce16cf7f4 | ||
|
|
2abd5b0c3c | ||
|
|
4b29bf7a30 | ||
|
|
6f1bbe4f2f | ||
|
|
f64364f37d | ||
|
|
d16e0bbfbf | ||
|
|
70ae41bd29 | ||
|
|
abf6863044 | ||
|
|
4279bd9675 | ||
|
|
5910110b95 | ||
|
|
44594f7011 | ||
|
|
dbb5301ade | ||
|
|
74a4290be4 | ||
|
|
3ce892f846 | ||
|
|
68cebce04a | ||
|
|
1646e964b5 | ||
|
|
2ee97ad4ce | ||
|
|
109ddc9e1e | ||
|
|
804f8aa1fa | ||
|
|
49b97ba508 | ||
|
|
6c11d8165d | ||
|
|
93554b39ba | ||
|
|
6af0e9cf28 | ||
|
|
083deb8357 | ||
|
|
ffb375faeb | ||
|
|
b8cbd8ff6a | ||
|
|
c2bd761383 | ||
|
|
878e3438c8 | ||
|
|
3da65370e0 | ||
|
|
83e646cba9 | ||
|
|
0566166af4 | ||
|
|
ed0b8c3911 | ||
|
|
03d753a83f | ||
|
|
cf51ed1988 | ||
|
|
70f46e89d3 | ||
|
|
efd760fb2e | ||
|
|
f303d24f4a | ||
|
|
9688e88a7c | ||
|
|
c8a6325615 | ||
|
|
798db14bb5 | ||
|
|
178d78ef72 | ||
|
|
8139a0ea54 | ||
|
|
327c2bec70 | ||
|
|
fc0195d9f7 | ||
|
|
db42bca44b | ||
|
|
b3623c84a5 | ||
|
|
45c1f9004b | ||
|
|
845a395ff1 | ||
|
|
f63653c307 | ||
|
|
5b523c68a7 | ||
|
|
03efbe0681 | ||
|
|
cebd3d81e7 | ||
|
|
de53bebeb8 | ||
|
|
6ccaedd48f | ||
|
|
707856fcf2 | ||
|
|
3c3dc35e1d | ||
|
|
f9820bd226 | ||
|
|
fe2ef92ef3 | ||
|
|
9364768397 | ||
|
|
9c28d5a3b7 | ||
|
|
d5078b978c | ||
|
|
d49594d3fb | ||
|
|
619ce932f9 | ||
|
|
b564d0b1c1 | ||
|
|
fc1fc9f170 | ||
|
|
fd5bcfae90 | ||
|
|
3ee0a53688 | ||
|
|
62c081ecf2 | ||
|
|
d9beb647c1 | ||
|
|
f8f8a80a21 | ||
|
|
ac8023d50f | ||
|
|
769f2f5702 | ||
|
|
2f6839bcc4 | ||
|
|
d37109f5f7 | ||
|
|
15bd9fc43c | ||
|
|
8049e90853 | ||
|
|
e47a2c3e5c | ||
|
|
9512c22e1f | ||
|
|
8a77001016 | ||
|
|
9b0214ee55 | ||
|
|
7ad735552a | ||
|
|
ea35472ef8 | ||
|
|
50c5621d8a | ||
|
|
da275cfd52 | ||
|
|
0f4ee5d965 | ||
|
|
af8c0f5ccd | ||
|
|
8ea370a1d1 | ||
|
|
fcf0de72af | ||
|
|
320c5e6ce5 | ||
|
|
7a858cc424 | ||
|
|
c0292842a5 |
No files matched your search
@@ -32,7 +32,7 @@ jobs:
|
||||
git \
|
||||
libssl-dev
|
||||
- name: Build Linux
|
||||
run: ./scripts/build-linux.sh
|
||||
run: ./scripts/linux/build-linux.sh
|
||||
- name: Upload Linux binary
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
@@ -48,7 +48,7 @@ jobs:
|
||||
- name: Setup pspdev
|
||||
uses: ./.github/actions/setup-pspdev
|
||||
- name: Build PSP
|
||||
run: ./scripts/build-psp.sh
|
||||
run: ./scripts/psp/build-psp.sh
|
||||
- name: Move EBOOT.PBP to Dusk subfolder
|
||||
run: |
|
||||
mkdir -p ./git-artifcats/Dusk/PSP/GAME/Dusk
|
||||
@@ -103,7 +103,7 @@ jobs:
|
||||
libgles2:arm64 \
|
||||
libgl1-mesa-dev:arm64
|
||||
- name: Build Knulli
|
||||
run: ./scripts/build-knulli.sh
|
||||
run: ./scripts/knulli/build-knulli.sh
|
||||
- name: Move output to Dusk subfolder
|
||||
run: |
|
||||
mkdir -p ./git-artifcats/Dusk
|
||||
@@ -134,7 +134,7 @@ jobs:
|
||||
gamecube-sdl2 ppc-liblzma ppc-libzip \
|
||||
gamecube-tools ppc-libmad ppc-zlib-ng ppc-bzip2 ppc-zstd
|
||||
- name: Build GameCube
|
||||
run: ./scripts/build-gamecube.sh
|
||||
run: ./scripts/gamecube/build-gamecube.sh
|
||||
- name: Copy output files
|
||||
run: |
|
||||
mkdir -p ./git-artifcats/Dusk
|
||||
@@ -166,7 +166,7 @@ jobs:
|
||||
gamecube-sdl2 ppc-liblzma ppc-libzip \
|
||||
gamecube-tools ppc-libmad ppc-zlib-ng ppc-bzip2 ppc-zstd
|
||||
- name: Build GameCube ISO
|
||||
run: ./scripts/build-gamecube-iso.sh
|
||||
run: ./scripts/gamecube/build-gamecube-iso.sh
|
||||
- name: Copy output files
|
||||
run: |
|
||||
mkdir -p ./git-artifcats/Dusk
|
||||
@@ -199,7 +199,7 @@ jobs:
|
||||
gamecube-sdl2 ppc-liblzma ppc-libzip \
|
||||
gamecube-tools ppc-libmad ppc-zlib-ng ppc-bzip2 ppc-zstd
|
||||
- name: Build Wii
|
||||
run: ./scripts/build-wii.sh
|
||||
run: ./scripts/wii/build-wii.sh
|
||||
- name: Copy output files
|
||||
run: |
|
||||
mkdir -p ./git-artifcats/Dusk/apps/Dusk
|
||||
@@ -232,7 +232,7 @@ jobs:
|
||||
gamecube-sdl2 ppc-liblzma ppc-libzip \
|
||||
gamecube-tools ppc-libmad ppc-zlib-ng ppc-bzip2 ppc-zstd
|
||||
- name: Build Wii ISO
|
||||
run: ./scripts/build-wii-iso.sh
|
||||
run: ./scripts/wii/build-wii-iso.sh
|
||||
- name: Copy output files
|
||||
run: |
|
||||
mkdir -p ./git-artifcats/Dusk
|
||||
|
||||
@@ -32,4 +32,4 @@ jobs:
|
||||
git \
|
||||
libssl-dev
|
||||
- name: Run tests
|
||||
run: ./scripts/test-linux.sh
|
||||
run: ./scripts/linux/test-linux.sh
|
||||
+2
-1
@@ -106,4 +106,5 @@ yarn.lock
|
||||
/build*
|
||||
/assets/test
|
||||
/tools_old
|
||||
/assets/test.png
|
||||
/assets/test.png
|
||||
/assets/audio/boa.mp3
|
||||
+33
-15
@@ -8,7 +8,10 @@ cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
|
||||
set(CMAKE_MODULE_PATH
|
||||
${CMAKE_MODULE_PATH}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules
|
||||
)
|
||||
cmake_policy(SET CMP0079 NEW)
|
||||
# set(FETCHCONTENT_UPDATES_DISCONNECTED ON)
|
||||
|
||||
@@ -18,7 +21,9 @@ option(DUSK_NETWORK "Enable network support" ON)
|
||||
set(DUSK_GAME_NAME "Dusk" CACHE STRING "Game display name")
|
||||
set(DUSK_GAME_AUTHOR "YourWishes" CACHE STRING "Game author / coder")
|
||||
set(DUSK_GAME_SHORT_DESCRIPTION "Dusk game" CACHE STRING "One-line description")
|
||||
set(DUSK_GAME_LONG_DESCRIPTION "No description yet." CACHE STRING "Full description")
|
||||
set(DUSK_GAME_LONG_DESCRIPTION
|
||||
"No description yet." CACHE STRING "Full description"
|
||||
)
|
||||
|
||||
# Prep cache
|
||||
set(DUSK_CACHE_TARGET "dusk-target")
|
||||
@@ -32,13 +37,19 @@ set(DUSK_TEMP_DIR "${DUSK_BUILD_DIR}/temp")
|
||||
set(DUSK_TOOLS_DIR "${DUSK_ROOT_DIR}/tools")
|
||||
set(DUSK_DATA_DIR "${DUSK_ROOT_DIR}/data")
|
||||
set(DUSK_ASSETS_DIR "${DUSK_ROOT_DIR}/assets")
|
||||
set(DUSK_BUILT_ASSETS_DIR "${DUSK_BUILD_DIR}/built_assets" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
set(DUSK_BUILT_ASSETS_DIR "${DUSK_BUILD_DIR}/built_assets"
|
||||
CACHE INTERNAL ${DUSK_CACHE_TARGET}
|
||||
)
|
||||
set(DUSK_GENERATED_HEADERS_DIR "${DUSK_BUILD_DIR}/generated")
|
||||
set(DUSK_BUILD_BINARY ${DUSK_BUILD_DIR}/Dusk CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
set(DUSK_BUILD_BINARY ${DUSK_BUILD_DIR}/Dusk
|
||||
CACHE INTERNAL ${DUSK_CACHE_TARGET}
|
||||
)
|
||||
set(DUSK_ASSETS "" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
set(DUSK_LIBRARY_TARGET_NAME "DuskCore" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
set(DUSK_BINARY_TARGET_NAME "Dusk" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
set(DUSK_ASSETS_ZIP "${DUSK_BUILD_DIR}/dusk.dsk" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
set(DUSK_ASSETS_ZIP "${DUSK_BUILD_DIR}/dusk.dsk"
|
||||
CACHE INTERNAL ${DUSK_CACHE_TARGET}
|
||||
)
|
||||
|
||||
if(NOT DEFINED DUSK_TARGET_SYSTEM)
|
||||
set(DUSK_TARGET_SYSTEM "linux")
|
||||
@@ -73,7 +84,9 @@ if(DUSK_BUILD_TESTS)
|
||||
${DUSK_LIBRARY_TARGET_NAME}
|
||||
)
|
||||
else()
|
||||
set(DUSK_LIBRARY_TARGET_NAME "${DUSK_BINARY_TARGET_NAME}" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||
set(DUSK_LIBRARY_TARGET_NAME "${DUSK_BINARY_TARGET_NAME}"
|
||||
CACHE INTERNAL ${DUSK_CACHE_TARGET}
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED DUSK_VERSION)
|
||||
@@ -122,16 +135,21 @@ if(DUSK_BUILD_TESTS)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
# Build assets
|
||||
file(GLOB_RECURSE DUSK_ASSET_FILES CONFIGURE_DEPENDS "${DUSK_ASSETS_DIR}/*")
|
||||
add_custom_command(
|
||||
OUTPUT "${DUSK_ASSETS_ZIP}"
|
||||
# Build assets. Runs unconditionally on every build (rather than being
|
||||
# gated behind a custom_command's file-level DEPENDS list) because
|
||||
# CONFIGURE_DEPENDS globs only pick up added/removed files on the next
|
||||
# CMake configure, so that approach could miss/lag a rebuild behind an
|
||||
# asset edit. tools.asset.pack itself decides whether anything actually
|
||||
# changed (see its manifest check) and no-ops quickly when nothing did,
|
||||
# so this stays cheap on a build where assets are untouched.
|
||||
add_custom_target(DUSK_ASSETS_BUILT ALL
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${DUSK_ASSETS_DIR}"
|
||||
COMMAND ${CMAKE_COMMAND} -E rm -f "${DUSK_ASSETS_ZIP}"
|
||||
COMMAND ${CMAKE_COMMAND} -E tar "cf" "${DUSK_ASSETS_ZIP}" --format=zip -- .
|
||||
WORKING_DIRECTORY "${DUSK_ASSETS_DIR}"
|
||||
DEPENDS ${DUSK_ASSET_FILES}
|
||||
COMMAND ${Python3_EXECUTABLE} -m tools.asset.pack
|
||||
--input "${DUSK_ASSETS_DIR}"
|
||||
--output "${DUSK_ASSETS_ZIP}"
|
||||
WORKING_DIRECTORY "${DUSK_ROOT_DIR}"
|
||||
BYPRODUCTS "${DUSK_ASSETS_ZIP}"
|
||||
COMMENT "Packing assets into dusk.dsk"
|
||||
VERBATIM
|
||||
)
|
||||
add_custom_target(DUSK_ASSETS_BUILT DEPENDS "${DUSK_ASSETS_ZIP}")
|
||||
add_dependencies(${DUSK_LIBRARY_TARGET_NAME} DUSK_ASSETS_BUILT)
|
||||
@@ -9,15 +9,18 @@ following packages, depending on your system;
|
||||
|
||||
Fedora;
|
||||
```
|
||||
sudo dnf install git make gcc cmake python python-polib python3-pillow python3-dotenv python3-numpy python-qt5 python3-pyopengl SDL2-devel zlib-devel libzip-devel bzip2-devel openssl-devel lzma-sdk-devel xz xz-devel lua-devel
|
||||
sudo dnf install git make gcc cmake python python-polib python3-pillow python3-dotenv python3-numpy python-qt5 python3-pyopengl SDL2-devel zlib-devel libzip-devel bzip2-devel openssl-devel lzma-sdk-devel xz xz-devel lua-devel libmad-devel
|
||||
```
|
||||
`libmad-devel` (used for MP3 decoding) is GPL-licensed and ships in the
|
||||
[RPM Fusion](https://rpmfusion.org/) free repository rather than Fedora's
|
||||
base repos - make sure RPM Fusion is enabled first.
|
||||
|
||||
Ubuntu;
|
||||
```
|
||||
sudo apt-get install git build-essential gcc python python-polib python3-pillow python3-dotenv python3-numpy python3-pyqt5 python3-opengl
|
||||
sudo apt-get install git build-essential gcc python python-polib python3-pillow python3-dotenv python3-numpy python3-pyqt5 python3-opengl libmad0-dev
|
||||
```
|
||||
|
||||
Arch Linux;
|
||||
```
|
||||
sudo pacman -S git base-devel gcc python python-polib python-pillow python-dotenv python-numpy python-pyqt5 python-opengl
|
||||
sudo pacman -S git base-devel gcc python python-polib python-pillow python-dotenv python-numpy python-pyqt5 python-opengl libmad
|
||||
```
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"moves": {
|
||||
"fire": {
|
||||
// Target flags
|
||||
"enemies": true,
|
||||
"allies": true,
|
||||
"multiple": false,
|
||||
"self": true,
|
||||
"default": "enemy",
|
||||
"target": "SINGLE_ENEMY"
|
||||
},
|
||||
|
||||
"slash": {
|
||||
"enemies": true,
|
||||
"allies": true,
|
||||
"self": false,
|
||||
"default": "enemy",
|
||||
"target": "SINGLE_ENEMY"
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"type": "MODAL",
|
||||
"title": "Fire",
|
||||
"message": "A burst of flame scorches the target."
|
||||
},
|
||||
{
|
||||
"type": "WAIT",
|
||||
"seconds": 2
|
||||
},
|
||||
{
|
||||
"type": "MODAL_CLOSE"
|
||||
},
|
||||
{
|
||||
"type": "BATTLE_FIGHTER_DAMAGE",
|
||||
"fighter": "target",
|
||||
"amount": 12
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"type": "MODAL",
|
||||
"title": "Slash",
|
||||
"message": "A quick blade strike cuts across the target."
|
||||
},
|
||||
{
|
||||
"type": "WAIT",
|
||||
"seconds": 2
|
||||
},
|
||||
{
|
||||
"type": "MODAL_CLOSE"
|
||||
},
|
||||
{
|
||||
"type": "BATTLE_FIGHTER_DAMAGE",
|
||||
"fighter": "target",
|
||||
"amount": 8
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"type": "BATTLE_START",
|
||||
"enemies": [
|
||||
{
|
||||
"attack": 8, "defense": 4, "magic": 0, "speed": 5, "luck": 2,
|
||||
"healthMax": 30, "mpMax": 0,
|
||||
"abilities": ["fire"]
|
||||
},
|
||||
{
|
||||
"attack": 6, "defense": 3, "magic": 0, "speed": 7, "luck": 2,
|
||||
"healthMax": 20, "mpMax": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Binary file not shown.
@@ -1,7 +1,6 @@
|
||||
{
|
||||
"items": [
|
||||
// Boot check: make sure a save device is available before handing off
|
||||
// to the main menu.
|
||||
// First thing, try and find a save device, used for settings and what not.
|
||||
{
|
||||
"type": "MODAL",
|
||||
"title": "initial.checking_save.title",
|
||||
@@ -14,13 +13,13 @@
|
||||
{
|
||||
"type": "SAVE_DEVICE_CHECK",
|
||||
"successMarker": "CONTINUE",
|
||||
"failureMarker": "NO_DEVICE"
|
||||
"failureMarker": "SAVE_DEVICE_NOT_FOUND"
|
||||
},
|
||||
|
||||
// No save device found - offer to retry or continue without saving.
|
||||
// No save device found
|
||||
{
|
||||
"type": "MARKER",
|
||||
"name": "NO_DEVICE"
|
||||
"name": "SAVE_DEVICE_NOT_FOUND"
|
||||
},
|
||||
{
|
||||
"type": "MODAL_CLOSE"
|
||||
@@ -32,7 +31,7 @@
|
||||
"options": [
|
||||
{
|
||||
"text": "initial.no_device.retry",
|
||||
"marker": "RETRY"
|
||||
"marker": "SAVE_DEVICE_RETRY"
|
||||
},
|
||||
{
|
||||
"text": "initial.no_device.continue",
|
||||
@@ -41,9 +40,10 @@
|
||||
]
|
||||
},
|
||||
|
||||
// Save device not found, user to retry, just close modal and loop
|
||||
{
|
||||
"type": "MARKER",
|
||||
"name": "RETRY"
|
||||
"name": "SAVE_DEVICE_RETRY"
|
||||
},
|
||||
{
|
||||
"type": "MODAL_CLOSE"
|
||||
@@ -52,8 +52,7 @@
|
||||
"type": "RESTART"
|
||||
},
|
||||
|
||||
// Save device found (or continuing without one) - hand off to the
|
||||
// main menu scene.
|
||||
// Save device found (or continuing without one)
|
||||
{
|
||||
"type": "MARKER",
|
||||
"name": "CONTINUE"
|
||||
@@ -62,8 +61,8 @@
|
||||
"type": "MODAL_CLOSE"
|
||||
},
|
||||
{
|
||||
"type": "SCENE",
|
||||
"sceneType": "MAIN_MENU"
|
||||
"type": "CUTSCENE",
|
||||
"name": "cutscenes/main_menu.jsonc"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"type": "MARKER",
|
||||
"name": "MAIN_MENU_IDLE"
|
||||
},
|
||||
{
|
||||
"type": "UI_SHOW",
|
||||
"name": "main_menu"
|
||||
},
|
||||
|
||||
// Options button goes here - no options screen yet, so this is just
|
||||
// an alias landing right back on the idle loop below.
|
||||
{
|
||||
"type": "MARKER",
|
||||
"name": "OPTIONS"
|
||||
},
|
||||
{
|
||||
"type": "IDLE"
|
||||
},
|
||||
|
||||
// New Game button goes here.
|
||||
{
|
||||
"type": "MARKER",
|
||||
"name": "NEW_GAME"
|
||||
},
|
||||
{
|
||||
"type": "MODAL",
|
||||
"title": "main_menu.checking_save.title",
|
||||
"message": "main_menu.checking_save.message"
|
||||
},
|
||||
{
|
||||
"type": "WAIT",
|
||||
"seconds": 0.2
|
||||
},
|
||||
{
|
||||
"type": "SAVE_DEVICE_CHECK",
|
||||
"successMarker": "SAVE_DEVICE_FOUND",
|
||||
"failureMarker": "SAVE_DEVICE_NOT_FOUND"
|
||||
},
|
||||
|
||||
// Save device not found
|
||||
{
|
||||
"type": "MARKER",
|
||||
"name": "SAVE_DEVICE_NOT_FOUND"
|
||||
},
|
||||
{
|
||||
"type": "MODAL_CLOSE"
|
||||
},
|
||||
{
|
||||
"type": "MODAL_OPTIONS_MARKERS",
|
||||
"title": "main_menu.no_device.title",
|
||||
"message": "main_menu.no_device.message",
|
||||
"options": [
|
||||
{
|
||||
"text": "main_menu.no_device.retry",
|
||||
"marker": "NEW_GAME"
|
||||
},
|
||||
{
|
||||
"text": "main_menu.no_device.continue",
|
||||
"marker": "SAVE_DEVICE_FOUND"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
// Save data failed to load (e.g. corrupt/unreadable) - only option is
|
||||
// to retry, no "continue without saving" here since we already know a
|
||||
// device is present.
|
||||
{
|
||||
"type": "MARKER",
|
||||
"name": "LOAD_ERROR"
|
||||
},
|
||||
{
|
||||
"type": "MODAL_OPTIONS_MARKERS",
|
||||
"title": "main_menu.save_load_error.title",
|
||||
"message": "main_menu.save_load_error.message",
|
||||
"options": [
|
||||
{
|
||||
"text": "main_menu.save_load_error.retry",
|
||||
"marker": "NEW_GAME"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
// Quit Game button goes here. Cancelling jumps back to
|
||||
// MAIN_MENU_IDLE; confirming falls through to QUIT_GAME, which
|
||||
// ends the process directly.
|
||||
{
|
||||
"type": "MARKER",
|
||||
"name": "QUIT"
|
||||
},
|
||||
{
|
||||
"type": "MODAL_OPTIONS_MARKERS",
|
||||
"title": "main_menu.quit_confirm",
|
||||
"options": [
|
||||
{
|
||||
"text": "ui.confirm.confirm",
|
||||
"marker": "QUIT_CONFIRMED"
|
||||
},
|
||||
{
|
||||
"text": "ui.confirm.cancel",
|
||||
"marker": "MAIN_MENU_IDLE"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"type": "MARKER",
|
||||
"name": "QUIT_CONFIRMED"
|
||||
},
|
||||
{
|
||||
"type": "QUIT_GAME"
|
||||
},
|
||||
|
||||
// main menu just listens for cutscene ending to show the select save modal
|
||||
// so we have that here.
|
||||
{
|
||||
"type": "MARKER",
|
||||
"name": "SAVE_DEVICE_FOUND"
|
||||
},
|
||||
{
|
||||
"type": "MODAL_CLOSE"
|
||||
},
|
||||
{
|
||||
"type": "SAVE_LOAD_ALL_SLOTS",
|
||||
"successMarker": "LOADED",
|
||||
"failureMarker": "LOAD_ERROR"
|
||||
},
|
||||
|
||||
// Must be the very last item - falling off the end here is what
|
||||
// completes the cutscene and fires uiMainMenuOpenSelectSave (see
|
||||
// cutsceneSystemSetOnComplete in ui/screen/mainmenu/uimainmenu.c).
|
||||
// Placing this anywhere earlier would fall through into whatever
|
||||
// comes next instead (e.g. the QUIT block, if placed just before it).
|
||||
{
|
||||
"type": "MARKER",
|
||||
"name": "LOADED"
|
||||
}
|
||||
]
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,11 @@
|
||||
{
|
||||
// Placeholder for the new-game intro flow - just shows a modal for now.
|
||||
"items": [
|
||||
{
|
||||
"type": "MODAL",
|
||||
"title": "New Game",
|
||||
"message": "This is a placeholder for the new game intro.",
|
||||
"blocking": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"items": {
|
||||
"potion": { "type": "MEDICINE" },
|
||||
"potato": { "type": "FOOD" },
|
||||
"apple": { "type": "FOOD" }
|
||||
}
|
||||
}
|
||||
+20
-1
@@ -73,6 +73,12 @@ msgstr "Select Save"
|
||||
msgid "ui.select_save.empty"
|
||||
msgstr "Empty Slot"
|
||||
|
||||
msgid "ui.select_save.corrupt"
|
||||
msgstr "Corrupted Save"
|
||||
|
||||
msgid "ui.select_save.corrupt_warning"
|
||||
msgstr "This save file is corrupted and could not be loaded. Please contact support if this issue persists."
|
||||
|
||||
msgid "ui.select_save.slot_format"
|
||||
msgstr "%s Lv.%d %s"
|
||||
|
||||
@@ -260,6 +266,10 @@ msgstr "loading"
|
||||
msgid "ui.autosave.saving"
|
||||
msgstr "SAVING"
|
||||
|
||||
|
||||
#
|
||||
# Items
|
||||
#
|
||||
msgid "item.potion.name"
|
||||
msgstr "Potion"
|
||||
|
||||
@@ -267,4 +277,13 @@ msgid "item.potato.name"
|
||||
msgstr "Potato"
|
||||
|
||||
msgid "item.apple.name"
|
||||
msgstr "Apple"
|
||||
msgstr "Apple"
|
||||
|
||||
#
|
||||
# Moves
|
||||
#
|
||||
msgid "move.fire.name"
|
||||
msgstr "Fire"
|
||||
|
||||
msgid "move.slash.name"
|
||||
msgstr "Slash"
|
||||
@@ -0,0 +1 @@
|
||||
{"meshes":[{"file":"house_4_4.dmf","pos":[2,1,0]},{"file":"house_6_3.dmf","pos":[1,9,0]},{"file":"house_2_2.dmf","pos":[12,6,0]}],"tiles":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]]}
|
||||
@@ -0,0 +1 @@
|
||||
{"tiles":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[6,0],[2,0],[2,0],[2,0],[2,0],[2,0],[2,0],[7,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[3,0],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[5,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[3,0],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[5,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[3,0],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[5,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[8,0],[4,0],[4,0],[4,0],[12,0],[1,1],[1,1],[5,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[3,0],[1,1],[1,1],[5,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[3,0],[1,1],[1,1],[5,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[8,0],[4,0],[4,0],[9,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]],"meshes":[{"file":"house_5_3.dmf","pos":[1,1,0]}],"entities":[{"type":"global","globalId":3,"pos":[8,8,1]},{"type":"global","globalId":4,"pos":[12,2,0]}],"areas":[{"min":[11,3,0],"max":[16,9,10],"callbackId":1,"notify":3,"trigger":6}]}
|
||||
@@ -0,0 +1 @@
|
||||
{"meshes":[{"file":"house_8_4.dmf","pos":[1,1,0]},{"file":"house_3_3.dmf","pos":[11,2,0]},{"file":"house_2_2.dmf","pos":[3,11,0]}],"tiles":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,null,null,null,[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],null,null,null,null,null,null,null,null,[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],null,null,null,null,null,null,null,null,[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]]}
|
||||
@@ -0,0 +1 @@
|
||||
{"meshes":[{"file":"house_3_2.dmf","pos":[1,1,0]},{"file":"house_2_3.dmf","pos":[7,2,0]},{"file":"house_4_2.dmf","pos":[1,8,0]},{"file":"house_1_1.dmf","pos":[11,10,0]},{"file":"house_5_2.dmf","pos":[13,6,0]}],"tiles":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,[1,0],null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]]}
|
||||
@@ -0,0 +1 @@
|
||||
{"meshes":[{"file":"house_5_5.dmf","pos":[3,2,0]},{"file":"house_2_3.dmf","pos":[10,3,0]},{"file":"house_3_1.dmf","pos":[1,12,0]}],"tiles":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],null,null,null,[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]]}
|
||||
@@ -0,0 +1 @@
|
||||
{"tiles":[[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,3],[1,3],[1,3],[1,3],[1,3],[1,3],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,3],[1,3],[1,3],[1,3],[1,3],[1,3],[1,0],[1,0],[1,0],[1,0],null,null,[1,0],[1,0],[1,0],[1,0],[1,3],[1,3],[1,3],[1,3],[1,3],[1,3],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[4,1],[4,1],[4,1],[4,1],[4,1],[4,1],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[4,0],[4,0],[4,0],[4,0],[4,0],[4,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]],"meshes":[]}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"mesh": "meshes/chunks/chunk_-1_0_0_0.dmf",
|
||||
"color": [
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255
|
||||
],
|
||||
"texture": "tiles.png"
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"mesh": "meshes/chunks/chunk_0_0_0_0.dmf",
|
||||
"color": [
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255
|
||||
],
|
||||
"texture": "tiles.png"
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"mesh": "meshes/chunks/chunk_0_1_0_0.dmf",
|
||||
"color": [
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255
|
||||
],
|
||||
"texture": "tiles.png"
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"mesh": "meshes/chunks/chunk_1_0_0_0.dmf",
|
||||
"color": [
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255
|
||||
],
|
||||
"texture": "tiles.png"
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"mesh": "meshes/chunks/chunk_1_1_0_0.dmf",
|
||||
"color": [
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255
|
||||
],
|
||||
"texture": "tiles.png"
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"mesh": "meshes/chunks/chunk_2_0_0_0.dmf",
|
||||
"color": [
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255
|
||||
],
|
||||
"texture": "tiles.png"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"members": {
|
||||
"hero": {
|
||||
"attack": 10,
|
||||
"defense": 5,
|
||||
"magic": 0,
|
||||
"speed": 10,
|
||||
"luck": 0,
|
||||
"healthMax": 30,
|
||||
"mpMax": 10
|
||||
},
|
||||
"companion": {
|
||||
"attack": 8,
|
||||
"defense": 6,
|
||||
"magic": 4,
|
||||
"speed": 8,
|
||||
"luck": 1,
|
||||
"healthMax": 25,
|
||||
"mpMax": 15
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"flags": {
|
||||
"test": {
|
||||
"initial": true
|
||||
},
|
||||
"test2": {
|
||||
"initial": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -1,92 +0,0 @@
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"type": "MODAL",
|
||||
"title": "main_menu.checking_save.title",
|
||||
"message": "main_menu.checking_save.message"
|
||||
},
|
||||
{
|
||||
"type": "WAIT",
|
||||
"seconds": 0.2
|
||||
},
|
||||
{
|
||||
"type": "SAVE_DEVICE_CHECK",
|
||||
"successMarker": "CONTINUE",
|
||||
"failureMarker": "NO_DEVICE"
|
||||
},
|
||||
|
||||
// No save device found - offer to retry or continue without saving.
|
||||
{
|
||||
"type": "MARKER",
|
||||
"name": "NO_DEVICE"
|
||||
},
|
||||
{
|
||||
"type": "MODAL_CLOSE"
|
||||
},
|
||||
{
|
||||
"type": "MODAL_OPTIONS_MARKERS",
|
||||
"title": "main_menu.no_device.title",
|
||||
"message": "main_menu.no_device.message",
|
||||
"options": [
|
||||
{
|
||||
"text": "main_menu.no_device.retry",
|
||||
"marker": "RETRY"
|
||||
},
|
||||
{
|
||||
"text": "main_menu.no_device.continue",
|
||||
"marker": "CONTINUE"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
// Retry
|
||||
{
|
||||
"type": "MARKER",
|
||||
"name": "RETRY"
|
||||
},
|
||||
{
|
||||
"type": "MODAL_CLOSE"
|
||||
},
|
||||
{
|
||||
"type": "RESTART"
|
||||
},
|
||||
|
||||
// Save device found - attempt to load all save slots.
|
||||
{
|
||||
"type": "MARKER",
|
||||
"name": "CONTINUE"
|
||||
},
|
||||
{
|
||||
"type": "MODAL_CLOSE"
|
||||
},
|
||||
{
|
||||
"type": "SAVE_LOAD_ALL_SLOTS",
|
||||
"successMarker": "LOADED",
|
||||
"failureMarker": "LOAD_ERROR"
|
||||
},
|
||||
|
||||
// Save data failed to load (e.g. corrupt/unreadable) - only option is
|
||||
// to retry, no "continue without saving" here since we already know a
|
||||
// device is present.
|
||||
{
|
||||
"type": "MARKER",
|
||||
"name": "LOAD_ERROR"
|
||||
},
|
||||
{
|
||||
"type": "MODAL_OPTIONS_MARKERS",
|
||||
"title": "main_menu.save_load_error.title",
|
||||
"message": "main_menu.save_load_error.message",
|
||||
"options": [
|
||||
{
|
||||
"text": "main_menu.save_load_error.retry",
|
||||
"marker": "RETRY"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"type": "MARKER",
|
||||
"name": "LOADED"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# NOTE: libmad itself is GPL-licensed (see https://www.underbit.com/products/mad/),
|
||||
# not MIT like the rest of this project. Any binary linking it must comply
|
||||
# with the GPL - a deliberate tradeoff accepted for MP3 decode correctness
|
||||
# (see audiostreammp3decodersw.c's own comment on why minimp3 wasn't enough).
|
||||
|
||||
find_path(LIBMAD_INCLUDE_DIR NAMES mad.h)
|
||||
mark_as_advanced(LIBMAD_INCLUDE_DIR)
|
||||
|
||||
find_library(LIBMAD_LIBRARY NAMES mad)
|
||||
mark_as_advanced(LIBMAD_LIBRARY)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(
|
||||
libmad
|
||||
REQUIRED_VARS
|
||||
LIBMAD_LIBRARY
|
||||
LIBMAD_INCLUDE_DIR
|
||||
)
|
||||
|
||||
if(libmad_FOUND AND NOT TARGET libmad::mad)
|
||||
add_library(libmad::mad UNKNOWN IMPORTED)
|
||||
set_target_properties(libmad::mad
|
||||
PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES ${LIBMAD_INCLUDE_DIR}
|
||||
IMPORTED_LOCATION ${LIBMAD_LIBRARY}
|
||||
)
|
||||
endif()
|
||||
@@ -61,6 +61,8 @@ target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PRIVATE
|
||||
zstd
|
||||
z
|
||||
lzma
|
||||
asnd
|
||||
mad
|
||||
)
|
||||
|
||||
if(DUSK_DOLPHIN_BUILD_TYPE STREQUAL "ISO")
|
||||
|
||||
@@ -27,6 +27,7 @@ target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
)
|
||||
|
||||
set(DUSK_BACKTRACE ON CACHE BOOL "Enable backtrace support for assert failures.")
|
||||
set(DUSK_TRACK_MEMORY ON CACHE BOOL "Track memoryAllocate() call sites to help find memory leaks.")
|
||||
|
||||
# Define platform-specific macros.
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
|
||||
@@ -30,6 +30,7 @@ target_link_libraries(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
||||
pspgu
|
||||
pspaudio
|
||||
pspaudiolib
|
||||
pspmp3
|
||||
psputility
|
||||
pspvfpu
|
||||
pspvram
|
||||
@@ -59,6 +60,19 @@ target_compile_definitions(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
||||
DUSK_DISPLAY_OVERSCAN=6
|
||||
)
|
||||
|
||||
# logDebug()/logError() additionally write every call to a file on the
|
||||
# Memory Stick (ms0:/PSP/GAME/Dusk/*.log) - a real, measured source of
|
||||
# per-call hitching (fopen+write+fclose every log line), not just a
|
||||
# theoretical cost. Default off so a normal build doesn't pay it; opt in
|
||||
# with -DDUSK_PSP_LOG_FILE=ON when the log file itself is actually needed
|
||||
# (e.g. no way to see stdout on real hardware).
|
||||
set(DUSK_PSP_LOG_FILE OFF CACHE BOOL "Also write PSP debug/error logs to ms0:/PSP/GAME/Dusk/*.log (slow - Memory Stick I/O per call).")
|
||||
if(DUSK_PSP_LOG_FILE)
|
||||
target_compile_definitions(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
||||
DUSK_PSP_LOG_FILE
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
target_compile_definitions(${DUSK_BINARY_TARGET_NAME} PUBLIC
|
||||
DUSK_ASSERTIONS_FAKED
|
||||
|
||||
@@ -5,7 +5,7 @@ target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
)
|
||||
|
||||
# Wii save storage method - see src/duskdolphin/save/savedeviceplatform.h.
|
||||
set(DUSK_SAVE_WII_METHOD "NAND" CACHE STRING
|
||||
set(DUSK_SAVE_WII_METHOD "SD" CACHE STRING
|
||||
"Wii save storage: NAND (internal storage via ISFS), CARD (GameCube-\
|
||||
compatible memory card emulation), or SD (SD card via libfat)"
|
||||
)
|
||||
|
||||
@@ -1,159 +0,0 @@
|
||||
// Copyright (c) 2026 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
"use strict";
|
||||
|
||||
// ChunkTerrain - JS port of the terrain-quad generation performed by
|
||||
// tools/asset/chunk/__main__.py (build_terrain_verts / _tile_quad /
|
||||
// _RAMP_CORNERS) so the editor's 3D preview can show the same geometry the
|
||||
// Python compiler will bake into the chunk's terrain mesh, without waiting
|
||||
// for a compile pass. Vertex layout matches DMF: interleaved [u, v, x, y, z].
|
||||
|
||||
const ChunkTerrain = (() => {
|
||||
const CHUNK_WIDTH = 16;
|
||||
const CHUNK_HEIGHT = 16;
|
||||
const CHUNK_DEPTH = 4;
|
||||
const TILE_COUNT = CHUNK_WIDTH * CHUNK_HEIGHT * CHUNK_DEPTH;
|
||||
|
||||
// World-space Z distance of one Z-layer/story, in world-float space.
|
||||
// Must match WORLD_LAYER_HEIGHT in src/dusk/rpg/overworld/worldpos.h.
|
||||
const WORLD_LAYER_HEIGHT = Math.SQRT1_2;
|
||||
|
||||
const TILE_SHAPE_NULL = 0;
|
||||
const TILE_SHAPE_GROUND = 1;
|
||||
const TILE_SHAPE_RAMP_NORTH = 2;
|
||||
const TILE_SHAPE_RAMP_EAST = 3;
|
||||
const TILE_SHAPE_RAMP_SOUTH = 4;
|
||||
const TILE_SHAPE_RAMP_WEST = 5;
|
||||
const TILE_SHAPE_RAMP_NORTHEAST = 6;
|
||||
const TILE_SHAPE_RAMP_NORTHWEST = 7;
|
||||
const TILE_SHAPE_RAMP_SOUTHEAST = 8;
|
||||
const TILE_SHAPE_RAMP_SOUTHWEST = 9;
|
||||
const TILE_SHAPE_RAMP_NORTHEAST_INNER = 10;
|
||||
const TILE_SHAPE_RAMP_NORTHWEST_INNER = 11;
|
||||
const TILE_SHAPE_RAMP_SOUTHEAST_INNER = 12;
|
||||
const TILE_SHAPE_RAMP_SOUTHWEST_INNER = 13;
|
||||
|
||||
// Per-shape corner heights as [sw, se, ne, nw] offsets from tile base Z.
|
||||
// NORTH=+Y, EAST=+X. Cardinal ramps: low face at 0, high face at 1.
|
||||
// Diagonal outer-corner ramps: only the named corner raised, rest at 0.
|
||||
// Diagonal inner-corner ramps: only the corner opposite the named one is
|
||||
// lowered to 0, the rest (including the named corner) stay raised at 1.
|
||||
const RAMP_CORNERS = {
|
||||
[TILE_SHAPE_GROUND]: [0.0, 0.0, 0.0, 0.0],
|
||||
[TILE_SHAPE_RAMP_NORTH]: [0.0, 0.0, 1.0, 1.0],
|
||||
[TILE_SHAPE_RAMP_SOUTH]: [1.0, 1.0, 0.0, 0.0],
|
||||
[TILE_SHAPE_RAMP_EAST]: [0.0, 1.0, 1.0, 0.0],
|
||||
[TILE_SHAPE_RAMP_WEST]: [1.0, 0.0, 0.0, 1.0],
|
||||
[TILE_SHAPE_RAMP_NORTHEAST]: [0.0, 0.0, 1.0, 0.0],
|
||||
[TILE_SHAPE_RAMP_NORTHWEST]: [0.0, 0.0, 0.0, 1.0],
|
||||
[TILE_SHAPE_RAMP_SOUTHEAST]: [0.0, 1.0, 0.0, 0.0],
|
||||
[TILE_SHAPE_RAMP_SOUTHWEST]: [1.0, 0.0, 0.0, 0.0],
|
||||
[TILE_SHAPE_RAMP_NORTHEAST_INNER]: [0.0, 1.0, 1.0, 1.0],
|
||||
[TILE_SHAPE_RAMP_NORTHWEST_INNER]: [1.0, 0.0, 1.0, 1.0],
|
||||
[TILE_SHAPE_RAMP_SOUTHEAST_INNER]: [1.0, 1.0, 1.0, 0.0],
|
||||
[TILE_SHAPE_RAMP_SOUTHWEST_INNER]: [1.0, 1.0, 0.0, 1.0],
|
||||
};
|
||||
|
||||
function tileIndex(x, y, z) {
|
||||
return x + y * CHUNK_WIDTH + z * CHUNK_WIDTH * CHUNK_HEIGHT;
|
||||
}
|
||||
|
||||
// Six vertices (2 CCW triangles) for a quad with per-corner Z heights.
|
||||
// Corner order: SW=(fx,fy), SE=(fx+1,fy), NE=(fx+1,fy+1), NW=(fx,fy+1).
|
||||
function pushTileQuad(out, u0, u1, v0, v1, fx, fy, swZ, seZ, neZ, nwZ) {
|
||||
out.push(
|
||||
u0, v0, fx, fy, swZ,
|
||||
u1, v0, fx + 1, fy, seZ,
|
||||
u1, v1, fx + 1, fy + 1, neZ,
|
||||
u0, v0, fx, fy, swZ,
|
||||
u1, v1, fx + 1, fy + 1, neZ,
|
||||
u0, v1, fx, fy + 1, nwZ,
|
||||
);
|
||||
}
|
||||
|
||||
// Generate terrain quads for every non-null tile in a flat tiles array
|
||||
// (length TILE_COUNT, indexed via tileIndex). Returns a Float32Array of
|
||||
// interleaved [u, v, x, y, z] vertices, matching DMF.VERTEX_FLOATS.
|
||||
function buildTerrainVerts(tiles) {
|
||||
const out = [];
|
||||
for(let z = 0; z < CHUNK_DEPTH; z++) {
|
||||
for(let y = 0; y < CHUNK_HEIGHT; y++) {
|
||||
for(let x = 0; x < CHUNK_WIDTH; x++) {
|
||||
const type = tiles[tileIndex(x, y, z)] || TILE_SHAPE_NULL;
|
||||
const corners = RAMP_CORNERS[type];
|
||||
if(!corners) continue;
|
||||
|
||||
const u0 = x / CHUNK_WIDTH;
|
||||
const u1 = (x + 1) / CHUNK_WIDTH;
|
||||
const v0 = y / CHUNK_HEIGHT;
|
||||
const v1 = (y + 1) / CHUNK_HEIGHT;
|
||||
const [sw, se, ne, nw] = corners;
|
||||
|
||||
pushTileQuad(
|
||||
out, u0, u1, v0, v1, x, y,
|
||||
(z + sw) * WORLD_LAYER_HEIGHT,
|
||||
(z + se) * WORLD_LAYER_HEIGHT,
|
||||
(z + ne) * WORLD_LAYER_HEIGHT,
|
||||
(z + nw) * WORLD_LAYER_HEIGHT
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Float32Array(out);
|
||||
}
|
||||
|
||||
// Four edges (SW-SE, SE-NE, NE-NW, NW-SW) of a tile's quad as line
|
||||
// segments, lifted slightly above the terrain surface to avoid
|
||||
// z-fighting - same corner-height convention as pushTileQuad().
|
||||
function pushTileGridLines(out, fx, fy, swZ, seZ, neZ, nwZ) {
|
||||
const eps = 0.01;
|
||||
const sw = [fx, fy, swZ + eps];
|
||||
const se = [fx + 1, fy, seZ + eps];
|
||||
const ne = [fx + 1, fy + 1, neZ + eps];
|
||||
const nw = [fx, fy + 1, nwZ + eps];
|
||||
const edges = [sw, se, se, ne, ne, nw, nw, sw];
|
||||
for(const [x, y, z] of edges) out.push(0, 0, x, y, z);
|
||||
}
|
||||
|
||||
// Generate grid-outline line segments for every non-null tile, following
|
||||
// the same per-corner heights as buildTerrainVerts() so lines hug ramps
|
||||
// instead of cutting through them. Returns a Float32Array of interleaved
|
||||
// [u, v, x, y, z] vertices meant to be drawn with gl.LINES (pairs).
|
||||
function buildGridLines(tiles) {
|
||||
const out = [];
|
||||
for(let z = 0; z < CHUNK_DEPTH; z++) {
|
||||
for(let y = 0; y < CHUNK_HEIGHT; y++) {
|
||||
for(let x = 0; x < CHUNK_WIDTH; x++) {
|
||||
const type = tiles[tileIndex(x, y, z)] || TILE_SHAPE_NULL;
|
||||
const corners = RAMP_CORNERS[type];
|
||||
if(!corners) continue;
|
||||
|
||||
const [sw, se, ne, nw] = corners;
|
||||
pushTileGridLines(
|
||||
out, x, y,
|
||||
(z + sw) * WORLD_LAYER_HEIGHT,
|
||||
(z + se) * WORLD_LAYER_HEIGHT,
|
||||
(z + ne) * WORLD_LAYER_HEIGHT,
|
||||
(z + nw) * WORLD_LAYER_HEIGHT
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Float32Array(out);
|
||||
}
|
||||
|
||||
return Object.freeze({
|
||||
CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, TILE_COUNT, WORLD_LAYER_HEIGHT,
|
||||
TILE_SHAPE_NULL, TILE_SHAPE_GROUND,
|
||||
TILE_SHAPE_RAMP_NORTH, TILE_SHAPE_RAMP_EAST,
|
||||
TILE_SHAPE_RAMP_SOUTH, TILE_SHAPE_RAMP_WEST,
|
||||
TILE_SHAPE_RAMP_NORTHEAST, TILE_SHAPE_RAMP_NORTHWEST,
|
||||
TILE_SHAPE_RAMP_SOUTHEAST, TILE_SHAPE_RAMP_SOUTHWEST,
|
||||
TILE_SHAPE_RAMP_NORTHEAST_INNER, TILE_SHAPE_RAMP_NORTHWEST_INNER,
|
||||
TILE_SHAPE_RAMP_SOUTHEAST_INNER, TILE_SHAPE_RAMP_SOUTHWEST_INNER,
|
||||
RAMP_CORNERS, tileIndex, buildTerrainVerts, buildGridLines,
|
||||
});
|
||||
})();
|
||||
@@ -1,64 +0,0 @@
|
||||
// Copyright (c) 2026 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
"use strict";
|
||||
|
||||
// DMF - Dusk Mesh Format
|
||||
//
|
||||
// Header (12 bytes):
|
||||
// [0-3] "DMF\0" magic
|
||||
// [4-7] uint32 version (little-endian)
|
||||
// [8-11] uint32 vertCount (little-endian)
|
||||
//
|
||||
// Followed by vertCount vertices, each 20 bytes:
|
||||
// [0-7] float32[2] uv (little-endian)
|
||||
// [8-19] float32[3] pos (little-endian)
|
||||
|
||||
const DMF = (() => {
|
||||
const MAGIC = [0x44, 0x4d, 0x46, 0x00]; // "DMF\0"
|
||||
const VERSION = 1;
|
||||
const HEADER_SIZE = 12;
|
||||
const VERTEX_FLOATS = 5; // uv[2] + pos[3]
|
||||
const VERTEX_SIZE = VERTEX_FLOATS * 4;
|
||||
|
||||
// Decode a DMF ArrayBuffer into { version, vertexCount, floats }, where
|
||||
// floats is a Float32Array of tightly interleaved [u, v, x, y, z] per
|
||||
// vertex - ready to hand straight to gl.bufferData().
|
||||
function decode(buffer) {
|
||||
const bytes = new Uint8Array(buffer);
|
||||
const view = new DataView(buffer);
|
||||
|
||||
if(bytes.length < HEADER_SIZE) throw new Error("File too small to be a valid DMF");
|
||||
if(
|
||||
bytes[0] !== MAGIC[0] || bytes[1] !== MAGIC[1] ||
|
||||
bytes[2] !== MAGIC[2] || bytes[3] !== MAGIC[3]
|
||||
) {
|
||||
throw new Error("Invalid DMF magic bytes - not a DMF file");
|
||||
}
|
||||
|
||||
const version = view.getUint32(4, true);
|
||||
if(version !== VERSION) {
|
||||
throw new Error(`Unsupported DMF version: ${version}`);
|
||||
}
|
||||
|
||||
const vertexCount = view.getUint32(8, true);
|
||||
const expected = HEADER_SIZE + vertexCount * VERTEX_SIZE;
|
||||
if(bytes.length < expected) {
|
||||
throw new Error(`DMF vertex data truncated (expected ${expected} bytes, got ${bytes.length})`);
|
||||
}
|
||||
|
||||
const floats = new Float32Array(vertexCount * VERTEX_FLOATS);
|
||||
for(let i = 0; i < floats.length; i++) {
|
||||
floats[i] = view.getFloat32(HEADER_SIZE + i * 4, true);
|
||||
}
|
||||
|
||||
return { version, vertexCount, floats };
|
||||
}
|
||||
|
||||
return Object.freeze({
|
||||
decode,
|
||||
VERSION, HEADER_SIZE, VERTEX_FLOATS, VERTEX_SIZE,
|
||||
});
|
||||
})();
|
||||
@@ -1,6 +0,0 @@
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<h1>Dusk Map Editor</h1>
|
||||
<p class="text-muted">Browse and edit project assets.</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,92 +0,0 @@
|
||||
<link rel="stylesheet" href="/map/map.css">
|
||||
|
||||
<div class="row g-3">
|
||||
<div class="col-12">
|
||||
<div class="d-flex flex-wrap align-items-end gap-2 mb-2">
|
||||
<div>
|
||||
<label class="form-label mb-0">X</label>
|
||||
<input type="number" id="coordX" class="form-control form-control-sm" style="width:5rem" value="0">
|
||||
</div>
|
||||
<div>
|
||||
<label class="form-label mb-0">Y</label>
|
||||
<input type="number" id="coordY" class="form-control form-control-sm" style="width:5rem" value="0">
|
||||
</div>
|
||||
<div>
|
||||
<label class="form-label mb-0">Z</label>
|
||||
<input type="number" id="coordZ" class="form-control form-control-sm" style="width:5rem" value="0">
|
||||
</div>
|
||||
<button id="btnLoad" type="button" class="btn btn-sm btn-secondary">Load</button>
|
||||
|
||||
<div class="dropdown">
|
||||
<button
|
||||
class="btn btn-sm btn-outline-secondary dropdown-toggle"
|
||||
type="button" data-bs-toggle="dropdown"
|
||||
>Browse</button>
|
||||
<ul class="dropdown-menu" id="chunkBrowseList"></ul>
|
||||
</div>
|
||||
|
||||
<div class="dpad" title="Navigate to the neighboring chunk">
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary dpad-n" id="navN" title="North (+Y)">N</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary dpad-w" id="navW" title="West (-X)">W</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary dpad-e" id="navE" title="East (+X)">E</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary dpad-s" id="navS" title="South (-Y)">S</button>
|
||||
</div>
|
||||
<div class="d-flex flex-column gap-1">
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" id="navUp" title="Up (+Z)">Up</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" id="navDown" title="Down (-Z)">Down</button>
|
||||
</div>
|
||||
|
||||
<button id="btnSave" type="button" class="btn btn-sm btn-primary ms-auto">
|
||||
Save & Compile
|
||||
</button>
|
||||
</div>
|
||||
<div id="statusLine" class="small text-muted mb-2"> </div>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-lg-6">
|
||||
<div class="d-flex align-items-center gap-2 mb-2">
|
||||
<label class="form-label mb-0">Z-Level</label>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" id="zLevelDown">-</button>
|
||||
<input type="range" id="zLevel" class="form-range" style="width:150px" min="0" max="3" value="0">
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" id="zLevelUp">+</button>
|
||||
<span id="zLevelLabel">0</span>
|
||||
</div>
|
||||
<div class="d-flex gap-3">
|
||||
<div id="toolPalette" class="tile-palette"></div>
|
||||
<div id="tilePalette" class="tile-palette"></div>
|
||||
<canvas id="gridCanvas" class="border tile-grid" width="512" height="512"></canvas>
|
||||
</div>
|
||||
|
||||
<h5 class="mt-3">Meshes</h5>
|
||||
<ul id="meshList" class="list-group mb-2"></ul>
|
||||
<div class="d-flex gap-2 align-items-end flex-wrap">
|
||||
<div style="min-width:220px">
|
||||
<label class="form-label mb-0">Model</label>
|
||||
<select id="meshPicker" class="form-select form-select-sm"></select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="form-label mb-0">X</label>
|
||||
<input id="meshX" type="number" class="form-control form-control-sm" style="width:5rem" value="0">
|
||||
</div>
|
||||
<div>
|
||||
<label class="form-label mb-0">Y</label>
|
||||
<input id="meshY" type="number" class="form-control form-control-sm" style="width:5rem" value="0">
|
||||
</div>
|
||||
<div>
|
||||
<label class="form-label mb-0">Z</label>
|
||||
<input id="meshZ" type="number" class="form-control form-control-sm" style="width:5rem" value="0">
|
||||
</div>
|
||||
<button id="btnAddMesh" type="button" class="btn btn-sm btn-outline-primary">Add</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-lg-6">
|
||||
<p class="small text-muted mb-2">Preview (scroll to zoom)</p>
|
||||
<canvas id="previewCanvas" class="border" width="512" height="512"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/common/dmf.js"></script>
|
||||
<script src="/common/chunkterrain.js"></script>
|
||||
<script src="/map/renderer.js"></script>
|
||||
<script src="/map/map.js"></script>
|
||||
@@ -1,65 +0,0 @@
|
||||
/* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
.tile-palette {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
max-height: 600px;
|
||||
}
|
||||
|
||||
.tile-swatch {
|
||||
position: relative;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border: 2px solid transparent;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.tile-swatch.active {
|
||||
border-color: #fff;
|
||||
}
|
||||
|
||||
.tile-swatch-icon {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.dpad {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 2rem);
|
||||
grid-template-rows: repeat(3, 2rem);
|
||||
grid-template-areas:
|
||||
". n ."
|
||||
"w . e"
|
||||
". s .";
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.dpad-n { grid-area: n; }
|
||||
.dpad-w { grid-area: w; }
|
||||
.dpad-e { grid-area: e; }
|
||||
.dpad-s { grid-area: s; }
|
||||
.dpad button { padding: 0; }
|
||||
|
||||
.tile-grid {
|
||||
image-rendering: pixelated;
|
||||
cursor: crosshair;
|
||||
touch-action: none;
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
#previewCanvas {
|
||||
width: 100%;
|
||||
aspect-ratio: 1 / 1;
|
||||
height: auto;
|
||||
}
|
||||
@@ -1,918 +0,0 @@
|
||||
// Copyright (c) 2026 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
"use strict";
|
||||
|
||||
(() => {
|
||||
const SHAPES = [
|
||||
{ type: ChunkTerrain.TILE_SHAPE_NULL, name: "Erase", color: "#20232a" },
|
||||
{ type: ChunkTerrain.TILE_SHAPE_GROUND, name: "Ground", color: "#4caf50" },
|
||||
{ type: ChunkTerrain.TILE_SHAPE_RAMP_NORTH, name: "Ramp North", color: "#2196f3" },
|
||||
{ type: ChunkTerrain.TILE_SHAPE_RAMP_EAST, name: "Ramp East", color: "#03a9f4" },
|
||||
{ type: ChunkTerrain.TILE_SHAPE_RAMP_SOUTH, name: "Ramp South", color: "#00bcd4" },
|
||||
{ type: ChunkTerrain.TILE_SHAPE_RAMP_WEST, name: "Ramp West", color: "#009688" },
|
||||
{ type: ChunkTerrain.TILE_SHAPE_RAMP_NORTHEAST, name: "Ramp NE", color: "#ff9800" },
|
||||
{ type: ChunkTerrain.TILE_SHAPE_RAMP_NORTHWEST, name: "Ramp NW", color: "#ff5722" },
|
||||
{ type: ChunkTerrain.TILE_SHAPE_RAMP_SOUTHEAST, name: "Ramp SE", color: "#9c27b0" },
|
||||
{ type: ChunkTerrain.TILE_SHAPE_RAMP_SOUTHWEST, name: "Ramp SW", color: "#e91e63" },
|
||||
{ type: ChunkTerrain.TILE_SHAPE_RAMP_NORTHEAST_INNER, name: "Ramp NE Inner", color: "#795548" },
|
||||
{ type: ChunkTerrain.TILE_SHAPE_RAMP_NORTHWEST_INNER, name: "Ramp NW Inner", color: "#607d8b" },
|
||||
{ type: ChunkTerrain.TILE_SHAPE_RAMP_SOUTHEAST_INNER, name: "Ramp SE Inner", color: "#8bc34a" },
|
||||
{ type: ChunkTerrain.TILE_SHAPE_RAMP_SOUTHWEST_INNER, name: "Ramp SW Inner", color: "#ffc107" },
|
||||
];
|
||||
const SHAPE_COLORS = Object.fromEntries(SHAPES.map((s) => [s.type, s.color]));
|
||||
|
||||
// Arrow direction per ramp, in canvas/screen space: north is up (dy < 0),
|
||||
// east is right (dx > 0) - matches renderGrid()'s north-is-up convention.
|
||||
const SHAPE_DIRECTIONS = {
|
||||
[ChunkTerrain.TILE_SHAPE_RAMP_NORTH]: { dx: 0, dy: -1 },
|
||||
[ChunkTerrain.TILE_SHAPE_RAMP_SOUTH]: { dx: 0, dy: 1 },
|
||||
[ChunkTerrain.TILE_SHAPE_RAMP_EAST]: { dx: 1, dy: 0 },
|
||||
[ChunkTerrain.TILE_SHAPE_RAMP_WEST]: { dx: -1, dy: 0 },
|
||||
[ChunkTerrain.TILE_SHAPE_RAMP_NORTHEAST]: { dx: 1, dy: -1 },
|
||||
[ChunkTerrain.TILE_SHAPE_RAMP_NORTHWEST]: { dx: -1, dy: -1 },
|
||||
[ChunkTerrain.TILE_SHAPE_RAMP_SOUTHEAST]: { dx: 1, dy: 1 },
|
||||
[ChunkTerrain.TILE_SHAPE_RAMP_SOUTHWEST]: { dx: -1, dy: 1 },
|
||||
[ChunkTerrain.TILE_SHAPE_RAMP_NORTHEAST_INNER]: { dx: 1, dy: -1 },
|
||||
[ChunkTerrain.TILE_SHAPE_RAMP_NORTHWEST_INNER]: { dx: -1, dy: -1 },
|
||||
[ChunkTerrain.TILE_SHAPE_RAMP_SOUTHEAST_INNER]: { dx: 1, dy: 1 },
|
||||
[ChunkTerrain.TILE_SHAPE_RAMP_SOUTHWEST_INNER]: { dx: -1, dy: 1 },
|
||||
};
|
||||
|
||||
const INNER_CORNER_SHAPES = new Set([
|
||||
ChunkTerrain.TILE_SHAPE_RAMP_NORTHEAST_INNER,
|
||||
ChunkTerrain.TILE_SHAPE_RAMP_NORTHWEST_INNER,
|
||||
ChunkTerrain.TILE_SHAPE_RAMP_SOUTHEAST_INNER,
|
||||
ChunkTerrain.TILE_SHAPE_RAMP_SOUTHWEST_INNER,
|
||||
]);
|
||||
|
||||
// Draws a single-headed arrow from (tailX, tailY) to (tipX, tipY).
|
||||
function drawArrowSegment(ctx, tailX, tailY, tipX, tipY, size) {
|
||||
ctx.strokeStyle = "#ffffff";
|
||||
ctx.fillStyle = "#ffffff";
|
||||
ctx.lineWidth = Math.max(1, size * 0.08);
|
||||
ctx.lineCap = "round";
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(tailX, tailY);
|
||||
ctx.lineTo(tipX, tipY);
|
||||
ctx.stroke();
|
||||
|
||||
const headLen = size * 0.18;
|
||||
const angle = Math.atan2(tipY - tailY, tipX - tailX);
|
||||
const leftAngle = angle + Math.PI * 0.8;
|
||||
const rightAngle = angle - Math.PI * 0.8;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(tipX, tipY);
|
||||
ctx.lineTo(tipX + Math.cos(leftAngle) * headLen, tipY + Math.sin(leftAngle) * headLen);
|
||||
ctx.lineTo(tipX + Math.cos(rightAngle) * headLen, tipY + Math.sin(rightAngle) * headLen);
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
// Draws an arrow centered at (cx, cy) pointing toward the ramp's high
|
||||
// side, so ramp direction is visible at a glance on both the palette
|
||||
// swatches and the tile grid. Used for cardinal ramps and outer-corner
|
||||
// ramps (a single raised corner).
|
||||
function drawArrow(ctx, cx, cy, size, dx, dy) {
|
||||
const mag = Math.hypot(dx, dy) || 1;
|
||||
const ux = dx / mag, uy = dy / mag;
|
||||
const len = size * 0.32;
|
||||
drawArrowSegment(ctx, cx - ux * len, cy - uy * len, cx + ux * len, cy + uy * len, size);
|
||||
}
|
||||
|
||||
// Draws a plain right-angle bracket - two line segments meeting at 90
|
||||
// degrees at the tile's corner, one running along each of the two edges
|
||||
// adjacent to it - so inner-corner ramps (three corners raised, one
|
||||
// dropped) read as "the adjacent sides meeting in a 90-degree corner",
|
||||
// distinct from the single diagonal arrow used for outer-corner ramps.
|
||||
function drawCornerBracket(ctx, cx, cy, size, dx, dy) {
|
||||
const cornerDist = size * 0.42;
|
||||
const armLen = size * 0.34;
|
||||
const cornerX = cx + dx * cornerDist;
|
||||
const cornerY = cy + dy * cornerDist;
|
||||
|
||||
ctx.strokeStyle = "#ffffff";
|
||||
ctx.lineWidth = Math.max(1, size * 0.08);
|
||||
ctx.lineCap = "round";
|
||||
ctx.lineJoin = "round";
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(cornerX - dx * armLen, cornerY);
|
||||
ctx.lineTo(cornerX, cornerY);
|
||||
ctx.lineTo(cornerX, cornerY - dy * armLen);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
// Draws the direction icon for a ramp tile `type` in a `size`x`size` area
|
||||
// centered at (cx, cy): a diagonal arrow for cardinal/outer-corner ramps,
|
||||
// or a right-angle bracket for inner-corner ramps. No-op for shapes with
|
||||
// no direction (ground, erase).
|
||||
function drawShapeIcon(ctx, cx, cy, size, type) {
|
||||
const dir = SHAPE_DIRECTIONS[type];
|
||||
if(!dir) return;
|
||||
if(INNER_CORNER_SHAPES.has(type)) {
|
||||
drawCornerBracket(ctx, cx, cy, size, dir.dx, dir.dy);
|
||||
} else {
|
||||
drawArrow(ctx, cx, cy, size, dir.dx, dir.dy);
|
||||
}
|
||||
}
|
||||
|
||||
// Draws a small pencil icon centered in a `size`x`size` canvas.
|
||||
function drawPencilIcon(ctx, size) {
|
||||
ctx.save();
|
||||
ctx.translate(size / 2, size / 2);
|
||||
ctx.rotate(-Math.PI / 4);
|
||||
|
||||
const shaftW = size * 0.18;
|
||||
const shaftH = size * 0.62;
|
||||
|
||||
ctx.fillStyle = "#e0e0e0";
|
||||
ctx.fillRect(-shaftW / 2, shaftH * 0.28, shaftW, shaftH * 0.22);
|
||||
|
||||
ctx.fillStyle = "#f0c419";
|
||||
ctx.fillRect(-shaftW / 2, -shaftH * 0.5, shaftW, shaftH * 0.78);
|
||||
|
||||
ctx.fillStyle = "#8d6e63";
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(-shaftW / 2, -shaftH * 0.5);
|
||||
ctx.lineTo(shaftW / 2, -shaftH * 0.5);
|
||||
ctx.lineTo(0, -shaftH * 0.5 - shaftW);
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
// Draws a small paint bucket icon centered in a `size`x`size` canvas.
|
||||
function drawBucketIcon(ctx, size) {
|
||||
ctx.save();
|
||||
ctx.translate(size / 2, size / 2);
|
||||
|
||||
const w = size * 0.5, h = size * 0.34;
|
||||
|
||||
ctx.strokeStyle = "#e0e0e0";
|
||||
ctx.lineWidth = Math.max(1, size * 0.06);
|
||||
ctx.beginPath();
|
||||
ctx.arc(0, -h * 0.4, w * 0.4, Math.PI, 0);
|
||||
ctx.stroke();
|
||||
|
||||
ctx.fillStyle = "#03a9f4";
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(-w / 2, -h * 0.2);
|
||||
ctx.lineTo(w / 2, -h * 0.2);
|
||||
ctx.lineTo(w * 0.32, h * 0.6);
|
||||
ctx.lineTo(-w * 0.32, h * 0.6);
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.arc(-w * 0.55, h * 0.75, size * 0.06, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
const TOOLS = [
|
||||
{ id: "pencil", name: "Pencil", draw: drawPencilIcon },
|
||||
{ id: "bucket", name: "Paint Bucket", draw: drawBucketIcon },
|
||||
];
|
||||
|
||||
let coord = { x: 0, y: 0, z: 0 };
|
||||
let tiles = new Int32Array(ChunkTerrain.TILE_COUNT);
|
||||
let meshes = [];
|
||||
let chunkExists = false;
|
||||
let currentZLevel = 0;
|
||||
let selectedShape = ChunkTerrain.TILE_SHAPE_GROUND;
|
||||
let zoomWorldH = 20;
|
||||
let dirty = false;
|
||||
let hoverTile = null;
|
||||
let activeTool = "pencil";
|
||||
|
||||
let mapRenderer = null;
|
||||
let terrainMesh = null;
|
||||
let gridLinesMesh = null;
|
||||
let terrainTexturePromise = null;
|
||||
let modelIndex = null;
|
||||
let neighborChunks = [];
|
||||
const modelCache = new Map();
|
||||
|
||||
const UNDO_LIMIT = 100;
|
||||
let undoStack = [];
|
||||
|
||||
function markDirty() {
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
function snapshotState() {
|
||||
return {
|
||||
tiles: tiles.slice(),
|
||||
meshes: meshes.map((m) => ({ file: m.file, pos: m.pos.slice() })),
|
||||
};
|
||||
}
|
||||
|
||||
function pushUndo() {
|
||||
undoStack.push(snapshotState());
|
||||
if(undoStack.length > UNDO_LIMIT) undoStack.shift();
|
||||
}
|
||||
|
||||
function undo() {
|
||||
if(!undoStack.length) return;
|
||||
const snap = undoStack.pop();
|
||||
tiles = snap.tiles;
|
||||
meshes = snap.meshes;
|
||||
dirty = true;
|
||||
renderGrid();
|
||||
renderMeshList();
|
||||
renderPreview();
|
||||
updateStatus("Undid last change.");
|
||||
}
|
||||
|
||||
// Returns true if it's OK to proceed (no unsaved changes, or the user
|
||||
// confirmed discarding them).
|
||||
function confirmDiscardIfDirty() {
|
||||
if(!dirty) return true;
|
||||
return window.confirm("You have unsaved changes to this chunk. Discard them?");
|
||||
}
|
||||
|
||||
function statusLine() {
|
||||
return document.getElementById("statusLine");
|
||||
}
|
||||
|
||||
function updateStatus(msg, isError) {
|
||||
const el = statusLine();
|
||||
el.textContent = msg;
|
||||
el.classList.toggle("text-danger", !!isError);
|
||||
el.classList.toggle("text-muted", !isError);
|
||||
}
|
||||
|
||||
async function apiReadJson(path) {
|
||||
const res = await fetch(`/api/read?path=${encodeURIComponent(path)}`);
|
||||
const data = await res.json();
|
||||
return { ok: res.ok, data };
|
||||
}
|
||||
|
||||
async function apiWrite(path, content) {
|
||||
return fetch(`/api/write?path=${encodeURIComponent(path)}`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ content }),
|
||||
});
|
||||
}
|
||||
|
||||
async function apiDelete(path) {
|
||||
return fetch(`/api/delete?path=${encodeURIComponent(path)}`, { method: "POST" });
|
||||
}
|
||||
|
||||
async function apiCompileChunk(x, y, z) {
|
||||
const res = await fetch(`/api/compile-chunk?x=${x}&y=${y}&z=${z}`, { method: "POST" });
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function apiLs(path) {
|
||||
const res = await fetch(`/api/ls?path=${encodeURIComponent(path)}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function apiFind(path, ext) {
|
||||
const res = await fetch(`/api/find?path=${encodeURIComponent(path)}&ext=${encodeURIComponent(ext)}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
function base64ToBuffer(base64) {
|
||||
const bytes = Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
|
||||
return bytes.buffer;
|
||||
}
|
||||
|
||||
async function loadImageTexture(assetPath) {
|
||||
const { ok, data } = await apiReadJson(assetPath);
|
||||
if(!ok || data.error) return null;
|
||||
const blob = new Blob([base64ToBuffer(data.content)], { type: "image/png" });
|
||||
const bitmap = await createImageBitmap(blob);
|
||||
return mapRenderer.createTextureFromImage(bitmap);
|
||||
}
|
||||
|
||||
async function readDmfVertices(assetPath) {
|
||||
const { ok, data } = await apiReadJson(assetPath);
|
||||
if(!ok || data.error) throw new Error(`Failed to read ${assetPath}`);
|
||||
return DMF.decode(base64ToBuffer(data.content)).floats;
|
||||
}
|
||||
|
||||
async function ensureModelIndex() {
|
||||
if(modelIndex) return modelIndex;
|
||||
const res = await apiFind("assets/models", ".json");
|
||||
modelIndex = new Map();
|
||||
for(const file of res.files || []) {
|
||||
const base = file.split("/").pop().replace(/\.json$/, "");
|
||||
modelIndex.set(base, file);
|
||||
}
|
||||
return modelIndex;
|
||||
}
|
||||
|
||||
// Scales a mesh's stored [x, y, z] offset for preview, matching the
|
||||
// Z scaling mapChunkLoaded() applies at runtime (chunk.meshOffsets[m][2]
|
||||
// * WORLD_LAYER_HEIGHT) - x/y stay 1:1 since only Z is height-scaled.
|
||||
function scaledMeshOffset(pos) {
|
||||
return [pos[0], pos[1], pos[2] * ChunkTerrain.WORLD_LAYER_HEIGHT];
|
||||
}
|
||||
|
||||
// Resolves a chunk mesh entry's bare filename (e.g. "house_5_3.dmf") to
|
||||
// its model JSON by basename, mirroring find_model() in
|
||||
// tools/asset/chunk/__main__.py - the chunk JSON only ever stores a bare
|
||||
// filename, not a path.
|
||||
async function resolveModelForMeshFile(file) {
|
||||
await ensureModelIndex();
|
||||
const base = file.replace(/\.[^.]+$/, "");
|
||||
const rel = modelIndex.get(base);
|
||||
if(!rel) return null;
|
||||
|
||||
const modelPath = `assets/models/${rel}`;
|
||||
if(modelCache.has(modelPath)) return modelCache.get(modelPath);
|
||||
|
||||
const promise = (async () => {
|
||||
const { ok, data } = await apiReadJson(modelPath);
|
||||
if(!ok || data.error) throw new Error(`Failed to read model ${modelPath}`);
|
||||
const modelDef = JSON.parse(data.content);
|
||||
const meshFloats = await readDmfVertices(`assets/${modelDef.mesh}`);
|
||||
const mesh = mapRenderer.createMesh(meshFloats);
|
||||
const texture = modelDef.texture ? await loadImageTexture(`assets/${modelDef.texture}`) : null;
|
||||
const colorBytes = modelDef.color || [255, 255, 255, 255];
|
||||
const color = colorBytes.map((c) => c / 255);
|
||||
return { mesh, texture, color };
|
||||
})();
|
||||
modelCache.set(modelPath, promise);
|
||||
return promise;
|
||||
}
|
||||
|
||||
function chunkPaths(x, y, z) {
|
||||
return {
|
||||
raw: `assetsraw/chunks/chunk_${x}_${y}_${z}.json`,
|
||||
dcf: `assets/chunks/${x}_${y}_${z}.dcf`,
|
||||
terrainDmf: `assets/meshes/chunks/chunk_${x}_${y}_${z}_0.dmf`,
|
||||
terrainModel: `assets/models/chunks/chunk_${x}_${y}_${z}_0.json`,
|
||||
};
|
||||
}
|
||||
|
||||
// Loads the 8 same-Z neighbors around `coord` (read-only, for context in
|
||||
// the 3D preview) and pre-builds their render data so renderPreview()
|
||||
// doesn't have to rebuild GL buffers on every paint stroke.
|
||||
async function loadNeighborChunks() {
|
||||
const offsets = [];
|
||||
for(let dy = -1; dy <= 1; dy++) {
|
||||
for(let dx = -1; dx <= 1; dx++) {
|
||||
if(dx || dy) offsets.push({ dx, dy });
|
||||
}
|
||||
}
|
||||
|
||||
const results = await Promise.all(offsets.map(async ({ dx, dy }) => {
|
||||
const nx = coord.x + dx, ny = coord.y + dy, nz = coord.z;
|
||||
const { ok, data } = await apiReadJson(chunkPaths(nx, ny, nz).raw);
|
||||
if(!ok || data.error) return null;
|
||||
|
||||
const json = JSON.parse(data.content);
|
||||
const neighborTiles = new Int32Array(ChunkTerrain.TILE_COUNT);
|
||||
for(const t of json.tiles || []) {
|
||||
const [tx, ty, tz] = t.pos;
|
||||
neighborTiles[ChunkTerrain.tileIndex(tx, ty, tz)] = t.type;
|
||||
}
|
||||
const neighborMeshes = (json.meshes || []).map((m) => ({ file: m.file, pos: m.pos || [0, 0, 0] }));
|
||||
|
||||
const floats = ChunkTerrain.buildTerrainVerts(neighborTiles);
|
||||
const terrain = floats.length ? { mesh: mapRenderer.createMesh(floats) } : null;
|
||||
|
||||
const models = [];
|
||||
for(const m of neighborMeshes) {
|
||||
try {
|
||||
const resolved = await resolveModelForMeshFile(m.file);
|
||||
if(resolved) models.push({ ...resolved, offset: scaledMeshOffset(m.pos) });
|
||||
} catch(e) {
|
||||
console.warn("Failed to load neighbor mesh preview", m.file, e);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
offset: [dx * ChunkTerrain.CHUNK_WIDTH, dy * ChunkTerrain.CHUNK_HEIGHT, 0],
|
||||
terrain,
|
||||
models,
|
||||
};
|
||||
}));
|
||||
|
||||
neighborChunks = results.filter(Boolean);
|
||||
}
|
||||
|
||||
async function loadChunk(x, y, z) {
|
||||
coord = { x, y, z };
|
||||
tiles = new Int32Array(ChunkTerrain.TILE_COUNT);
|
||||
meshes = [];
|
||||
chunkExists = false;
|
||||
|
||||
const { ok, data } = await apiReadJson(chunkPaths(x, y, z).raw);
|
||||
if(ok && !data.error) {
|
||||
chunkExists = true;
|
||||
const json = JSON.parse(data.content);
|
||||
for(const t of json.tiles || []) {
|
||||
const [tx, ty, tz] = t.pos;
|
||||
tiles[ChunkTerrain.tileIndex(tx, ty, tz)] = t.type;
|
||||
}
|
||||
meshes = (json.meshes || []).map((m) => ({ file: m.file, pos: m.pos || [0, 0, 0] }));
|
||||
}
|
||||
|
||||
await loadNeighborChunks();
|
||||
dirty = false;
|
||||
undoStack = [];
|
||||
|
||||
renderGrid();
|
||||
renderMeshList();
|
||||
renderPreview();
|
||||
updateStatus(chunkExists
|
||||
? `Loaded chunk_${x}_${y}_${z}.json`
|
||||
: `New (empty) chunk at ${x}, ${y}, ${z} - paint a tile and save to create it.`);
|
||||
}
|
||||
|
||||
async function saveChunk() {
|
||||
const tilesArr = [];
|
||||
for(let z = 0; z < ChunkTerrain.CHUNK_DEPTH; z++) {
|
||||
for(let y = 0; y < ChunkTerrain.CHUNK_HEIGHT; y++) {
|
||||
for(let x = 0; x < ChunkTerrain.CHUNK_WIDTH; x++) {
|
||||
const type = tiles[ChunkTerrain.tileIndex(x, y, z)];
|
||||
if(type && type !== ChunkTerrain.TILE_SHAPE_NULL) {
|
||||
tilesArr.push({ pos: [x, y, z], type, tile: 0 });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const paths = chunkPaths(coord.x, coord.y, coord.z);
|
||||
|
||||
if(tilesArr.length === 0 && meshes.length === 0) {
|
||||
await Promise.all(Object.values(paths).map((p) => apiDelete(p)));
|
||||
chunkExists = false;
|
||||
dirty = false;
|
||||
updateStatus(`Chunk ${coord.x}, ${coord.y}, ${coord.z} is empty - deleted.`);
|
||||
return;
|
||||
}
|
||||
|
||||
const json = { tiles: tilesArr, meshes: meshes.map((m) => ({ file: m.file, pos: m.pos })) };
|
||||
await apiWrite(paths.raw, JSON.stringify(json, null, 2));
|
||||
chunkExists = true;
|
||||
dirty = false;
|
||||
updateStatus("Saved. Compiling...");
|
||||
|
||||
const result = await apiCompileChunk(coord.x, coord.y, coord.z);
|
||||
if(result.ok) {
|
||||
updateStatus(`Compiled OK.\n${result.stdout}`);
|
||||
} else {
|
||||
updateStatus(`Compile FAILED (code ${result.returncode}):\n${result.stderr}`, true);
|
||||
}
|
||||
}
|
||||
|
||||
function buildPalette() {
|
||||
const el = document.getElementById("tilePalette");
|
||||
el.innerHTML = "";
|
||||
for(const s of SHAPES) {
|
||||
const btn = document.createElement("button");
|
||||
btn.type = "button";
|
||||
btn.className = "tile-swatch" + (s.type === selectedShape ? " active" : "");
|
||||
btn.style.background = s.color;
|
||||
btn.title = s.name;
|
||||
btn.addEventListener("click", () => {
|
||||
selectedShape = s.type;
|
||||
buildPalette();
|
||||
});
|
||||
|
||||
if(SHAPE_DIRECTIONS[s.type]) {
|
||||
const icon = document.createElement("canvas");
|
||||
icon.width = 32;
|
||||
icon.height = 32;
|
||||
icon.className = "tile-swatch-icon";
|
||||
drawShapeIcon(icon.getContext("2d"), 16, 16, 32, s.type);
|
||||
btn.appendChild(icon);
|
||||
}
|
||||
|
||||
el.appendChild(btn);
|
||||
}
|
||||
}
|
||||
|
||||
function buildToolPalette() {
|
||||
const el = document.getElementById("toolPalette");
|
||||
el.innerHTML = "";
|
||||
for(const tool of TOOLS) {
|
||||
const btn = document.createElement("button");
|
||||
btn.type = "button";
|
||||
btn.className = "tile-swatch" + (tool.id === activeTool ? " active" : "");
|
||||
btn.style.background = "#2a2d33";
|
||||
btn.title = tool.name;
|
||||
btn.addEventListener("click", () => {
|
||||
activeTool = tool.id;
|
||||
buildToolPalette();
|
||||
});
|
||||
|
||||
const icon = document.createElement("canvas");
|
||||
icon.width = 32;
|
||||
icon.height = 32;
|
||||
icon.className = "tile-swatch-icon";
|
||||
tool.draw(icon.getContext("2d"), 32);
|
||||
btn.appendChild(icon);
|
||||
|
||||
el.appendChild(btn);
|
||||
}
|
||||
}
|
||||
|
||||
function canvasToTile(e, canvas) {
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
const cell = canvas.width / ChunkTerrain.CHUNK_WIDTH;
|
||||
const px = (e.clientX - rect.left) * (canvas.width / rect.width);
|
||||
const py = (e.clientY - rect.top) * (canvas.height / rect.height);
|
||||
const x = Math.floor(px / cell);
|
||||
const yFromTop = Math.floor(py / cell);
|
||||
const y = ChunkTerrain.CHUNK_HEIGHT - 1 - yFromTop;
|
||||
if(x < 0 || x >= ChunkTerrain.CHUNK_WIDTH || y < 0 || y >= ChunkTerrain.CHUNK_HEIGHT) return null;
|
||||
return { x, y };
|
||||
}
|
||||
|
||||
function renderGrid() {
|
||||
const canvas = document.getElementById("gridCanvas");
|
||||
const ctx = canvas.getContext("2d");
|
||||
const cell = canvas.width / ChunkTerrain.CHUNK_WIDTH;
|
||||
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
for(let y = 0; y < ChunkTerrain.CHUNK_HEIGHT; y++) {
|
||||
for(let x = 0; x < ChunkTerrain.CHUNK_WIDTH; x++) {
|
||||
const type = tiles[ChunkTerrain.tileIndex(x, y, currentZLevel)];
|
||||
const sy = (ChunkTerrain.CHUNK_HEIGHT - 1 - y) * cell;
|
||||
ctx.fillStyle = SHAPE_COLORS[type] || "#15171b";
|
||||
ctx.fillRect(x * cell, sy, cell, cell);
|
||||
ctx.strokeStyle = "rgba(255, 255, 255, 0.25)";
|
||||
ctx.strokeRect(x * cell, sy, cell, cell);
|
||||
|
||||
drawShapeIcon(ctx, x * cell + cell / 2, sy + cell / 2, cell, type);
|
||||
}
|
||||
}
|
||||
|
||||
ctx.fillStyle = "#ffffff";
|
||||
for(const m of meshes) {
|
||||
const [mx, my, mz] = m.pos;
|
||||
if(Math.round(mz) !== currentZLevel) continue;
|
||||
const sy = (ChunkTerrain.CHUNK_HEIGHT - 1 - my) * cell;
|
||||
ctx.beginPath();
|
||||
ctx.arc(mx * cell + cell / 2, sy + cell / 2, cell * 0.3, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
if(hoverTile) {
|
||||
const sy = (ChunkTerrain.CHUNK_HEIGHT - 1 - hoverTile.y) * cell;
|
||||
ctx.strokeStyle = "#ffeb3b";
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeRect(hoverTile.x * cell + 1, sy + 1, cell - 2, cell - 2);
|
||||
}
|
||||
}
|
||||
|
||||
function hitTestMesh(e, canvas) {
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
const cell = canvas.width / ChunkTerrain.CHUNK_WIDTH;
|
||||
const px = (e.clientX - rect.left) * (canvas.width / rect.width);
|
||||
const py = (e.clientY - rect.top) * (canvas.height / rect.height);
|
||||
|
||||
let closest = -1;
|
||||
let closestDist = cell * 0.5;
|
||||
meshes.forEach((m, i) => {
|
||||
const [mx, my, mz] = m.pos;
|
||||
if(Math.round(mz) !== currentZLevel) return;
|
||||
const cx = mx * cell + cell / 2;
|
||||
const cy = (ChunkTerrain.CHUNK_HEIGHT - 1 - my) * cell + cell / 2;
|
||||
const dist = Math.hypot(px - cx, py - cy);
|
||||
if(dist < closestDist) { closestDist = dist; closest = i; }
|
||||
});
|
||||
return closest;
|
||||
}
|
||||
|
||||
function moveMeshTo(e, index) {
|
||||
const canvas = document.getElementById("gridCanvas");
|
||||
const t = canvasToTile(e, canvas);
|
||||
if(!t) return;
|
||||
meshes[index].pos[0] = t.x;
|
||||
meshes[index].pos[1] = t.y;
|
||||
markDirty();
|
||||
renderGrid();
|
||||
renderMeshList();
|
||||
renderPreview();
|
||||
}
|
||||
|
||||
function paintAt(e) {
|
||||
const canvas = document.getElementById("gridCanvas");
|
||||
const t = canvasToTile(e, canvas);
|
||||
if(!t) return;
|
||||
tiles[ChunkTerrain.tileIndex(t.x, t.y, currentZLevel)] = selectedShape;
|
||||
markDirty();
|
||||
renderGrid();
|
||||
renderPreview();
|
||||
}
|
||||
|
||||
// 4-connected flood fill of same-type tiles at the current Z-level,
|
||||
// starting from (startX, startY), replacing them with selectedShape.
|
||||
function floodFill(startX, startY) {
|
||||
const targetType = tiles[ChunkTerrain.tileIndex(startX, startY, currentZLevel)];
|
||||
if(targetType === selectedShape) return;
|
||||
|
||||
const stack = [[startX, startY]];
|
||||
const visited = new Set();
|
||||
while(stack.length) {
|
||||
const [x, y] = stack.pop();
|
||||
const key = `${x},${y}`;
|
||||
if(visited.has(key)) continue;
|
||||
if(x < 0 || x >= ChunkTerrain.CHUNK_WIDTH || y < 0 || y >= ChunkTerrain.CHUNK_HEIGHT) continue;
|
||||
visited.add(key);
|
||||
|
||||
const idx = ChunkTerrain.tileIndex(x, y, currentZLevel);
|
||||
if(tiles[idx] !== targetType) continue;
|
||||
tiles[idx] = selectedShape;
|
||||
stack.push([x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
function fillAt(e) {
|
||||
const canvas = document.getElementById("gridCanvas");
|
||||
const t = canvasToTile(e, canvas);
|
||||
if(!t) return;
|
||||
pushUndo();
|
||||
floodFill(t.x, t.y);
|
||||
markDirty();
|
||||
renderGrid();
|
||||
renderPreview();
|
||||
}
|
||||
|
||||
function rebuildTerrainMesh() {
|
||||
const floats = ChunkTerrain.buildTerrainVerts(tiles);
|
||||
terrainMesh = floats.length ? mapRenderer.createMesh(floats) : null;
|
||||
|
||||
const lineFloats = ChunkTerrain.buildGridLines(tiles);
|
||||
gridLinesMesh = lineFloats.length ? mapRenderer.createMesh(lineFloats) : null;
|
||||
}
|
||||
|
||||
// Keeps the preview canvas's backing-store resolution matched to its
|
||||
// actual displayed CSS size (times devicePixelRatio) - the canvas
|
||||
// otherwise stays at its fixed width/height attributes (512x512) while
|
||||
// CSS stretches it to fill the column, which upscales and blurs the
|
||||
// WebGL output on wider or high-DPI screens.
|
||||
function resizePreviewCanvas() {
|
||||
const canvas = document.getElementById("previewCanvas");
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
const displayWidth = Math.max(1, Math.round(canvas.clientWidth * dpr));
|
||||
const displayHeight = Math.max(1, Math.round(canvas.clientHeight * dpr));
|
||||
if(canvas.width !== displayWidth || canvas.height !== displayHeight) {
|
||||
canvas.width = displayWidth;
|
||||
canvas.height = displayHeight;
|
||||
}
|
||||
}
|
||||
|
||||
async function renderPreview() {
|
||||
if(!mapRenderer) return;
|
||||
resizePreviewCanvas();
|
||||
rebuildTerrainMesh();
|
||||
|
||||
const models = [];
|
||||
for(const m of meshes) {
|
||||
try {
|
||||
const resolved = await resolveModelForMeshFile(m.file);
|
||||
if(resolved) models.push({ ...resolved, offset: scaledMeshOffset(m.pos) });
|
||||
} catch(e) {
|
||||
console.warn("Failed to load mesh preview", m.file, e);
|
||||
}
|
||||
}
|
||||
|
||||
let terrainTexture = null;
|
||||
if(terrainMesh || neighborChunks.some((n) => n.terrain)) {
|
||||
if(!terrainTexturePromise) terrainTexturePromise = loadImageTexture("assets/tiles.png");
|
||||
terrainTexture = await terrainTexturePromise;
|
||||
}
|
||||
|
||||
const neighbors = neighborChunks.map((n) => ({
|
||||
offset: n.offset,
|
||||
terrain: n.terrain ? { mesh: n.terrain.mesh, texture: terrainTexture } : null,
|
||||
models: n.models,
|
||||
}));
|
||||
|
||||
const zLevelHeight = currentZLevel * ChunkTerrain.WORLD_LAYER_HEIGHT;
|
||||
mapRenderer.render({
|
||||
target: [ChunkTerrain.CHUNK_WIDTH / 2, ChunkTerrain.CHUNK_HEIGHT / 2, zLevelHeight],
|
||||
worldH: zoomWorldH,
|
||||
terrain: terrainMesh ? { mesh: terrainMesh, texture: terrainTexture } : null,
|
||||
gridLines: gridLinesMesh ? { mesh: gridLinesMesh } : null,
|
||||
models,
|
||||
neighbors,
|
||||
highlight: hoverTile ? { x: hoverTile.x, y: hoverTile.y, z: zLevelHeight } : null,
|
||||
});
|
||||
}
|
||||
|
||||
function renderMeshList() {
|
||||
const ul = document.getElementById("meshList");
|
||||
ul.innerHTML = "";
|
||||
meshes.forEach((m, i) => {
|
||||
const li = document.createElement("li");
|
||||
li.className = "list-group-item d-flex align-items-center gap-2 flex-wrap";
|
||||
|
||||
const label = document.createElement("span");
|
||||
label.className = "me-auto";
|
||||
label.textContent = m.file;
|
||||
li.appendChild(label);
|
||||
|
||||
["X", "Y", "Z"].forEach((axis, axisIndex) => {
|
||||
const input = document.createElement("input");
|
||||
input.type = "number";
|
||||
input.className = "form-control form-control-sm";
|
||||
input.style.width = "5rem";
|
||||
input.title = axis;
|
||||
input.value = m.pos[axisIndex];
|
||||
input.addEventListener("change", () => {
|
||||
pushUndo();
|
||||
m.pos[axisIndex] = parseFloat(input.value) || 0;
|
||||
markDirty();
|
||||
renderGrid();
|
||||
renderPreview();
|
||||
});
|
||||
li.appendChild(input);
|
||||
});
|
||||
|
||||
const btn = document.createElement("button");
|
||||
btn.type = "button";
|
||||
btn.className = "btn btn-sm btn-outline-danger";
|
||||
btn.textContent = "Remove";
|
||||
btn.addEventListener("click", () => {
|
||||
pushUndo();
|
||||
meshes.splice(i, 1);
|
||||
markDirty();
|
||||
renderMeshList();
|
||||
renderGrid();
|
||||
renderPreview();
|
||||
});
|
||||
|
||||
li.appendChild(btn);
|
||||
ul.appendChild(li);
|
||||
});
|
||||
}
|
||||
|
||||
async function buildMeshPicker() {
|
||||
await ensureModelIndex();
|
||||
const select = document.getElementById("meshPicker");
|
||||
select.innerHTML = "";
|
||||
for(const [base, rel] of [...modelIndex.entries()].sort()) {
|
||||
const opt = document.createElement("option");
|
||||
opt.value = base;
|
||||
opt.textContent = rel;
|
||||
select.appendChild(opt);
|
||||
}
|
||||
}
|
||||
|
||||
async function buildChunkBrowseList() {
|
||||
const list = document.getElementById("chunkBrowseList");
|
||||
list.innerHTML = "";
|
||||
const res = await apiLs("assetsraw/chunks");
|
||||
for(const entry of res.entries || []) {
|
||||
const m = entry.name.match(/^chunk_(-?\d+)_(-?\d+)_(-?\d+)\.json$/);
|
||||
if(!m) continue;
|
||||
const [, x, y, z] = m;
|
||||
|
||||
const li = document.createElement("li");
|
||||
const a = document.createElement("a");
|
||||
a.className = "dropdown-item";
|
||||
a.href = "#";
|
||||
a.textContent = `${x}, ${y}, ${z}`;
|
||||
a.addEventListener("click", (e) => {
|
||||
e.preventDefault();
|
||||
goToChunk(parseInt(x, 10), parseInt(y, 10), parseInt(z, 10));
|
||||
});
|
||||
|
||||
li.appendChild(a);
|
||||
list.appendChild(li);
|
||||
}
|
||||
}
|
||||
|
||||
function setCoordInputs(x, y, z) {
|
||||
document.getElementById("coordX").value = x;
|
||||
document.getElementById("coordY").value = y;
|
||||
document.getElementById("coordZ").value = z;
|
||||
}
|
||||
|
||||
function goToChunk(x, y, z) {
|
||||
if(!confirmDiscardIfDirty()) return;
|
||||
setCoordInputs(x, y, z);
|
||||
loadChunk(x, y, z);
|
||||
}
|
||||
|
||||
function bindEvents() {
|
||||
const gridCanvas = document.getElementById("gridCanvas");
|
||||
let painting = false;
|
||||
let draggingMeshIndex = -1;
|
||||
|
||||
gridCanvas.addEventListener("mousedown", (e) => {
|
||||
if(activeTool === "bucket") {
|
||||
fillAt(e);
|
||||
return;
|
||||
}
|
||||
|
||||
const hit = hitTestMesh(e, gridCanvas);
|
||||
pushUndo();
|
||||
if(hit !== -1) {
|
||||
draggingMeshIndex = hit;
|
||||
return;
|
||||
}
|
||||
painting = true;
|
||||
paintAt(e);
|
||||
});
|
||||
window.addEventListener("mouseup", () => { painting = false; draggingMeshIndex = -1; });
|
||||
gridCanvas.addEventListener("mousemove", (e) => {
|
||||
hoverTile = canvasToTile(e, gridCanvas);
|
||||
if(draggingMeshIndex !== -1) { moveMeshTo(e, draggingMeshIndex); return; }
|
||||
if(painting) { paintAt(e); return; }
|
||||
renderGrid();
|
||||
renderPreview();
|
||||
});
|
||||
gridCanvas.addEventListener("mouseleave", () => {
|
||||
hoverTile = null;
|
||||
renderGrid();
|
||||
renderPreview();
|
||||
});
|
||||
|
||||
function setZLevel(z) {
|
||||
currentZLevel = Math.max(0, Math.min(ChunkTerrain.CHUNK_DEPTH - 1, z));
|
||||
document.getElementById("zLevel").value = currentZLevel;
|
||||
document.getElementById("zLevelLabel").textContent = currentZLevel;
|
||||
renderGrid();
|
||||
renderPreview();
|
||||
}
|
||||
|
||||
document.getElementById("zLevel").addEventListener("input", (e) => {
|
||||
setZLevel(parseInt(e.target.value, 10));
|
||||
});
|
||||
document.getElementById("zLevelDown").addEventListener("click", () => setZLevel(currentZLevel - 1));
|
||||
document.getElementById("zLevelUp").addEventListener("click", () => setZLevel(currentZLevel + 1));
|
||||
|
||||
document.getElementById("btnLoad").addEventListener("click", () => {
|
||||
const x = parseInt(document.getElementById("coordX").value, 10) || 0;
|
||||
const y = parseInt(document.getElementById("coordY").value, 10) || 0;
|
||||
const z = parseInt(document.getElementById("coordZ").value, 10) || 0;
|
||||
goToChunk(x, y, z);
|
||||
});
|
||||
|
||||
// NORTH=+Y, EAST=+X (matches tile-shape convention used by the tile
|
||||
// grid and tools/asset/chunk/__main__.py).
|
||||
document.getElementById("navN").addEventListener("click", () => goToChunk(coord.x, coord.y + 1, coord.z));
|
||||
document.getElementById("navS").addEventListener("click", () => goToChunk(coord.x, coord.y - 1, coord.z));
|
||||
document.getElementById("navE").addEventListener("click", () => goToChunk(coord.x + 1, coord.y, coord.z));
|
||||
document.getElementById("navW").addEventListener("click", () => goToChunk(coord.x - 1, coord.y, coord.z));
|
||||
document.getElementById("navUp").addEventListener("click", () => goToChunk(coord.x, coord.y, coord.z + 1));
|
||||
document.getElementById("navDown").addEventListener("click", () => goToChunk(coord.x, coord.y, coord.z - 1));
|
||||
|
||||
function runSave() {
|
||||
saveChunk().catch((e) => updateStatus(`Save failed: ${e.message}`, true));
|
||||
}
|
||||
|
||||
document.getElementById("btnSave").addEventListener("click", runSave);
|
||||
|
||||
document.getElementById("btnAddMesh").addEventListener("click", () => {
|
||||
const base = document.getElementById("meshPicker").value;
|
||||
if(!base) return;
|
||||
const pos = [
|
||||
parseFloat(document.getElementById("meshX").value) || 0,
|
||||
parseFloat(document.getElementById("meshY").value) || 0,
|
||||
parseFloat(document.getElementById("meshZ").value) || 0,
|
||||
];
|
||||
pushUndo();
|
||||
meshes.push({ file: `${base}.dmf`, pos });
|
||||
markDirty();
|
||||
renderMeshList();
|
||||
renderGrid();
|
||||
renderPreview();
|
||||
});
|
||||
|
||||
document.getElementById("previewCanvas").addEventListener("wheel", (e) => {
|
||||
e.preventDefault();
|
||||
zoomWorldH = Math.min(60, Math.max(4, zoomWorldH + Math.sign(e.deltaY)));
|
||||
renderPreview();
|
||||
}, { passive: false });
|
||||
|
||||
window.addEventListener("resize", () => renderPreview());
|
||||
|
||||
window.addEventListener("keydown", (e) => {
|
||||
if(!(e.ctrlKey || e.metaKey)) return;
|
||||
const key = e.key.toLowerCase();
|
||||
if(key === "z") {
|
||||
e.preventDefault();
|
||||
undo();
|
||||
} else if(key === "s") {
|
||||
e.preventDefault();
|
||||
runSave();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
buildPalette();
|
||||
buildToolPalette();
|
||||
mapRenderer = MapRenderer.create(document.getElementById("previewCanvas"));
|
||||
bindEvents();
|
||||
await Promise.all([buildChunkBrowseList(), buildMeshPicker()]);
|
||||
await loadChunk(coord.x, coord.y, coord.z);
|
||||
});
|
||||
})();
|
||||
@@ -1,298 +0,0 @@
|
||||
// Copyright (c) 2026 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
"use strict";
|
||||
|
||||
// MapRenderer - a minimal, dependency-free WebGL renderer for the chunk
|
||||
// preview pane. The camera formula is ported 1:1 from
|
||||
// src/dusk/scene/overworld/sceneoverworld.c (lines 62-81) so the preview
|
||||
// approximates the game's own fixed-angle 3rd-person camera: the eye sits
|
||||
// worldH units "behind" the target along Y and a proportional distance
|
||||
// "above" along Z, always looking at the target, up = (0, 1, 0).
|
||||
//
|
||||
// The material model mirrors SHADER_UNLIT: a texture sampler multiplied by
|
||||
// a flat RGBA tint, with a 1x1 white fallback texture standing in for
|
||||
// untextured models.
|
||||
|
||||
const MapRenderer = (() => {
|
||||
const VERT_SRC = `
|
||||
attribute vec2 aUV;
|
||||
attribute vec3 aPos;
|
||||
uniform mat4 uModel;
|
||||
uniform mat4 uView;
|
||||
uniform mat4 uProjection;
|
||||
varying vec2 vUV;
|
||||
void main() {
|
||||
vUV = aUV;
|
||||
gl_Position = uProjection * uView * uModel * vec4(aPos, 1.0);
|
||||
}
|
||||
`;
|
||||
|
||||
const FRAG_SRC = `
|
||||
precision mediump float;
|
||||
varying vec2 vUV;
|
||||
uniform sampler2D uTexture;
|
||||
uniform vec4 uColor;
|
||||
void main() {
|
||||
gl_FragColor = texture2D(uTexture, vUV) * uColor;
|
||||
}
|
||||
`;
|
||||
|
||||
function mat4Identity(out) {
|
||||
out.fill(0);
|
||||
out[0] = out[5] = out[10] = out[15] = 1;
|
||||
return out;
|
||||
}
|
||||
|
||||
function mat4Translation(out, v) {
|
||||
mat4Identity(out);
|
||||
out[12] = v[0];
|
||||
out[13] = v[1];
|
||||
out[14] = v[2];
|
||||
return out;
|
||||
}
|
||||
|
||||
function mat4Perspective(out, fovy, aspect, near, far) {
|
||||
const f = 1.0 / Math.tan(fovy / 2);
|
||||
out.fill(0);
|
||||
out[0] = f / aspect;
|
||||
out[5] = f;
|
||||
out[10] = (far + near) / (near - far);
|
||||
out[11] = -1;
|
||||
out[14] = (2 * far * near) / (near - far);
|
||||
return out;
|
||||
}
|
||||
|
||||
function vec3Sub(a, b) {
|
||||
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
||||
}
|
||||
|
||||
function vec3Cross(a, b) {
|
||||
return [
|
||||
a[1] * b[2] - a[2] * b[1],
|
||||
a[2] * b[0] - a[0] * b[2],
|
||||
a[0] * b[1] - a[1] * b[0],
|
||||
];
|
||||
}
|
||||
|
||||
function vec3Normalize(a) {
|
||||
const len = Math.hypot(a[0], a[1], a[2]) || 1;
|
||||
return [a[0] / len, a[1] / len, a[2] / len];
|
||||
}
|
||||
|
||||
function mat4LookAt(out, eye, center, up) {
|
||||
const zAxis = vec3Normalize(vec3Sub(eye, center));
|
||||
const xAxis = vec3Normalize(vec3Cross(up, zAxis));
|
||||
const yAxis = vec3Cross(zAxis, xAxis);
|
||||
|
||||
out[0] = xAxis[0]; out[1] = yAxis[0]; out[2] = zAxis[0]; out[3] = 0;
|
||||
out[4] = xAxis[1]; out[5] = yAxis[1]; out[6] = zAxis[1]; out[7] = 0;
|
||||
out[8] = xAxis[2]; out[9] = yAxis[2]; out[10] = zAxis[2]; out[11] = 0;
|
||||
out[12] = -(xAxis[0] * eye[0] + xAxis[1] * eye[1] + xAxis[2] * eye[2]);
|
||||
out[13] = -(yAxis[0] * eye[0] + yAxis[1] * eye[1] + yAxis[2] * eye[2]);
|
||||
out[14] = -(zAxis[0] * eye[0] + zAxis[1] * eye[1] + zAxis[2] * eye[2]);
|
||||
out[15] = 1;
|
||||
return out;
|
||||
}
|
||||
|
||||
// Ported from sceneoverworld.c:62-81. Returns { eye, view }.
|
||||
function computeCamera(target, worldH) {
|
||||
const fov = Math.PI / 4; // glm_rad(45.0f)
|
||||
const zDist = (worldH * 0.5) / Math.tan(fov * 0.5);
|
||||
const offset = -worldH;
|
||||
|
||||
const eye = [target[0], target[1] + offset, target[2] + zDist];
|
||||
const view = mat4LookAt(new Float32Array(16), eye, target, [0, 1, 0]);
|
||||
return { eye, view, fov };
|
||||
}
|
||||
|
||||
function compileShader(gl, type, src) {
|
||||
const shader = gl.createShader(type);
|
||||
gl.shaderSource(shader, src);
|
||||
gl.compileShader(shader);
|
||||
if(!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
||||
const info = gl.getShaderInfoLog(shader);
|
||||
gl.deleteShader(shader);
|
||||
throw new Error(`Shader compile failed: ${info}`);
|
||||
}
|
||||
return shader;
|
||||
}
|
||||
|
||||
function create(canvas) {
|
||||
const gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
|
||||
if(!gl) throw new Error("WebGL is not available in this browser");
|
||||
|
||||
const program = gl.createProgram();
|
||||
gl.attachShader(program, compileShader(gl, gl.VERTEX_SHADER, VERT_SRC));
|
||||
gl.attachShader(program, compileShader(gl, gl.FRAGMENT_SHADER, FRAG_SRC));
|
||||
gl.linkProgram(program);
|
||||
if(!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
||||
throw new Error(`Program link failed: ${gl.getProgramInfoLog(program)}`);
|
||||
}
|
||||
|
||||
const attribs = {
|
||||
aUV: gl.getAttribLocation(program, "aUV"),
|
||||
aPos: gl.getAttribLocation(program, "aPos"),
|
||||
};
|
||||
const uniforms = {
|
||||
uModel: gl.getUniformLocation(program, "uModel"),
|
||||
uView: gl.getUniformLocation(program, "uView"),
|
||||
uProjection: gl.getUniformLocation(program, "uProjection"),
|
||||
uTexture: gl.getUniformLocation(program, "uTexture"),
|
||||
uColor: gl.getUniformLocation(program, "uColor"),
|
||||
};
|
||||
|
||||
const whiteTexture = gl.createTexture();
|
||||
gl.bindTexture(gl.TEXTURE_2D, whiteTexture);
|
||||
gl.texImage2D(
|
||||
gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE,
|
||||
new Uint8Array([255, 255, 255, 255]),
|
||||
);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
||||
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
gl.enable(gl.BLEND);
|
||||
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
||||
// Terrain/mesh winding isn't guaranteed consistent relative to this
|
||||
// preview's fixed camera angle, so backface culling stays off - this
|
||||
// is an authoring preview, not a performance-sensitive renderer, and
|
||||
// an invisible mesh is a worse failure mode than a visible backface.
|
||||
|
||||
// Uploads interleaved [u, v, x, y, z] float data (DMF/terrain layout)
|
||||
// into a GL buffer. Returns { buffer, vertexCount }.
|
||||
function createMesh(floats) {
|
||||
const buffer = gl.createBuffer();
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, floats, gl.STATIC_DRAW);
|
||||
return { buffer, vertexCount: floats.length / 5 };
|
||||
}
|
||||
|
||||
function createTextureFromImage(image) {
|
||||
const texture = gl.createTexture();
|
||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
|
||||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
return texture;
|
||||
}
|
||||
|
||||
function drawMesh(mesh, model, texture, color, depthWrite, mode) {
|
||||
gl.depthMask(depthWrite !== false);
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, mesh.buffer);
|
||||
gl.enableVertexAttribArray(attribs.aUV);
|
||||
gl.vertexAttribPointer(attribs.aUV, 2, gl.FLOAT, false, 20, 0);
|
||||
gl.enableVertexAttribArray(attribs.aPos);
|
||||
gl.vertexAttribPointer(attribs.aPos, 3, gl.FLOAT, false, 20, 8);
|
||||
|
||||
gl.uniformMatrix4fv(uniforms.uModel, false, model);
|
||||
gl.uniform4f(uniforms.uColor, color[0], color[1], color[2], color[3]);
|
||||
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_2D, texture || whiteTexture);
|
||||
gl.uniform1i(uniforms.uTexture, 0);
|
||||
|
||||
gl.drawArrays(mode || gl.TRIANGLES, 0, mesh.vertexCount);
|
||||
}
|
||||
|
||||
// Builds a 4-vertex outline of the tile at (x, y, z), lifted slightly
|
||||
// to avoid z-fighting with the terrain surface beneath it.
|
||||
function buildHighlightMesh(x, y, z) {
|
||||
const eps = 0.02;
|
||||
return createMesh(new Float32Array([
|
||||
0, 0, x, y, z + eps,
|
||||
0, 0, x + 1, y, z + eps,
|
||||
0, 0, x + 1, y + 1, z + eps,
|
||||
0, 0, x, y + 1, z + eps,
|
||||
]));
|
||||
}
|
||||
|
||||
// Neighboring chunks are drawn dimmer and semi-transparent, so they
|
||||
// read as context rather than part of the chunk being edited.
|
||||
const NEIGHBOR_ALPHA = 0.35;
|
||||
const NEIGHBOR_DARKEN = 0.5;
|
||||
|
||||
// scene = {
|
||||
// target: [x, y, z], worldH: number,
|
||||
// terrain: { mesh, texture } | null,
|
||||
// gridLines: { mesh } | null,
|
||||
// models: [{ mesh, texture, color: [r,g,b,a in 0..1], offset: [x,y,z] }],
|
||||
// neighbors: [{
|
||||
// offset: [x,y,z],
|
||||
// terrain: { mesh, texture } | null,
|
||||
// models: [{ mesh, texture, color, offset }],
|
||||
// }],
|
||||
// highlight: { x, y, z } | null,
|
||||
// }
|
||||
function render(scene) {
|
||||
const width = canvas.width, height = canvas.height;
|
||||
gl.viewport(0, 0, width, height);
|
||||
gl.clearColor(0.16, 0.18, 0.22, 1);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||
gl.useProgram(program);
|
||||
gl.depthMask(true);
|
||||
|
||||
const { view, fov } = computeCamera(scene.target, scene.worldH);
|
||||
const projection = mat4Perspective(new Float32Array(16), fov, width / height, 0.1, 1000);
|
||||
gl.uniformMatrix4fv(uniforms.uProjection, false, projection);
|
||||
gl.uniformMatrix4fv(uniforms.uView, false, view);
|
||||
|
||||
const identity = mat4Identity(new Float32Array(16));
|
||||
|
||||
if(scene.terrain) {
|
||||
drawMesh(scene.terrain.mesh, identity, scene.terrain.texture, [1, 1, 1, 1], true);
|
||||
}
|
||||
|
||||
if(scene.gridLines) {
|
||||
drawMesh(scene.gridLines.mesh, identity, null, [0, 0, 0, 0.35], false, gl.LINES);
|
||||
}
|
||||
|
||||
for(const model of scene.models) {
|
||||
const modelMatrix = mat4Translation(new Float32Array(16), model.offset);
|
||||
drawMesh(model.mesh, modelMatrix, model.texture, model.color, true);
|
||||
}
|
||||
|
||||
for(const neighbor of scene.neighbors || []) {
|
||||
if(neighbor.terrain) {
|
||||
const modelMatrix = mat4Translation(new Float32Array(16), neighbor.offset);
|
||||
drawMesh(
|
||||
neighbor.terrain.mesh, modelMatrix, neighbor.terrain.texture,
|
||||
[NEIGHBOR_DARKEN, NEIGHBOR_DARKEN, NEIGHBOR_DARKEN, NEIGHBOR_ALPHA], false,
|
||||
);
|
||||
}
|
||||
|
||||
for(const model of neighbor.models) {
|
||||
const worldOffset = [
|
||||
neighbor.offset[0] + model.offset[0],
|
||||
neighbor.offset[1] + model.offset[1],
|
||||
neighbor.offset[2] + model.offset[2],
|
||||
];
|
||||
const modelMatrix = mat4Translation(new Float32Array(16), worldOffset);
|
||||
const color = [
|
||||
model.color[0] * NEIGHBOR_DARKEN,
|
||||
model.color[1] * NEIGHBOR_DARKEN,
|
||||
model.color[2] * NEIGHBOR_DARKEN,
|
||||
model.color[3] * NEIGHBOR_ALPHA,
|
||||
];
|
||||
drawMesh(model.mesh, modelMatrix, model.texture, color, false);
|
||||
}
|
||||
}
|
||||
|
||||
if(scene.highlight) {
|
||||
const { x, y, z } = scene.highlight;
|
||||
const highlightMesh = buildHighlightMesh(x, y, z);
|
||||
drawMesh(highlightMesh, identity, null, [1, 0.92, 0.23, 1], false, gl.LINE_LOOP);
|
||||
}
|
||||
}
|
||||
|
||||
return { gl, createMesh, createTextureFromImage, render };
|
||||
}
|
||||
|
||||
return Object.freeze({ create, computeCamera });
|
||||
})();
|
||||
@@ -1,23 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Dusk Map Editor</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand navbar-dark bg-dark">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="/">Dusk Map Editor</a>
|
||||
<ul class="navbar-nav flex-row">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/map">Map Editor</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
<div id="editor" class="container-fluid py-3"></div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,295 +0,0 @@
|
||||
"""
|
||||
Map Editor HTTP Server
|
||||
|
||||
Serves editor/client/public/ as static files with smart routing:
|
||||
/ -> index.html
|
||||
/page -> page.html or page/index.html
|
||||
/index -> index.html
|
||||
|
||||
API endpoints (all paths relative to project root):
|
||||
GET /api/ls?path=<dir> directory listing
|
||||
GET /api/read?path=<file> file contents
|
||||
GET /api/find?path=<dir>&ext=<.json> recursive file listing by extension
|
||||
POST /api/write?path=<file> write file (JSON body: {"content":"..."})
|
||||
POST /api/mkdir?path=<dir> create directory
|
||||
POST /api/delete?path=<file> delete a file
|
||||
POST /api/compile-chunk?x=&y=&z= recompile a chunk JSON to .dcf
|
||||
"""
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import json
|
||||
import mimetypes
|
||||
import subprocess
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
from urllib.parse import urlparse, parse_qs, unquote
|
||||
from pathlib import Path
|
||||
|
||||
CHUNK_COORD_RE = re.compile(r"^-?\d+$")
|
||||
|
||||
PORT = 3000
|
||||
SCRIPT_DIR = Path(__file__).parent.resolve()
|
||||
PUBLIC_DIR = SCRIPT_DIR.parent / "client" / "public"
|
||||
PROJECT_ROOT = SCRIPT_DIR.parent.parent.resolve()
|
||||
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
parsed = urlparse(self.path)
|
||||
path = unquote(parsed.path)
|
||||
if path.startswith("/api/"):
|
||||
params = parse_qs(parsed.query)
|
||||
if path == "/api/ls":
|
||||
self.api_ls(params)
|
||||
elif path == "/api/read":
|
||||
self.api_read(params)
|
||||
elif path == "/api/find":
|
||||
self.api_find(params)
|
||||
else:
|
||||
self.send_error(404)
|
||||
else:
|
||||
self.serve_static(path)
|
||||
|
||||
def do_POST(self):
|
||||
parsed = urlparse(self.path)
|
||||
params = parse_qs(parsed.query)
|
||||
if parsed.path == "/api/write":
|
||||
self.api_write(params)
|
||||
elif parsed.path == "/api/mkdir":
|
||||
self.api_mkdir(params)
|
||||
elif parsed.path == "/api/delete":
|
||||
self.api_delete(params)
|
||||
elif parsed.path == "/api/compile-chunk":
|
||||
self.api_compile_chunk(params)
|
||||
else:
|
||||
self.send_error(404)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Helpers
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
def resolve_project_path(self, rel):
|
||||
rel = rel.lstrip("/")
|
||||
target = (PROJECT_ROOT / rel).resolve()
|
||||
if not str(target).startswith(str(PROJECT_ROOT)):
|
||||
return None
|
||||
return target
|
||||
|
||||
def send_json(self, data, code=200):
|
||||
body = json.dumps(data, indent=2).encode("utf-8")
|
||||
self.send_response(code)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.send_header("Content-Length", len(body))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
def read_body(self):
|
||||
length = int(self.headers.get("Content-Length", 0))
|
||||
return self.rfile.read(length)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# API handlers
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
def api_ls(self, params):
|
||||
rel = params.get("path", [""])[0]
|
||||
target = self.resolve_project_path(rel)
|
||||
if target is None:
|
||||
self.send_json({"error": "invalid path"}, 400)
|
||||
return
|
||||
if not target.exists():
|
||||
self.send_json({"error": "path not found"}, 404)
|
||||
return
|
||||
if not target.is_dir():
|
||||
self.send_json({"error": "not a directory"}, 400)
|
||||
return
|
||||
|
||||
entries = []
|
||||
for entry in sorted(target.iterdir(), key=lambda e: (e.is_file(), e.name)):
|
||||
entries.append({
|
||||
"name": entry.name,
|
||||
"type": "dir" if entry.is_dir() else "file",
|
||||
"size": entry.stat().st_size if entry.is_file() else None,
|
||||
})
|
||||
self.send_json({
|
||||
"path": str(target.relative_to(PROJECT_ROOT)),
|
||||
"entries": entries,
|
||||
})
|
||||
|
||||
def api_read(self, params):
|
||||
rel = params.get("path", [""])[0]
|
||||
target = self.resolve_project_path(rel)
|
||||
if target is None:
|
||||
self.send_json({"error": "invalid path"}, 400)
|
||||
return
|
||||
if not target.exists():
|
||||
self.send_json({"error": "file not found"}, 404)
|
||||
return
|
||||
if not target.is_file():
|
||||
self.send_json({"error": "not a file"}, 400)
|
||||
return
|
||||
|
||||
try:
|
||||
content = target.read_text(encoding="utf-8")
|
||||
self.send_json({
|
||||
"path": str(target.relative_to(PROJECT_ROOT)),
|
||||
"content": content,
|
||||
})
|
||||
except UnicodeDecodeError:
|
||||
import base64
|
||||
content = base64.b64encode(target.read_bytes()).decode("ascii")
|
||||
self.send_json({
|
||||
"path": str(target.relative_to(PROJECT_ROOT)),
|
||||
"content": content,
|
||||
"encoding": "base64",
|
||||
})
|
||||
|
||||
def api_write(self, params):
|
||||
rel = params.get("path", [""])[0]
|
||||
target = self.resolve_project_path(rel)
|
||||
if target is None:
|
||||
self.send_json({"error": "invalid path"}, 400)
|
||||
return
|
||||
|
||||
body = self.read_body()
|
||||
try:
|
||||
data = json.loads(body)
|
||||
content = data.get("content", "")
|
||||
except (json.JSONDecodeError, UnicodeDecodeError):
|
||||
content = body.decode("utf-8")
|
||||
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_text(content, encoding="utf-8")
|
||||
self.send_json({"ok": True, "path": str(target.relative_to(PROJECT_ROOT))})
|
||||
|
||||
def api_mkdir(self, params):
|
||||
rel = params.get("path", [""])[0]
|
||||
target = self.resolve_project_path(rel)
|
||||
if target is None:
|
||||
self.send_json({"error": "invalid path"}, 400)
|
||||
return
|
||||
target.mkdir(parents=True, exist_ok=True)
|
||||
self.send_json({"ok": True, "path": str(target.relative_to(PROJECT_ROOT))})
|
||||
|
||||
def api_delete(self, params):
|
||||
rel = params.get("path", [""])[0]
|
||||
target = self.resolve_project_path(rel)
|
||||
if target is None:
|
||||
self.send_json({"error": "invalid path"}, 400)
|
||||
return
|
||||
if target.is_file():
|
||||
target.unlink()
|
||||
self.send_json({"ok": True, "path": str(target.relative_to(PROJECT_ROOT))})
|
||||
|
||||
def api_find(self, params):
|
||||
rel = params.get("path", [""])[0]
|
||||
ext = params.get("ext", [""])[0]
|
||||
target = self.resolve_project_path(rel)
|
||||
if target is None:
|
||||
self.send_json({"error": "invalid path"}, 400)
|
||||
return
|
||||
if not target.is_dir():
|
||||
self.send_json({"error": "not a directory"}, 400)
|
||||
return
|
||||
|
||||
pattern = f"*{ext}" if ext else "*"
|
||||
paths = sorted(
|
||||
str(p.relative_to(target)).replace(os.sep, "/")
|
||||
for p in target.rglob(pattern)
|
||||
if p.is_file()
|
||||
)
|
||||
self.send_json({"path": str(target.relative_to(PROJECT_ROOT)), "files": paths})
|
||||
|
||||
def api_compile_chunk(self, params):
|
||||
x = params.get("x", [""])[0]
|
||||
y = params.get("y", [""])[0]
|
||||
z = params.get("z", [""])[0]
|
||||
if not (CHUNK_COORD_RE.match(x) and CHUNK_COORD_RE.match(y) and CHUNK_COORD_RE.match(z)):
|
||||
self.send_json({"error": "invalid chunk coordinates"}, 400)
|
||||
return
|
||||
|
||||
json_path = PROJECT_ROOT / "assetsraw" / "chunks" / f"chunk_{x}_{y}_{z}.json"
|
||||
if not json_path.is_file():
|
||||
self.send_json({"error": "chunk json not found"}, 404)
|
||||
return
|
||||
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-m", "tools.asset.chunk", str(json_path)],
|
||||
cwd=str(PROJECT_ROOT),
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
self.send_json({
|
||||
"ok": result.returncode == 0,
|
||||
"returncode": result.returncode,
|
||||
"stdout": result.stdout,
|
||||
"stderr": result.stderr,
|
||||
})
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Static file serving
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
def serve_static(self, path):
|
||||
clean = path.lstrip("/")
|
||||
candidates = []
|
||||
|
||||
if clean == "" or clean == "index" or clean == "index.html":
|
||||
candidates = ["index.html"]
|
||||
else:
|
||||
candidates.append(clean)
|
||||
if "." not in Path(clean).name:
|
||||
candidates.append(clean + ".html")
|
||||
candidates.append(clean + "/index.html")
|
||||
|
||||
for candidate in candidates:
|
||||
file_path = PUBLIC_DIR / candidate
|
||||
if file_path.is_file():
|
||||
self.serve_file(file_path)
|
||||
return
|
||||
|
||||
self.send_error(404)
|
||||
|
||||
def serve_file(self, file_path):
|
||||
mime, _ = mimetypes.guess_type(str(file_path))
|
||||
mime = mime or "application/octet-stream"
|
||||
|
||||
template = PUBLIC_DIR / "template.html"
|
||||
if (
|
||||
mime == "text/html"
|
||||
and file_path.name != "template.html"
|
||||
and template.is_file()
|
||||
):
|
||||
fragment = file_path.read_text(encoding="utf-8")
|
||||
shell = template.read_text(encoding="utf-8")
|
||||
marker = shell.find('id="editor"')
|
||||
if marker == -1:
|
||||
content = shell.encode("utf-8")
|
||||
else:
|
||||
tag_end = shell.index(">", marker) + 1
|
||||
close_idx = shell.index("</div>", tag_end)
|
||||
content = (shell[:tag_end] + fragment + shell[close_idx:]).encode("utf-8")
|
||||
else:
|
||||
content = file_path.read_bytes()
|
||||
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", mime)
|
||||
self.send_header("Content-Length", len(content))
|
||||
self.end_headers()
|
||||
self.wfile.write(content)
|
||||
|
||||
def log_message(self, fmt, *args):
|
||||
print(f" {self.address_string()} {fmt % args}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Map Editor")
|
||||
print(f" http://localhost:{PORT}")
|
||||
print(f" public : {PUBLIC_DIR}")
|
||||
print(f" project: {PROJECT_ROOT}")
|
||||
server = HTTPServer(("", PORT), Handler)
|
||||
try:
|
||||
server.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
print("\nStopped.")
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
cd "$(dirname "$0")"
|
||||
python3 server/server.py
|
||||
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
docker build -t dusk-dolphin -f docker/dolphin/Dockerfile .
|
||||
docker run --rm -v "$(pwd):/workdir" dusk-dolphin /bin/bash -c "./scripts/build-gamecube.sh"
|
||||
docker run --rm -v "$(pwd):/workdir" dusk-dolphin /bin/bash -c "./scripts/gamecube/build-gamecube.sh"
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
docker build -t dusk-dolphin -f docker/dolphin/Dockerfile .
|
||||
docker run --rm -v "$(pwd):/workdir" dusk-dolphin /bin/bash -c "./scripts/build-gamecube-iso.sh"
|
||||
docker run --rm -v "$(pwd):/workdir" dusk-dolphin /bin/bash -c "./scripts/gamecube/build-gamecube-iso.sh"
|
||||
File renamed without changes.
File renamed without changes.
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
docker build -t dusk-knulli -f docker/knulli/Dockerfile .
|
||||
docker run --rm -v "$(pwd):/workdir" dusk-knulli /bin/bash -c "./scripts/build-knulli.sh"
|
||||
docker run --rm -v "$(pwd):/workdir" dusk-knulli /bin/bash -c "./scripts/knulli/build-knulli.sh"
|
||||
File renamed without changes.
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
docker build -t dusk-linux -f docker/linux/Dockerfile .
|
||||
docker run --rm -v "$(pwd):/workdir" dusk-linux /bin/bash -c "./scripts/build-linux.sh"
|
||||
docker run --rm -v "$(pwd):/workdir" dusk-linux /bin/bash -c "./scripts/linux/build-linux.sh"
|
||||
File renamed without changes.
@@ -4,4 +4,4 @@ docker run \
|
||||
--rm \
|
||||
-v "${GITHUB_WORKSPACE}:/workdir" \
|
||||
dusk-linux \
|
||||
/bin/bash -c "./scripts/test-linux.sh"
|
||||
/bin/bash -c "./scripts/linux/test-linux.sh"
|
||||
File renamed without changes.
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
docker build -t dusk-psp -f docker/psp/Dockerfile .
|
||||
docker run --rm -v "$(pwd):/workdir" dusk-psp /bin/bash -c "./scripts/build-psp.sh"
|
||||
docker run --rm -v "$(pwd):/workdir" dusk-psp /bin/bash -c "./scripts/psp/build-psp.sh"
|
||||
File renamed without changes.
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
docker build -t dusk-vita -f docker/vita/Dockerfile .
|
||||
docker run --rm -v "$(pwd):/workdir" dusk-vita /bin/bash -c "./scripts/build-vita.sh"
|
||||
docker run --rm -v "$(pwd):/workdir" dusk-vita /bin/bash -c "./scripts/vita/build-vita.sh"
|
||||
File renamed without changes.
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
docker build -t dusk-dolphin -f docker/dolphin/Dockerfile .
|
||||
docker run --rm -v "$(pwd):/workdir" dusk-dolphin /bin/bash -c "./scripts/build-wii.sh"
|
||||
docker run --rm -v "$(pwd):/workdir" dusk-dolphin /bin/bash -c "./scripts/wii/build-wii.sh"
|
||||
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
docker build -t dusk-dolphin -f docker/dolphin/Dockerfile .
|
||||
docker run --rm -v "$(pwd):/workdir" dusk-dolphin /bin/bash -c "./scripts/build-wii-iso.sh"
|
||||
docker run --rm -v "$(pwd):/workdir" dusk-dolphin /bin/bash -c "./scripts/wii/build-wii-iso.sh"
|
||||
File renamed without changes.
File renamed without changes.
+7
-2
@@ -13,6 +13,7 @@ if(DUSK_TARGET_SYSTEM STREQUAL "linux" OR DUSK_TARGET_SYSTEM STREQUAL "knulli")
|
||||
add_subdirectory(dusklinux)
|
||||
add_subdirectory(dusksdl2)
|
||||
add_subdirectory(duskgl)
|
||||
add_subdirectory(duskmad)
|
||||
|
||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
|
||||
add_subdirectory(duskpsp)
|
||||
@@ -24,7 +25,11 @@ elseif(DUSK_TARGET_SYSTEM STREQUAL "vita")
|
||||
add_subdirectory(dusksdl2)
|
||||
add_subdirectory(duskgl)
|
||||
|
||||
elseif(DUSK_TARGET_SYSTEM STREQUAL "wii" OR DUSK_TARGET_SYSTEM STREQUAL "gamecube")
|
||||
elseif(
|
||||
DUSK_TARGET_SYSTEM STREQUAL "wii" OR
|
||||
DUSK_TARGET_SYSTEM STREQUAL "gamecube"
|
||||
)
|
||||
add_subdirectory(duskdolphin)
|
||||
|
||||
add_subdirectory(duskmad)
|
||||
|
||||
endif()
|
||||
+21
-4
@@ -14,12 +14,21 @@ if(NOT libzip_FOUND)
|
||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC zip)
|
||||
endif()
|
||||
|
||||
# assetdsk.c calls crc32() directly (to verify dusk.dsk archive checksums).
|
||||
# find_package(libzip) above already resolves ZLIB as a side effect, so
|
||||
# ZLIB_FOUND may already be true without ZLIB::ZLIB having been linked to
|
||||
# our target - link it unconditionally rather than guarding on ZLIB_FOUND.
|
||||
find_package(ZLIB REQUIRED)
|
||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC ZLIB::ZLIB)
|
||||
|
||||
if(NOT stb_image_FOUND)
|
||||
find_package(stb REQUIRED)
|
||||
if(STB_IMAGE_FOUND)
|
||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC stb_image)
|
||||
else()
|
||||
message(FATAL_ERROR "stb_image not found. Please ensure stb is correctly fetched.")
|
||||
message(FATAL_ERROR
|
||||
"stb_image not found. Please ensure stb is correctly fetched."
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -28,7 +37,9 @@ if(NOT yyjson_FOUND)
|
||||
if(yyjson_FOUND)
|
||||
target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC yyjson::yyjson)
|
||||
else()
|
||||
message(FATAL_ERROR "yyjson not found. Please ensure yyjson is correctly fetched.")
|
||||
message(FATAL_ERROR
|
||||
"yyjson not found. Please ensure yyjson is correctly fetched."
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -39,6 +50,12 @@ if(DUSK_BACKTRACE)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(DUSK_TRACK_MEMORY)
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
DUSK_TRACK_MEMORY
|
||||
)
|
||||
endif()
|
||||
|
||||
# Includes
|
||||
target_include_directories(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
@@ -55,6 +72,7 @@ target_sources(${DUSK_BINARY_TARGET_NAME}
|
||||
add_subdirectory(animation)
|
||||
add_subdirectory(assert)
|
||||
add_subdirectory(asset)
|
||||
add_subdirectory(audio)
|
||||
add_subdirectory(console)
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(log)
|
||||
@@ -62,11 +80,10 @@ add_subdirectory(engine)
|
||||
add_subdirectory(error)
|
||||
add_subdirectory(input)
|
||||
add_subdirectory(locale)
|
||||
add_subdirectory(rpg)
|
||||
add_subdirectory(perf)
|
||||
add_subdirectory(scene)
|
||||
add_subdirectory(system)
|
||||
add_subdirectory(time)
|
||||
add_subdirectory(ui)
|
||||
add_subdirectory(save)
|
||||
add_subdirectory(util)
|
||||
add_subdirectory(thread)
|
||||
@@ -6,6 +6,4 @@
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
easing.c
|
||||
animation.c
|
||||
keyframe.c
|
||||
)
|
||||
@@ -1,132 +0,0 @@
|
||||
// Copyright (c) 2026 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "animation.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/math.h"
|
||||
|
||||
void animationInit(
|
||||
animation_t *anim,
|
||||
keyframe_t *keyframes,
|
||||
uint16_t *keyframeCounts,
|
||||
const uint16_t layerCount
|
||||
) {
|
||||
assertNotNull(anim, "Animation pointer cannot be null.");
|
||||
assertNotNull(keyframes, "Keyframes pointer cannot be null.");
|
||||
assertNotNull(keyframeCounts, "Keyframe counts pointer cannot be null.");
|
||||
assertTrue(layerCount > 0, "Layer count must be greater than zero.");
|
||||
|
||||
memoryZero(anim, sizeof(animation_t));
|
||||
anim->keyframes = keyframes;
|
||||
anim->keyframeCounts = keyframeCounts;
|
||||
anim->layerCount = layerCount;
|
||||
|
||||
// Determine duration
|
||||
float_t duration = 0.0f;
|
||||
for(uint16_t layer = 0; layer < layerCount; layer++) {
|
||||
uint16_t keyframeCount = keyframeCounts[layer];
|
||||
assertTrue(keyframeCount > 0, "Keyframe count invalid.");
|
||||
keyframe_t *layerKeyframes = keyframes + layer * keyframeCount;
|
||||
|
||||
#ifdef DUSK_ASSERTIONS
|
||||
// Check that the keyframes are sorted by time.
|
||||
for(uint16_t i = 1; i < keyframeCount; i++) {
|
||||
assertTrue(
|
||||
layerKeyframes[i].time >= layerKeyframes[i - 1].time,
|
||||
"Keyframes must be sorted by time."
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
keyframe_t *lastKeyframe = layerKeyframes + keyframeCount - 1;
|
||||
duration = mathMax(duration, lastKeyframe->time);
|
||||
}
|
||||
assertTrue(duration > 0, "Animation duration must be greater than 0.");
|
||||
anim->duration = duration;
|
||||
}
|
||||
|
||||
float_t animationGetLayerValue(const animation_t *anim, const uint16_t layer) {
|
||||
assertNotNull(anim, "Animation pointer cannot be null.");
|
||||
assertTrue(layer < anim->layerCount, "Layer index out of bounds.");
|
||||
|
||||
uint16_t keyframeCount = anim->keyframeCounts[layer];
|
||||
keyframe_t *layerKeyframes = anim->keyframes + layer * keyframeCount;
|
||||
return keyframeGetValue(layerKeyframes, keyframeCount, anim->time);
|
||||
}
|
||||
|
||||
void animationUpdate(
|
||||
animation_t *anim,
|
||||
const float_t deltaTime
|
||||
) {
|
||||
assertNotNull(anim, "Animation pointer cannot be null.");
|
||||
assertTrue(deltaTime >= 0, "Delta time must be non-negative.");
|
||||
|
||||
bool_t justCompleted = false;
|
||||
|
||||
if(!(anim->flags & ANIMATION_FLAG_INTERNAL_COMPLETED)) {
|
||||
bool_t loop = (anim->flags & ANIMATION_FLAG_LOOP) != 0;
|
||||
bool_t pingpong = (anim->flags & ANIMATION_FLAG_PINGPONG) != 0;
|
||||
assertFalse(
|
||||
loop && pingpong,
|
||||
"Cannot set both ANIMATION_FLAG_LOOP and ANIMATION_FLAG_PINGPONG."
|
||||
);
|
||||
|
||||
bool_t backward;
|
||||
if(pingpong) {
|
||||
backward = (anim->flags & ANIMATION_FLAG_INTERNAL_PINGPONG_BACKWARD) != 0;
|
||||
} else {
|
||||
backward = (anim->flags & ANIMATION_FLAG_REVERSE) != 0;
|
||||
}
|
||||
|
||||
// Resolve boundary crossings one at a time, so a single large deltaTime
|
||||
// can correctly loop/pingpong across multiple boundaries in one call.
|
||||
float_t remaining = deltaTime;
|
||||
while(remaining > 0.0f) {
|
||||
float_t toBoundary = (
|
||||
backward ? anim->time : (anim->duration - anim->time)
|
||||
);
|
||||
if(remaining < toBoundary) {
|
||||
anim->time += backward ? -remaining : remaining;
|
||||
break;
|
||||
}
|
||||
|
||||
remaining -= toBoundary;
|
||||
anim->time = backward ? 0.0f : anim->duration;
|
||||
|
||||
bool_t stopHere;
|
||||
if(backward) {
|
||||
stopHere = (anim->flags & ANIMATION_FLAG_STOP_BEGINNING) != 0;
|
||||
} else {
|
||||
stopHere = (anim->flags & ANIMATION_FLAG_STOP_END) != 0;
|
||||
}
|
||||
|
||||
if(stopHere) {
|
||||
justCompleted = true;
|
||||
break;
|
||||
} else if(pingpong) {
|
||||
backward = !backward;
|
||||
if(backward) anim->flags |= ANIMATION_FLAG_INTERNAL_PINGPONG_BACKWARD;
|
||||
else anim->flags &= ~ANIMATION_FLAG_INTERNAL_PINGPONG_BACKWARD;
|
||||
} else if(loop) {
|
||||
anim->time = backward ? anim->duration : 0.0f;
|
||||
if(anim->onLoop) anim->onLoop(anim->user);
|
||||
} else {
|
||||
justCompleted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(justCompleted) anim->flags |= ANIMATION_FLAG_INTERNAL_COMPLETED;
|
||||
}
|
||||
|
||||
// Call onUpdate for each layer.
|
||||
for(uint16_t layer = 0; layer < anim->layerCount; layer++) {
|
||||
float_t value = animationGetLayerValue(anim, layer);
|
||||
if(anim->onUpdate) anim->onUpdate(layer, value, anim->user);
|
||||
}
|
||||
|
||||
if(justCompleted && anim->onComplete) anim->onComplete(anim->user);
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
// Copyright (c) 2026 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "keyframe.h"
|
||||
|
||||
#define ANIMATION_FLAG_LOOP (1 << 0)
|
||||
#define ANIMATION_FLAG_REVERSE (1 << 1)
|
||||
#define ANIMATION_FLAG_PINGPONG (1 << 2)
|
||||
#define ANIMATION_FLAG_STOP_BEGINNING (1 << 3)
|
||||
#define ANIMATION_FLAG_STOP_END (1 << 4)
|
||||
|
||||
// Internal - tracks which direction a pingponging animation is currently
|
||||
// travelling. Do not set this manually, it is managed by animationUpdate().
|
||||
#define ANIMATION_FLAG_INTERNAL_PINGPONG_BACKWARD (1 << 7)
|
||||
|
||||
// Internal - set once the animation has stopped advancing (see
|
||||
// animationUpdate()). Do not set this manually. There is currently no way to
|
||||
// restart a completed animation short of clearing this bit and resetting
|
||||
// anim->time by hand.
|
||||
#define ANIMATION_FLAG_INTERNAL_COMPLETED (1 << 6)
|
||||
|
||||
typedef struct {
|
||||
keyframe_t *keyframes;
|
||||
uint16_t *keyframeCounts;
|
||||
uint16_t layerCount;
|
||||
float_t time;
|
||||
float_t duration;
|
||||
uint8_t flags;
|
||||
|
||||
void *user;
|
||||
void (*onUpdate)(const uint16_t layer, const float_t value, void *user);
|
||||
void (*onComplete)(void *user);
|
||||
void (*onLoop)(void *user);
|
||||
} animation_t;
|
||||
|
||||
/**
|
||||
* Initializes an animation with the given keyframes and layer count.
|
||||
*
|
||||
* @param anim Pointer to the animation to initialize.
|
||||
* @param keyframes Pointer to the array of keyframes for each layer.
|
||||
* @param keyframeCount Number of keyframes in each layer.
|
||||
* @param layerCount Number of layers in the animation.
|
||||
*/
|
||||
void animationInit(
|
||||
animation_t *anim,
|
||||
keyframe_t *keyframes,
|
||||
uint16_t *keyframeCounts,
|
||||
const uint16_t layerCount
|
||||
);
|
||||
|
||||
/**
|
||||
* Sets the current time of the animation, clamping it to the valid range.
|
||||
* This will call the onUpdate callback but none of the other callbacks.
|
||||
*
|
||||
* @param anim Pointer to the animation to set the time for.
|
||||
* @param time The new time to set for the animation.
|
||||
*/
|
||||
void animationSetTime(animation_t *anim, const float_t time);
|
||||
|
||||
/**
|
||||
* Gets the current value of a specific layer in the animation based on the
|
||||
* current animation time.
|
||||
*/
|
||||
float_t animationGetLayerValue(const animation_t *anim, const uint16_t layer);
|
||||
|
||||
/**
|
||||
* Updates the animation state based on the elapsed time. Advances anim->time
|
||||
* by deltaTime (or against it, if ANIMATION_FLAG_REVERSE is set), then
|
||||
* resolves whatever happens when it reaches the 0 or duration boundary:
|
||||
*
|
||||
* - ANIMATION_FLAG_PINGPONG: reflects off the boundary and continues playing
|
||||
* in the opposite direction, forever, unless stopped (see below).
|
||||
* - ANIMATION_FLAG_LOOP: wraps back around to the other boundary and keeps
|
||||
* playing in the same direction, forever, unless stopped (see below).
|
||||
* - ANIMATION_FLAG_STOP_BEGINNING / ANIMATION_FLAG_STOP_END: when the
|
||||
* animation reaches that specific boundary, it clamps there and stops
|
||||
* (firing onComplete) instead of looping/pingponging past it.
|
||||
* - If none of the above apply at a boundary, the animation clamps there and
|
||||
* stops, firing onComplete.
|
||||
*
|
||||
* onUpdate is called for every layer on every call. onLoop is called each
|
||||
* time a loop wraps around. onComplete is called at most once, the moment
|
||||
* the animation stops advancing.
|
||||
*
|
||||
* @param anim Pointer to the animation to update.
|
||||
* @param deltaTime Time elapsed since the last update (in seconds).
|
||||
*/
|
||||
void animationUpdate(
|
||||
animation_t *anim,
|
||||
const float_t deltaTime
|
||||
);
|
||||
@@ -1,45 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "keyframe.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/math.h"
|
||||
|
||||
float_t keyframeGetValue(
|
||||
const keyframe_t *keyframes,
|
||||
const uint32_t keyframeCount,
|
||||
const float_t time
|
||||
) {
|
||||
assertNotNull(keyframes, "Keyframes pointer cannot be null.");
|
||||
assertTrue(keyframeCount > 0, "Keyframe count must be more than 0.");
|
||||
assertTrue(time >= 0, "Time must be non-negative.");
|
||||
#ifdef DUSK_ASSERTIONS
|
||||
// Checks that the keyframes are sorted by time.
|
||||
for(uint32_t i = 1; i < keyframeCount; i++) {
|
||||
assertTrue(
|
||||
keyframes[i].time >= keyframes[i - 1].time,
|
||||
"Keyframes must be sorted by time."
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
keyframe_t *last = (keyframe_t *)(keyframes + keyframeCount - 1);
|
||||
if(time >= last->time) return last->value;
|
||||
|
||||
// Since time < last->time (checked above), current is guaranteed to stop
|
||||
// at or before reaching last, so no separate end-of-array check is needed.
|
||||
keyframe_t *current = (keyframe_t *)keyframes;
|
||||
keyframe_t *start = current;
|
||||
while(current->time <= time) {
|
||||
start = current;
|
||||
current++;
|
||||
}
|
||||
keyframe_t *end = current;
|
||||
|
||||
float_t t = (time - start->time) / (end->time - start->time);
|
||||
return mathLerp(start->value, end->value, easingApply(start->easing, t));
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
// Copyright (c) 2026 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "easing.h"
|
||||
|
||||
typedef struct {
|
||||
float_t time;
|
||||
float_t value;
|
||||
easingtype_t easing;
|
||||
} keyframe_t;
|
||||
|
||||
/**
|
||||
* Gets the value of a keyframe at a given time.
|
||||
*
|
||||
* @param keyframes The keyframes to get the value from.
|
||||
* @param keyframeCount The number of keyframes in the array.
|
||||
* @param time The time at which to get the value, in seconds.
|
||||
* @return The value of the keyframe at the given time.
|
||||
*/
|
||||
float_t keyframeGetValue(
|
||||
const keyframe_t *keyframes,
|
||||
const uint32_t keyframeCount,
|
||||
const float_t time
|
||||
);
|
||||
@@ -7,6 +7,7 @@
|
||||
target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
asset.c
|
||||
assetdsk.c
|
||||
assetfile.c
|
||||
)
|
||||
|
||||
|
||||
+19
-4
@@ -19,6 +19,8 @@ asset_t ASSET;
|
||||
errorret_t assetInit(void) {
|
||||
memoryZero(&ASSET, sizeof(asset_t));
|
||||
|
||||
threadMutexInit(&ASSET.zipLock);
|
||||
|
||||
for(size_t i = 0; i < ASSET_LOADING_COUNT_MAX; i++) {
|
||||
threadMutexInit(&ASSET.loading[i].mutex);
|
||||
}
|
||||
@@ -35,9 +37,10 @@ errorret_t assetInit(void) {
|
||||
bool_t assetFileExists(const char_t *filename) {
|
||||
assertStrLenMax(filename, ASSET_FILE_NAME_MAX, "Filename too long.");
|
||||
|
||||
zip_int64_t idx = zip_name_locate(ASSET.zip, filename, 0);
|
||||
if(idx < 0) return false;
|
||||
return true;
|
||||
threadMutexLock(&ASSET.zipLock);
|
||||
bool_t found = zip_name_locate(ASSET.zip, filename, 0) >= 0;
|
||||
threadMutexUnlock(&ASSET.zipLock);
|
||||
return found;
|
||||
}
|
||||
|
||||
assetentry_t * assetGetEntry(
|
||||
@@ -117,6 +120,15 @@ errorret_t assetRequireLoaded(assetentry_t *entry) {
|
||||
assetEntryLock(entry);
|
||||
|
||||
while(entry->state != ASSET_ENTRY_STATE_LOADED) {
|
||||
// A failed load transitions to ERROR, not LOADED - without this check
|
||||
// this loop spins forever on any load failure (assetUpdate() itself
|
||||
// still returns OK, since a single asset failing isn't meant to halt
|
||||
// the whole update loop - see its ASSET_ENTRY_STATE_ERROR handling).
|
||||
if(entry->state == ASSET_ENTRY_STATE_ERROR) {
|
||||
assetEntryUnlock(entry);
|
||||
errorThrow("Failed to load asset: %s", entry->name);
|
||||
}
|
||||
|
||||
usleep(1000);
|
||||
errorret_t ret = assetUpdate();
|
||||
if(errorIsNotOk(ret)) {
|
||||
@@ -348,7 +360,9 @@ errorret_t assetUpdate(void) {
|
||||
assetentry_t *errEntry = loading->entry;
|
||||
loading->entry = NULL;
|
||||
threadMutexUnlock(&loading->mutex);
|
||||
if(errEntry->onError) errEntry->onError(errEntry, errEntry->onErrorUser);
|
||||
if(errEntry->onError) {
|
||||
errEntry->onError(errEntry, errEntry->onErrorUser);
|
||||
}
|
||||
loading++;
|
||||
break;
|
||||
}
|
||||
@@ -436,5 +450,6 @@ errorret_t assetDispose(void) {
|
||||
}
|
||||
|
||||
errorChain(assetDisposePlatform());
|
||||
threadMutexDispose(&ASSET.zipLock);
|
||||
errorOk();
|
||||
}
|
||||
@@ -26,10 +26,40 @@
|
||||
#define ASSET_LOADING_COUNT_MAX 10
|
||||
#define ASSET_ENTRY_COUNT_MAX 64
|
||||
|
||||
#define ASSET_BASE_DIRECTORY_MAX 256
|
||||
|
||||
typedef struct asset_s {
|
||||
// The dusk.dsk archive - a single uncompressed (ZIP_STORED) zip, so
|
||||
// every entry gets the reliable repeated seeking/re-opening that
|
||||
// libzip only supports reliably for uncompressed entries (locale
|
||||
// strings, MP3 loop restarts, etc.).
|
||||
zip_t *zip;
|
||||
|
||||
// Directory dusk.dsk was actually found/opened in (on PSP, the directory
|
||||
// EBOOT.PBP lives in, since dusk.dsk is embedded inside it rather than a
|
||||
// loose file) - populated by each platform's own assetInitXxx() once it
|
||||
// locates the file. Save devices that persist to a real filesystem path
|
||||
// (Linux, PSP, Wii SD) use this as their base directory instead of a
|
||||
// separate hardcoded location, so saves live next to wherever the game
|
||||
// itself was actually launched from rather than some unrelated fixed
|
||||
// path. Not meaningful for devices with no filesystem-path concept at
|
||||
// all (GameCube/Wii memory card, Wii NAND's ISFS namespace).
|
||||
char_t baseDirectory[ASSET_BASE_DIRECTORY_MAX];
|
||||
|
||||
assetplatform_t platform;
|
||||
|
||||
// Guards every libzip call against ASSET.zip (zip_fopen,
|
||||
// zip_fread, zip_fclose, zip_fseek, zip_stat, zip_name_locate - see
|
||||
// assetfile.c/assetFileExists). libzip is documented as not thread-safe,
|
||||
// and this asset system genuinely calls it from multiple real threads at
|
||||
// once (main thread, the background load thread below, and - on
|
||||
// platforms that stream PCM from an asset on their own thread, like PSP
|
||||
// - an audio feeder thread too). Confirmed necessary on real PSP
|
||||
// hardware: without this lock, concurrent zip_fopen/zip_fread calls from
|
||||
// different threads corrupted reads (EINVAL, then zlib data errors) once
|
||||
// dusk.dsk stopped being read entirely into memory up front.
|
||||
threadmutex_t zipLock;
|
||||
|
||||
// Background loading thread.
|
||||
thread_t loadThread;
|
||||
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assetdsk.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/endian.h"
|
||||
#include "assert/assert.h"
|
||||
#include <zlib.h>
|
||||
|
||||
errorret_t assetDskParseHeader(
|
||||
const uint8_t *bytes,
|
||||
const size_t bytesSize,
|
||||
assetdskheader_t *outHeader
|
||||
) {
|
||||
assertNotNull(bytes, "Bytes cannot be NULL.");
|
||||
assertNotNull(outHeader, "Out header cannot be NULL.");
|
||||
|
||||
if(bytesSize < ASSET_DSK_HEADER_SIZE) {
|
||||
errorThrow("dusk.dsk header is truncated.");
|
||||
}
|
||||
|
||||
if(memoryCompare(bytes, ASSET_DSK_MAGIC, ASSET_DSK_MAGIC_SIZE) != 0) {
|
||||
errorThrow("dusk.dsk has an invalid magic header.");
|
||||
}
|
||||
|
||||
// Every field is a little-endian uint32_t regardless of host - convert
|
||||
// to host order (a no-op on little-endian hosts, a real byteswap on
|
||||
// Dolphin's big-endian PowerPC).
|
||||
uint32_t fields[3];
|
||||
memoryCopy(fields, bytes + ASSET_DSK_MAGIC_SIZE, sizeof(fields));
|
||||
for(uint8_t i = 0; i < 3; i++) {
|
||||
fields[i] = endianLittleToHost32(fields[i]);
|
||||
}
|
||||
|
||||
const uint32_t version = fields[0];
|
||||
if(version != ASSET_DSK_VERSION) {
|
||||
errorThrow("dusk.dsk has an unsupported version: %u", version);
|
||||
}
|
||||
|
||||
outHeader->size = fields[1];
|
||||
outHeader->checksum = fields[2];
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t assetDskOpenFromPath(
|
||||
const char_t *path,
|
||||
zip_t **outZip
|
||||
) {
|
||||
errorChain(assetDskOpenFromPathRange(path, 0, SIZE_MAX, outZip));
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t assetDskOpenFromPathRange(
|
||||
const char_t *path,
|
||||
const size_t baseOffset,
|
||||
const size_t baseSize,
|
||||
zip_t **outZip
|
||||
) {
|
||||
assertNotNull(path, "Path cannot be NULL.");
|
||||
assertNotNull(outZip, "Out zip cannot be NULL.");
|
||||
|
||||
*outZip = NULL;
|
||||
|
||||
FILE *headerFile = fopen(path, "rb");
|
||||
if(headerFile == NULL) {
|
||||
errorThrow("Failed to open dusk.dsk: %s", path);
|
||||
}
|
||||
|
||||
if(fseek(headerFile, (long) baseOffset, SEEK_SET) != 0) {
|
||||
fclose(headerFile);
|
||||
errorThrow("Failed to seek to dusk.dsk range in file: %s", path);
|
||||
}
|
||||
|
||||
uint8_t headerBytes[ASSET_DSK_HEADER_SIZE];
|
||||
size_t headerRead = fread(headerBytes, 1, sizeof(headerBytes), headerFile);
|
||||
fclose(headerFile);
|
||||
if(headerRead != sizeof(headerBytes)) {
|
||||
errorThrow("Failed to read dusk.dsk header: %s", path);
|
||||
}
|
||||
|
||||
assetdskheader_t header;
|
||||
errorChain(assetDskParseHeader(headerBytes, sizeof(headerBytes), &header));
|
||||
|
||||
if((size_t) ASSET_DSK_HEADER_SIZE + header.size > baseSize) {
|
||||
errorThrow("dusk.dsk header describes a range beyond its containing file.");
|
||||
}
|
||||
|
||||
zip_error_t zipError;
|
||||
zip_error_init(&zipError);
|
||||
|
||||
zip_source_t *source = zip_source_file_create(
|
||||
path,
|
||||
(zip_uint64_t) (baseOffset + ASSET_DSK_HEADER_SIZE),
|
||||
(zip_int64_t) header.size,
|
||||
&zipError
|
||||
);
|
||||
if(source == NULL) {
|
||||
errorThrow(
|
||||
"Failed to create dusk.dsk source: %s", zip_error_strerror(&zipError)
|
||||
);
|
||||
}
|
||||
|
||||
*outZip = zip_open_from_source(source, ZIP_RDONLY, &zipError);
|
||||
if(*outZip == NULL) {
|
||||
zip_source_free(source);
|
||||
errorThrow(
|
||||
"Failed to open dusk.dsk archive: %s", zip_error_strerror(&zipError)
|
||||
);
|
||||
}
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t assetDskOpenFromBuffer(
|
||||
uint8_t *buffer,
|
||||
const size_t bufferSize,
|
||||
zip_t **outZip
|
||||
) {
|
||||
assertNotNull(buffer, "Buffer cannot be NULL.");
|
||||
assertNotNull(outZip, "Out zip cannot be NULL.");
|
||||
|
||||
*outZip = NULL;
|
||||
|
||||
assetdskheader_t header;
|
||||
errorChain(assetDskParseHeader(buffer, bufferSize, &header));
|
||||
|
||||
if((size_t) ASSET_DSK_HEADER_SIZE + header.size > bufferSize) {
|
||||
errorThrow("dusk.dsk header describes a range beyond the buffer.");
|
||||
}
|
||||
|
||||
uint8_t *data = buffer + ASSET_DSK_HEADER_SIZE;
|
||||
uint32_t checksum = (uint32_t) crc32(0L, data, (uInt) header.size);
|
||||
if(checksum != header.checksum) {
|
||||
errorThrow("dusk.dsk archive failed checksum verification.");
|
||||
}
|
||||
|
||||
zip_error_t zipError;
|
||||
zip_error_init(&zipError);
|
||||
|
||||
// freep=0 - this is a non-owning window into the same caller-owned
|
||||
// buffer, not an independent allocation libzip should free.
|
||||
zip_source_t *source = zip_source_buffer_create(
|
||||
data, header.size, 0, &zipError
|
||||
);
|
||||
if(source == NULL) {
|
||||
errorThrow(
|
||||
"Failed to create dusk.dsk source: %s", zip_error_strerror(&zipError)
|
||||
);
|
||||
}
|
||||
|
||||
*outZip = zip_open_from_source(source, ZIP_RDONLY, &zipError);
|
||||
if(*outZip == NULL) {
|
||||
zip_source_free(source);
|
||||
errorThrow(
|
||||
"Failed to open dusk.dsk archive: %s", zip_error_strerror(&zipError)
|
||||
);
|
||||
}
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include <zip.h>
|
||||
|
||||
// "DSK2" - distinct from a plain zip's "PK\x03\x04" so a stray plain zip
|
||||
// never gets misread as a valid dusk.dsk.
|
||||
#define ASSET_DSK_MAGIC_SIZE 4
|
||||
#define ASSET_DSK_MAGIC "DSK"
|
||||
#define ASSET_DSK_VERSION 2
|
||||
|
||||
// Magic + version + size + checksum
|
||||
#define ASSET_DSK_HEADER_SIZE ( \
|
||||
ASSET_DSK_MAGIC_SIZE + \
|
||||
sizeof(uint32_t) + \
|
||||
sizeof(uint32_t) + \
|
||||
sizeof(uint32_t) \
|
||||
)
|
||||
|
||||
/**
|
||||
* Parsed dusk.dsk (DSK2 format) header. dusk.dsk is a single uncompressed
|
||||
* (ZIP_STORED) zip archive (see tools/asset/pack) rather than DEFLATEd -
|
||||
* the bulk of what's packed (audio, images) is already compressed at the
|
||||
* file level, so DEFLATE-ing the whole archive on top buys negligible
|
||||
* space for real CPU cost, and every entry gets the reliable repeated
|
||||
* seeking/re-opening that libzip only supports for uncompressed entries
|
||||
* (locale line-by-line reads, MP3 loop restarts, etc.) instead of just a
|
||||
* hand-picked subset of files.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t size;
|
||||
uint32_t checksum;
|
||||
} assetdskheader_t;
|
||||
|
||||
/**
|
||||
* Parses a DSK2 header from a raw byte buffer (at least
|
||||
* ASSET_DSK_HEADER_SIZE bytes), validating the magic/version and
|
||||
* byte-swapping the little-endian fields to host order.
|
||||
*
|
||||
* @param bytes Buffer containing the header (and beyond).
|
||||
* @param bytesSize Number of bytes available at `bytes`.
|
||||
* @param outHeader Filled with the parsed header on success.
|
||||
* @return OK on success, error if too short, bad magic, or unsupported version.
|
||||
*/
|
||||
errorret_t assetDskParseHeader(
|
||||
const uint8_t *bytes,
|
||||
const size_t bytesSize,
|
||||
assetdskheader_t *outHeader
|
||||
);
|
||||
|
||||
/**
|
||||
* Opens the dusk.dsk archive given a filesystem path, using a lazy/
|
||||
* windowed file-backed zip source - no more memory used than the
|
||||
* existing per-platform small read buffers, matching the memory
|
||||
* characteristics of a plain zip_open() on the whole file. The checksum
|
||||
* is intentionally not verified here since doing so would require
|
||||
* reading the whole (potentially large) archive just to compute it.
|
||||
*
|
||||
* See assetDskOpenFromPathRange() for the case where the DSK2 blob isn't
|
||||
* the whole file (e.g. embedded inside another container).
|
||||
*
|
||||
* @param path Filesystem path to the dusk.dsk file.
|
||||
* @param outZip Set to the opened archive on success.
|
||||
* @return OK on success, error if the file is missing, too short, has a
|
||||
* bad header, or the archive fails to open.
|
||||
*/
|
||||
errorret_t assetDskOpenFromPath(
|
||||
const char_t *path,
|
||||
zip_t **outZip
|
||||
);
|
||||
|
||||
/**
|
||||
* Same as assetDskOpenFromPath(), but the DSK2 blob doesn't start at the
|
||||
* beginning of `path` - it's a byte range embedded inside a larger
|
||||
* container file (e.g. the PSAR region of an EBOOT.PBP). Every offset the
|
||||
* header describes is relative to `baseOffset`; `baseSize` bounds them
|
||||
* (the size of the embedded blob, not the whole container file) - pass
|
||||
* SIZE_MAX to skip that check when the caller doesn't know/care.
|
||||
*
|
||||
* @param path Filesystem path to the container file.
|
||||
* @param baseOffset Byte offset within `path` where the DSK2 blob starts.
|
||||
* @param baseSize Number of bytes available at `baseOffset`.
|
||||
* @param outZip Set to the opened archive on success.
|
||||
* @return OK on success, error if the file is missing, too short, has a
|
||||
* bad header, or the archive fails to open.
|
||||
*/
|
||||
errorret_t assetDskOpenFromPathRange(
|
||||
const char_t *path,
|
||||
const size_t baseOffset,
|
||||
const size_t baseSize,
|
||||
zip_t **outZip
|
||||
);
|
||||
|
||||
/**
|
||||
* Opens the dusk.dsk archive already fully resident in memory (e.g. a
|
||||
* PSAR embedded in an EBOOT.PBP, or an ISO-embedded file already read via
|
||||
* DVD_ReadAbs - platforms that already buffer the whole file for reasons
|
||||
* unrelated to this format). The returned archive doesn't take ownership
|
||||
* of `buffer` (it's opened as a non-owning sub-range of it) - the caller
|
||||
* remains responsible for freeing it, and must keep it alive for as long
|
||||
* as the archive stays open. Verifies the checksum, since the bytes are
|
||||
* already resident.
|
||||
*
|
||||
* @param buffer The whole dusk.dsk file's bytes.
|
||||
* @param bufferSize Number of bytes at `buffer`.
|
||||
* @param outZip Set to the opened archive on success.
|
||||
* @return OK on success, error if too short, has a bad header/checksum, or
|
||||
* the archive fails to open.
|
||||
*/
|
||||
errorret_t assetDskOpenFromBuffer(
|
||||
uint8_t *buffer,
|
||||
const size_t bufferSize,
|
||||
zip_t **outZip
|
||||
);
|
||||
@@ -24,9 +24,11 @@ errorret_t assetFileInit(
|
||||
file->params = params;
|
||||
file->output = output;
|
||||
|
||||
// Stat the file
|
||||
zip_stat_init(&file->stat);
|
||||
if(!zip_stat(ASSET.zip, filename, 0, &file->stat) == 0) {
|
||||
threadMutexLock(&ASSET.zipLock);
|
||||
int statResult = zip_stat(ASSET.zip, filename, 0, &file->stat);
|
||||
threadMutexUnlock(&ASSET.zipLock);
|
||||
if(statResult != 0) {
|
||||
errorThrow("Failed to stat asset file: %s", filename);
|
||||
}
|
||||
|
||||
@@ -47,6 +49,25 @@ errorret_t assetFileRewind(assetfile_t *file) {
|
||||
errorOk();
|
||||
}
|
||||
|
||||
// Prefer seeking within the still-open handle over closing and
|
||||
// re-opening it. Repeatedly closing/re-opening the same compressed zip
|
||||
// entry (once per rewind - e.g. once per locale string lookup) was
|
||||
// confirmed unreliable on at least one platform's zip backend, silently
|
||||
// skipping ranges of the decompressed content on some re-opens after
|
||||
// the first. A real seek avoids that failure mode entirely, with no
|
||||
// extra memory cost over the close+reopen fallback.
|
||||
threadMutexLock(&ASSET.zipLock);
|
||||
bool_t seekable = zip_file_is_seekable(file->zipFile);
|
||||
int seekResult = seekable ? zip_fseek(file->zipFile, 0, SEEK_SET) : -1;
|
||||
threadMutexUnlock(&ASSET.zipLock);
|
||||
if(seekable) {
|
||||
if(seekResult != 0) {
|
||||
errorThrow("Failed to seek asset file: %s", file->filename);
|
||||
}
|
||||
file->position = 0;
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorChain(assetFileClose(file));
|
||||
errorChain(assetFileOpen(file));
|
||||
errorOk();
|
||||
@@ -55,10 +76,11 @@ errorret_t assetFileRewind(assetfile_t *file) {
|
||||
errorret_t assetFileOpen(assetfile_t *file) {
|
||||
assertNotNull(file, "Asset file cannot be NULL.");
|
||||
assertNotNull(file->filename, "Asset file filename cannot be NULL.");
|
||||
assertNotNull(ASSET.zip, "Asset zip cannot be NULL.");
|
||||
assertNull(file->zipFile, "Asset file already open.");
|
||||
|
||||
threadMutexLock(&ASSET.zipLock);
|
||||
file->zipFile = zip_fopen(ASSET.zip, file->filename, 0);
|
||||
threadMutexUnlock(&ASSET.zipLock);
|
||||
if(file->zipFile == NULL) {
|
||||
errorThrow("Failed to open asset file: %s", file->filename);
|
||||
}
|
||||
@@ -79,8 +101,10 @@ errorret_t assetFileRead(
|
||||
uint8_t tempBuffer[256];
|
||||
while(bytesRemaining > 0) {
|
||||
size_t chunkSize = mathMin(bytesRemaining, sizeof(tempBuffer));
|
||||
// The recursive call below already advances file->position by
|
||||
// chunkSize (the non-NULL branch does this itself) - do not also
|
||||
// advance it here, or every skip ends up double-counted.
|
||||
errorChain(assetFileRead(file, tempBuffer, chunkSize));
|
||||
file->position += chunkSize;
|
||||
bytesRemaining -= chunkSize;
|
||||
}
|
||||
file->lastRead = bufferSize;
|
||||
@@ -97,15 +121,27 @@ errorret_t assetFileRead(
|
||||
size_t chunkSize = mathMin(
|
||||
bufferSize - totalRead, ASSET_FILE_READ_CHUNK_MAX
|
||||
);
|
||||
threadMutexLock(&ASSET.zipLock);
|
||||
zip_int64_t bytesRead = zip_fread(
|
||||
file->zipFile, dest + totalRead, chunkSize
|
||||
);
|
||||
errorret_t readError = errorOkImpl();
|
||||
if(bytesRead < 0) {
|
||||
errorThrow(
|
||||
// Built (not thrown) while still holding the lock, so
|
||||
// zip_file_strerror() reads the just-failed zipFile's error state
|
||||
// before another thread can touch it - errorThrow() itself isn't
|
||||
// used here since it returns immediately, which would leave
|
||||
// ASSET.zipLock held forever.
|
||||
readError = errorThrowImpl(
|
||||
&ERROR_STATE, ERROR_NOT_OK, __FILE__, __func__, __LINE__,
|
||||
"Failed to read from asset file: %s (%s)",
|
||||
file->filename, zip_file_strerror(file->zipFile)
|
||||
);
|
||||
}
|
||||
threadMutexUnlock(&ASSET.zipLock);
|
||||
if(errorIsNotOk(readError)) {
|
||||
errorChain(readError);
|
||||
}
|
||||
if(bytesRead == 0) break;
|
||||
totalRead += (size_t)bytesRead;
|
||||
}
|
||||
@@ -118,7 +154,10 @@ errorret_t assetFileClose(assetfile_t *file) {
|
||||
assertNotNull(file, "Asset file cannot be NULL.");
|
||||
assertNotNull(file->zipFile, "Asset file must be opened before closing.");
|
||||
|
||||
if(zip_fclose(file->zipFile) != 0) {
|
||||
threadMutexLock(&ASSET.zipLock);
|
||||
int closeResult = zip_fclose(file->zipFile);
|
||||
threadMutexUnlock(&ASSET.zipLock);
|
||||
if(closeResult != 0) {
|
||||
errorThrow("Failed to close asset file: %s", file->filename);
|
||||
}
|
||||
file->zipFile = NULL;
|
||||
@@ -218,7 +257,7 @@ const uint8_t *assetFileLineReaderUnreadPtr(
|
||||
return reader->readBuffer + reader->bufferStart;
|
||||
}
|
||||
|
||||
static errorret_t assetFileLineReaderAppend(
|
||||
errorret_t assetFileLineReaderAppend(
|
||||
assetfilelinereader_t *reader,
|
||||
const uint8_t *src,
|
||||
size_t srcLength
|
||||
@@ -240,7 +279,7 @@ static errorret_t assetFileLineReaderAppend(
|
||||
errorOk();
|
||||
}
|
||||
|
||||
static void assetFileLineReaderTerminate(assetfilelinereader_t *reader) {
|
||||
void assetFileLineReaderTerminate(assetfilelinereader_t *reader) {
|
||||
assertNotNull(reader, "Reader cannot be NULL.");
|
||||
assertNotNull(reader->outBuffer, "Out buffer cannot be NULL.");
|
||||
assertTrue(
|
||||
@@ -250,7 +289,7 @@ static void assetFileLineReaderTerminate(assetfilelinereader_t *reader) {
|
||||
reader->outBuffer[reader->lineLength] = '\0';
|
||||
}
|
||||
|
||||
static ssize_t assetFileLineReaderFindNewline(
|
||||
ssize_t assetFileLineReaderFindNewline(
|
||||
const assetfilelinereader_t *reader
|
||||
) {
|
||||
size_t i;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "error/error.h"
|
||||
#include <zip.h>
|
||||
|
||||
#define ASSET_FILE_NAME_MAX 48
|
||||
#define ASSET_FILE_NAME_MAX 128
|
||||
|
||||
// Max bytes requested per zip_fread() call in assetFileRead(). Some
|
||||
// zip_fread() implementations (seen on PSP) reject a single call asking
|
||||
@@ -150,10 +150,67 @@ void assetFileLineReaderInit(
|
||||
const size_t outBufferSize
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns the number of bytes still unread in the line reader's read buffer.
|
||||
*
|
||||
* @param reader The line reader to check.
|
||||
* @return Number of unread bytes remaining in the read buffer.
|
||||
*/
|
||||
size_t assetFileLineReaderUnreadBytes(const assetfilelinereader_t *reader);
|
||||
|
||||
/**
|
||||
* Returns a pointer to the first unread byte in the line reader's read
|
||||
* buffer.
|
||||
*
|
||||
* @param reader The line reader to check.
|
||||
* @return Pointer to the first unread byte.
|
||||
*/
|
||||
const uint8_t *assetFileLineReaderUnreadPtr(
|
||||
const assetfilelinereader_t *reader
|
||||
);
|
||||
|
||||
/**
|
||||
* Appends src to the line reader's current line buffer, growing lineLength.
|
||||
*
|
||||
* @param reader The line reader whose out buffer to append to.
|
||||
* @param src Bytes to append.
|
||||
* @param srcLength Number of bytes in src.
|
||||
* @return Error state if any (the line would exceed the output buffer).
|
||||
*/
|
||||
errorret_t assetFileLineReaderAppend(
|
||||
assetfilelinereader_t *reader,
|
||||
const uint8_t *src,
|
||||
size_t srcLength
|
||||
);
|
||||
|
||||
/**
|
||||
* Null-terminates the line reader's current line buffer at lineLength.
|
||||
*
|
||||
* @param reader The line reader whose out buffer to terminate.
|
||||
*/
|
||||
void assetFileLineReaderTerminate(assetfilelinereader_t *reader);
|
||||
|
||||
/**
|
||||
* Searches the line reader's unread buffered bytes for a newline character.
|
||||
*
|
||||
* @param reader The line reader to search.
|
||||
* @return The index of the newline within readBuffer, or -1 if not found.
|
||||
*/
|
||||
ssize_t assetFileLineReaderFindNewline(const assetfilelinereader_t *reader);
|
||||
|
||||
/**
|
||||
* Refills the line reader's read buffer from the underlying file once its
|
||||
* buffered bytes are fully consumed. A no-op once the file is at EOF.
|
||||
*
|
||||
* @param reader The line reader to refill.
|
||||
* @return Error state if any.
|
||||
*/
|
||||
errorret_t assetFileLineReaderFill(assetfilelinereader_t *reader);
|
||||
|
||||
/**
|
||||
* Reads the next line from the asset file into the line buffer. The line
|
||||
* buffer is null-terminated and does not include the newline character.
|
||||
*
|
||||
*
|
||||
* @param reader The line reader to read from.
|
||||
* @return An error code if a failure occurs, or errorOk() if a line was read
|
||||
* successfully. If the end of the file is reached, errorEndOfFile() is
|
||||
|
||||
@@ -15,6 +15,6 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(locale)
|
||||
add_subdirectory(json)
|
||||
add_subdirectory(chunk)
|
||||
add_subdirectory(dmf)
|
||||
add_subdirectory(cutscene)
|
||||
add_subdirectory(wav)
|
||||
add_subdirectory(mp3)
|
||||
@@ -46,15 +46,15 @@ assetloadercallbacks_t ASSET_LOADER_CALLBACKS[ASSET_LOADER_TYPE_COUNT] = {
|
||||
.dispose = assetJsonDispose
|
||||
},
|
||||
|
||||
[ASSET_LOADER_TYPE_CHUNK] = {
|
||||
.loadSync = assetChunkLoaderSync,
|
||||
.loadAsync = assetChunkLoaderAsync,
|
||||
.dispose = assetChunkDispose
|
||||
[ASSET_LOADER_TYPE_WAV] = {
|
||||
.loadSync = assetWavLoaderSync,
|
||||
.loadAsync = assetWavLoaderAsync,
|
||||
.dispose = assetWavDispose
|
||||
},
|
||||
|
||||
[ASSET_LOADER_TYPE_CUTSCENE] = {
|
||||
.loadSync = assetCutsceneLoaderSync,
|
||||
.loadAsync = assetCutsceneLoaderAsync,
|
||||
.dispose = assetCutsceneDispose
|
||||
[ASSET_LOADER_TYPE_MP3] = {
|
||||
.loadSync = assetMp3LoaderSync,
|
||||
.loadAsync = assetMp3LoaderAsync,
|
||||
.dispose = assetMp3Dispose
|
||||
},
|
||||
};
|
||||
Loaded 100 of 547 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user