Skip to content

Commit b0212c6

Browse files
authored
Merge pull request #104 from workadventure/new-ui
feat: integrate new ui for map starter kit
2 parents 3c0e098 + 0289130 commit b0212c6

23 files changed

Lines changed: 3150 additions & 2257 deletions

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ TILESET_OPTIMIZATION_QUALITY_MAX=1.0
1010

1111
# Here you can set your upload strategy. Simply comment the option you don't want to use.
1212
# Learn more by reading the 'Upload your map' section in the README.
13-
# UPLOAD_MODE=MAP_STORAGE
14-
UPLOAD_MODE=GH_PAGES
13+
UPLOAD_MODE=MAP_STORAGE
14+
# UPLOAD_MODE=GH_PAGES

.github/workflows/build-and-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
run: npm install
3030

3131
- name: Build project
32-
run: npm run build
32+
run: npm run buildmap
3333

3434
- name: Extract UPLOAD_MODE from .env
3535
run: |

README.md

Lines changed: 128 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,59 +20,169 @@ Uploading a map using [GitHub Pages](https://docs.github.com/pages) will host yo
2020

2121
Uploading a map using the [WA map storage](https://docs.workadventu.re/map-building/tiled-editor/publish/wa-hosted) will host your project on WA servers. It's a bit more difficult to set up, but it comes with great advantages, like being able to have private repositories.
2222

23-
## 🗂️ Structure
23+
## 🗂️ Project Structure
2424

25-
We recommend following this file structure:
25+
```
26+
map-starter-kit/
27+
├── 📁 app/ # Server entry point (loads @workadventure/map-starter-kit-core)
28+
│ └── app.ts # Re-exports the Express app from the core package
29+
30+
├── 📁 src/ # Map scripts (Browser/WorkAdventure) ⚠️ REQUIRED
31+
│ └── main.ts # Your map scripts go here
32+
33+
34+
├── 📁 tilesets/ # Map tileset images (PNG)
35+
36+
├── 📄 *.tmj # Map files (office.tmj, conference.tmj, etc.)
37+
├── 📄 vite.config.ts # Vite configuration
38+
└── 📄 package.json # Dependencies and scripts
39+
```
40+
41+
The **server** (Express app, controllers, HTML publishing pages, static assets) is provided by the npm package **`@workadventure/map-starter-kit-core`**. Updating this dependency gives you new publishing UI and server features without changing your maps or config.
2642

27-
- *`public/`*: Static files like PDFs or audio files
28-
- *`src/`*: Script files or design source files
43+
### Quick Reference
44+
45+
- *`src/`*: **Map scripts** (MUST be here for compilation) ⚠️
2946
- *`tilesets/`*: All PNG tilesets
47+
- *`app/`*: **Server entry point** – loads the core package; do not add server logic here
3048

3149
> [!TIP]
3250
> - If you want to use more than one map file, just add the new map file in the root folder (we recommend creating a copy of *office.tmj* and editing it to avoid any mistakes).
3351
> - We recommend using **512x512** images for the map thumbnails.
34-
> - If you are going to create custom websites to embed in the map, please reference the HTML files in the `input` option in *vite.config.js*.
52+
> - If you are going to create custom websites to embed in the map, please reference the HTML files in the `input` option in *buildmap.vite.config.js*.
53+
54+
### 📁 Server entry point (`app/`)
55+
56+
The `app/` directory contains only the **entry point** that loads the server from **`@workadventure/map-starter-kit-core`**.
57+
58+
- *`app.ts`*: Imports and re-exports the Express app from the core package (for Vite’s server plugin).
59+
60+
The actual server (Express, routes, HTML pages, upload, map storage) lives in the dependency. To get updates to the publishing UI and server behaviour, run `npm update @workadventure/map-starter-kit-core`.
61+
62+
> [!IMPORTANT]
63+
> Do **not** add server logic or new controllers in `app/`. The server is fully provided by the core package.
64+
65+
### 📁 Map Scripts Development (`src/`) ⚠️
66+
67+
The `src/` directory is where you **MUST** place **all map-related scripts** that will be executed in the browser. See [src/README.md](./src/README.md) for detailed documentation and examples.
68+
69+
- *`main.ts`*: Main map script (referenced in `.tmj` files)
70+
71+
> [!IMPORTANT]
72+
> **All map scripts MUST be placed in the `src/` directory** to be properly compiled and bundled by Vite. Scripts in this directory are:
73+
> - Automatically transformed from TypeScript to JavaScript
74+
> - Bundled with their npm dependencies (like `@workadventure/scripting-api-extra`)
75+
> - Served with the correct MIME types
76+
> - Referenced in your `.tmj` map files using paths like `src/main.ts`
77+
78+
> [!WARNING]
79+
> Do not place map scripts outside the `src/` directory. They will not be compiled correctly and will cause errors in the browser.
3580
3681
## 📜 Requirements
3782

3883
- Node.js version >= 18
3984

40-
## Installation and testing
41-
4285
## 🛠️ Installation and Testing
4386

44-
With npm installed (which comes with [Node.js](https://nodejs.org/en/)), run the following command in the root directory of the project:
87+
### Prerequisites
88+
89+
- **Node.js** version >= 18 ([Download Node.js](https://nodejs.org/en/))
90+
- **npm** (comes with Node.js)
91+
92+
### 📦 Installation
93+
94+
1. Clone or download this repository
95+
2. Navigate to the project root directory
96+
3. Install dependencies:
4597

4698
```bash
4799
npm install
48100
```
49101

50-
Then, you can test your map by running:
102+
This will install all required dependencies, including Vite, TypeScript, WorkAdventure packages, and **`@workadventure/map-starter-kit-core`** (server and publishing UI).
103+
104+
### 🚀 Development
105+
106+
#### Start Development Server
107+
108+
Start the Vite development server with hot module replacement:
51109

52110
```bash
53111
npm run dev
54112
```
55113

56-
You can also test the optimized map as it will be in production by running:
114+
This will:
115+
- Start the Vite dev server (usually on `http://localhost:5173`)
116+
- Enable hot module replacement for instant updates
117+
- Automatically transform TypeScript files in `src/`
118+
- Serve your maps and assets
119+
120+
> [!TIP]
121+
> The development server will automatically open your browser. If not, navigate to the URL shown in the terminal.
122+
123+
#### Test Production Build
124+
125+
To test how your map will behave in production:
57126

58127
```bash
59-
npm run build
60-
npm run prod
128+
# Build the optimized production version for your map
129+
npm run buildmap
130+
61131
```
62132

63-
You can manually [upload your map to the WA Map Storage]([WA Map Storage](https://github.com/workadventure/upload-maps)) by running:
133+
This will:
134+
- Compile TypeScript to JavaScript
135+
- Optimize and bundle all assets
136+
- Create a production-ready `dist/` folder
137+
- Start a preview server to test the optimized build
138+
139+
### 📤 Upload Your Map
140+
141+
#### Upload to WA Map Storage
142+
143+
To upload your map to the WorkAdventure Map Storage:
64144

65145
```bash
66146
npm run upload
67147
```
68148

69-
The three important variables that control the upload feature are:
149+
This command will:
150+
1. Build your map (`npm run buildmap`)
151+
2. Upload it to the configured WA Map Storage
152+
153+
> [!IMPORTANT]
154+
> Before uploading, you need to configure your upload settings. The upload feature requires three environment variables:
155+
156+
1. **`MAP_STORAGE_URL`** - Your WorkAdventure Map Storage URL
157+
- *Local development*: Created in `.env` by the upload command
158+
- *CI/CD*: Add as a GitHub secret (optional)
159+
160+
2. **`MAP_STORAGE_API_KEY`** - Your API key for authentication
161+
- *Local development*: Created in `.env.secret` by the upload command
162+
- *CI/CD*: Add as a GitHub secret (required)
163+
164+
3. **`UPLOAD_DIRECTORY`** - Directory path on the storage server
165+
- *Local development*: Created in `.env` by the upload command
166+
- *CI/CD*: Add as a GitHub secret (optional)
167+
168+
#### Configure Upload Settings
169+
170+
You can configure these settings through the web interface:
171+
1. Start the development server (`npm run dev`)
172+
2. Navigate to the upload configuration page
173+
3. Fill in your Map Storage credentials
174+
4. Save and upload your map
175+
176+
For more details, read [the WorkAdventure upload documentation](https://docs.workadventu.re/map-building/tiled-editor/publish/wa-hosted).
70177

71-
1. `MAP_STORAGE_URL` *(local: created in .env by the upload command / CI: to be added as a Github secret optionally)*
72-
2. `MAP_STORAGE_API_KEY` *(local: created in .env.secret by the upload command / CI: to be added as a Github secret)*
73-
3. `UPLOAD_DIRECTORY` *(local: created in .env by the upload command / CI: to be added as a Github secret optionally)*
178+
### 📋 Available Scripts
74179

75-
Read [the documentation](https://docs.workadventu.re/map-building/tiled-editor/publish/wa-hosted) to learn more about the upload feature.
180+
| Command | Description |
181+
|---------|-------------|
182+
| `npm run dev` | Start Vite development server with hot reload |
183+
| `npm run buildmap` | Build only the map files (without frontend) |
184+
| `npm run upload` | Build and upload map to WA Map Storage |
185+
| `npm run upload-only` | Upload map without rebuilding (requires existing build) |
76186

77187
## 📜 Licenses
78188

app/app.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { viteNodeApp as theApp } from '@workadventure/map-starter-kit-core/dist/server.js';
2+
3+
export const viteNodeApp = theApp;

vite.config.ts renamed to buildmap.vite.config.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,11 @@ export default defineConfig({
2727
sourcemap: true,
2828
rollupOptions: {
2929
input: {
30-
index: "./index.html",
3130
...getMapsScripts(maps),
3231
},
3332
},
3433
},
35-
plugins: [...getMapsOptimizers(maps, optimizerOptions)],
36-
server: {
37-
host: "localhost",
38-
headers: {
39-
"Access-Control-Allow-Origin": "*",
40-
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
41-
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization",
42-
"Cache-Control": "no-cache, no-store, must-revalidate",
43-
},
44-
open: "/",
45-
},
34+
plugins: [
35+
...getMapsOptimizers(maps, optimizerOptions),
36+
],
4637
});

conference.tmj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,10 @@
493493
{
494494
"name":"script",
495495
"type":"string",
496-
"value":"src\/main.ts"
496+
"value":"src/main.ts"
497497
}],
498498
"renderorder":"right-down",
499-
"tiledversion":"1.10.2",
499+
"tiledversion":"1.11.2",
500500
"tileheight":32,
501501
"tilesets":[
502502
{

0 commit comments

Comments
 (0)