Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches: [ "main" ]
pull_request:
workflow_dispatch:

jobs:
build:
Expand All @@ -17,18 +18,12 @@ jobs:
run: npm ci
- name: Build
run: npm run build
- name: Build github pages
run: |
mkdir -p /tmp/github-pages/dist
cp -r packages/tyria/dev/* /tmp/github-pages
cp -r packages/tyria/dist/* /tmp/github-pages/dist
- name: Upload github pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: /tmp/github-pages/
path: apps/demo/dist/

deploy-gh-pages:
if: github.event_name == 'push'
needs: build
permissions:
pages: write
Expand All @@ -38,6 +33,6 @@ jobs:
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
24 changes: 24 additions & 0 deletions apps/demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
54 changes: 54 additions & 0 deletions apps/demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:

```js
export default tseslint.config({
extends: [
// Remove ...tseslint.configs.recommended and replace with this
...tseslint.configs.recommendedTypeChecked,
// Alternatively, use this for stricter rules
...tseslint.configs.strictTypeChecked,
// Optionally, add this for stylistic rules
...tseslint.configs.stylisticTypeChecked,
],
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```

You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:

```js
// eslint.config.js
import reactX from 'eslint-plugin-react-x'
import reactDom from 'eslint-plugin-react-dom'

export default tseslint.config({
plugins: {
// Add the react-x and react-dom plugins
'react-x': reactX,
'react-dom': reactDom,
},
rules: {
// other rules...
// Enable its recommended typescript rules
...reactX.configs['recommended-typescript'].rules,
...reactDom.configs.recommended.rules,
},
})
```
28 changes: 28 additions & 0 deletions apps/demo/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
100 changes: 100 additions & 0 deletions apps/demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tyria</title>
<style>
html, body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #051626;
}
#map {
position: absolute;
inset: 0;
animation: fadeIn 2s ease-out;
}
@keyframes fadeIn {
from { opacity: 0; }
}
.controls {
position: absolute;
top: calc(50% - 48px);
right: 16px;
display: flex;
flex-direction: column;
background-color: #fff;
border-radius: 2px;
box-shadow: 0 0 4px rgb(0 0 0 / .5);
overflow: hidden;
}
.controls > button {
width: 48px;
height: 48px;
background: transparent;
border: none;
font-size: 24px;
cursor: pointer;
}
.controls > button + button {
border-top: 1px solid #eee;
}
.controls > button:hover {
background-color: #eee;
}
.toolbar {
position: absolute;
bottom: 16px;
background: #fff;
margin-left: 50%;
margin-right: -50%;
transform: translateX(-50%);
padding: 16px;
border-radius: 2px;
box-shadow: 0 0 4px rgb(0 0 0 / .5);
display: flex;
gap: 16px;
}
#over {
position: absolute;
top: 16px;
background: #fff;
margin-left: 50%;
margin-right: -50%;
transform: translateX(-50%);
padding: 16px;
border-radius: 2px;
box-shadow: 0 0 4px rgb(0 0 0 / .5);
display: flex;
gap: 16px;
}
#over:empty {
display: none;
}
</style>
</head>
<body>
<div id="map">
<div class="controls">
<button onclick="map.easeTo({ zoom: map.view.zoom + .5 }, { duration: 300 })">+</button>
<button onclick="map.easeTo({ zoom: map.view.zoom - .5 }, { duration: 300 })">-</button>
</div>
</div>
<div class="toolbar">
<label>
<input type="checkbox" id="debug"/>
debug overlays
</label>
<button id="lionsarch">Lion's Arch</button>
<button id="lionsarch2">Lion's Arch (padding)</button>
<button id="ascalon">Ascalon</button>
<button id="horn">Horn of Maguuma</button>
<button id="cantha">Cantha</button>
</div>
<div id="over"></div>
<div id="infobox"></div>
<script type="module" src="/src/index.ts"></script>
</body>
</html>
31 changes: 31 additions & 0 deletions apps/demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "demo",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"react": "^19.0.0",
"react-dom": "^19.0.0",
"tyria": "*"
},
"devDependencies": {
"@eslint/js": "^9.22.0",
"@types/node": "^22.14.1",
"@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4",
"@vitejs/plugin-react-swc": "^3.8.0",
"eslint": "^9.22.0",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.19",
"globals": "^16.0.0",
"typescript": "~5.7.2",
"typescript-eslint": "^8.26.1",
"vite": "^6.3.1"
}
}
58 changes: 58 additions & 0 deletions apps/demo/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Tyria, TileLayer, MarkerLayer } from 'tyria';

const map = new Tyria(document.getElementById('map')!, {
backgroundColor: '#051626',
maxZoom: 7,
minZoom: 0,
zoomSnap: .5,
// padding: 80,
bounds: [[0, 0], [81920, 114688]],
padding: { top: 16, bottom: 80, left: 16, right: 80 },
});

map.addLayer(new TileLayer({
source: (x, y, z) => `https://tiles.guildwars2.com/1/1/${z}/${x}/${y}.jpg`,
bounds: [[0, 0], [81920, 114688]],
}));

const markers = new MarkerLayer({
icon: 'https://render.guildwars2.com/file/32633AF8ADEA696A1EF56D3AE32D617B10D3AC57/157353.png',
iconSize: [32, 32],
minZoom: 3,
});
map.addLayer(markers)

const waypoints = new Map();

fetch('https://api.guildwars2.com/v2/continents/1/floors/1').then((r) => r.json()).then((data) => {
// @ts-expect-error test
const wps = Object.values(data.regions ?? []).flatMap((region) => Object.values(region.maps ?? {}).flatMap((map) => Object.values(map.points_of_interest ?? {}).filter((poi) => poi.type === 'waypoint').map((poi) => ({ ...poi, map }))));
wps.forEach((wp) => waypoints.set(wp.id, wp));
markers.add(...wps.map((wp) => ({
id: wp.id,
position: wp.coord,
})))
});

map.jumpTo({ center: [49432, 31440], zoom: 2.5 });
map.easeTo({ zoom: 3 }, { duration: 2000, easing: (x) => 1 - Math.pow(1 - x, 3) });

map.addEventListener('marker.over', (e) => document.getElementById('over')!.innerText = waypoints.get(e.markerId).name);
map.addEventListener('marker.leave', () => document.getElementById('over')!.innerText = '');
map.addEventListener('marker.click', (e) => {
const wp = waypoints.get(e.markerId);
console.log(wp);
map.easeTo({ contain: wp.map.continent_rect })
});

// @ts-expect-error test
document.getElementById('debug')!.addEventListener('change', (e) => map.setDebug(e.target.checked));

document.getElementById('lionsarch')!.addEventListener('click', () => map.easeTo({ contain: [[48130, 30720], [50430, 32250]] }))
document.getElementById('lionsarch2')!.addEventListener('click', () => map.easeTo({ contain: [[48130, 30720], [50430, 32250]], padding: { top: 16, bottom: 80, left: 1000, right: 80 } }))
document.getElementById('ascalon')!.addEventListener('click', () => map.easeTo({ contain: [[56682, 24700], [64500, 35800]], zoom: 3 }))
document.getElementById('horn')!.addEventListener('click', () => map.easeTo({ contain: [[19328, 19048], [27296, 24800]] }))
document.getElementById('cantha')!.addEventListener('click', () => map.easeTo({ contain: [[20576, 97840], [39056, 106256]] }))

// @ts-expect-error debug
window.map = map;
1 change: 1 addition & 0 deletions apps/demo/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
55 changes: 55 additions & 0 deletions apps/demo/src/wvw/App.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.layout {
display: flex;
gap: 16px;
padding: 16px;
flex: 1;
}

@media (max-width: 1200px) {
.layout {
flex-direction: column;
}
}

.map {
flex: 1;
position: relative;
}

.map > canvas {
border-radius: 6px;
position: absolute;
inset: 0;
}

.sidebar {
width: 400px;
}


.controls {
position: absolute;
top: 16px;
left: 16px;
display: flex;
flex-direction: column;
background-color: #fff;
border-radius: 4px;
box-shadow: 0 0 4px rgb(0 0 0 / .5);
overflow: hidden;
z-index: 1;
}
.controls > button {
width: 48px;
height: 48px;
background: transparent;
border: none;
font-size: 24px;
cursor: pointer;
}
.controls > button + button {
border-top: 1px solid #eee;
}
.controls > button:hover {
background-color: #eee;
}
Loading