├── .eslintignore
├── .eslintrc.js
├── .github
├── ISSUE_TEMPLATE
│ └── bug_report.md
└── workflows
│ └── CI.yml
├── .gitignore
├── .prettierrc.js
├── .vercelignore
├── .vscode
└── svelte-helpers.code-snippets
├── README.md
├── docs
├── .gitignore
├── README.md
├── package.json
├── server.js
├── src
│ ├── components
│ │ ├── Ball.svelte
│ │ └── IFrameExample.svelte
│ ├── examples.css
│ ├── includes
│ │ ├── error.md
│ │ ├── logo.md
│ │ ├── sidebar.md
│ │ └── topbar.md
│ ├── index.html
│ ├── pages
│ │ ├── animation
│ │ │ └── svelte-motion.md
│ │ ├── components
│ │ │ ├── arc.md
│ │ │ ├── camera.md
│ │ │ ├── container.md
│ │ │ ├── curve.md
│ │ │ ├── ellipse.md
│ │ │ ├── game.md
│ │ │ ├── grid.md
│ │ │ ├── iso-box.md
│ │ │ ├── iso-triangle.md
│ │ │ ├── line.md
│ │ │ ├── object-layer.md
│ │ │ ├── physics
│ │ │ │ ├── arcade-collider.md
│ │ │ │ └── arcade-physics.md
│ │ │ ├── polygon.md
│ │ │ ├── rectangle.md
│ │ │ ├── scene.md
│ │ │ ├── sprite.md
│ │ │ ├── star.md
│ │ │ ├── text.md
│ │ │ ├── tile-layer.md
│ │ │ ├── tile-sprite.md
│ │ │ ├── tilemap.md
│ │ │ └── triangle.md
│ │ ├── examples
│ │ │ ├── breakout.md
│ │ │ ├── invaders.md
│ │ │ └── platformer.md
│ │ ├── getting-started.md
│ │ ├── index.md
│ │ └── roadmap.md
│ ├── static
│ │ ├── favicon.png
│ │ ├── images
│ │ │ ├── adventurer-spritesheet.png
│ │ │ ├── ball.png
│ │ │ ├── mushroom.png
│ │ │ ├── mushroom2.png
│ │ │ ├── starfield.png
│ │ │ ├── tile.png
│ │ │ ├── tiled-create-tileset.png
│ │ │ ├── tiled-new-map-0.png
│ │ │ ├── tiled-new-map-1.png
│ │ │ └── tiled-object-layer.png
│ │ └── tilemaps
│ │ │ ├── castle-tileset.png
│ │ │ └── castle.json
│ └── theme.css
├── svelte-docs.config.js
└── theme
│ ├── assets
│ ├── burger.svg
│ └── fonts
│ │ ├── fira-mono-400.woff2
│ │ ├── overpass-300.woff2
│ │ ├── overpass-400.woff2
│ │ └── overpass-600.woff2
│ ├── components
│ ├── Document.svelte
│ ├── Example.svelte
│ ├── Layout.svelte
│ ├── Properties.svelte
│ ├── Sections.svelte
│ └── Topbar.svelte
│ ├── info.md
│ ├── style.css
│ └── styles
│ ├── fonts.css
│ ├── highlight.css
│ ├── layout.css
│ └── typography.css
├── examples
├── .gitignore
├── breakout
│ ├── .gitignore
│ ├── README.md
│ ├── index.js
│ ├── package.json
│ ├── public
│ │ ├── assets
│ │ │ ├── breakout.json
│ │ │ └── breakout.png
│ │ ├── favicon.png
│ │ └── index.html
│ ├── rollup.config.js
│ └── src
│ │ ├── App.svelte
│ │ ├── Ball.svelte
│ │ ├── Block.svelte
│ │ ├── Breakout.svelte
│ │ ├── LoadingBar.svelte
│ │ └── Paddle.svelte
├── invaders
│ ├── .gitignore
│ ├── README.md
│ ├── index.js
│ ├── package.json
│ ├── public
│ │ ├── assets
│ │ │ ├── bullet.png
│ │ │ ├── enemy-bullet.png
│ │ │ ├── explode.png
│ │ │ ├── invader.png
│ │ │ ├── ship.png
│ │ │ └── starfield.png
│ │ ├── favicon.png
│ │ └── index.html
│ ├── rollup.config.js
│ └── src
│ │ ├── App.svelte
│ │ ├── Background.svelte
│ │ ├── Bullet.svelte
│ │ ├── Enemies.svelte
│ │ ├── Enemy.svelte
│ │ ├── Explosion.svelte
│ │ ├── LoadingBar.svelte
│ │ ├── Player.svelte
│ │ ├── UI.svelte
│ │ └── store.js
├── package.json
├── platformer
│ ├── .gitignore
│ ├── README.md
│ ├── index.js
│ ├── package.json
│ ├── public
│ │ ├── assets
│ │ │ ├── adventurer.png
│ │ │ ├── castle-tileset.png
│ │ │ └── tilemap.json
│ │ ├── favicon.png
│ │ └── index.html
│ ├── rollup.config.js
│ └── src
│ │ ├── App.svelte
│ │ ├── LoadingBar.svelte
│ │ └── Player.svelte
└── vercel.json
├── package.json
├── packages
└── svelte-phaser
│ ├── .babelrc
│ ├── .gitignore
│ ├── README.md
│ ├── jest.config.js
│ ├── package.json
│ └── src
│ ├── Arc.spec.js
│ ├── Arc.svelte
│ ├── ArcadeCollider.svelte
│ ├── ArcadePhysics.spec.js
│ ├── ArcadePhysics.svelte
│ ├── Camera.spec.js
│ ├── Camera.svelte
│ ├── Container.svelte
│ ├── Curve.svelte
│ ├── Ellipse.svelte
│ ├── Game.svelte
│ ├── GameObject.spec.js
│ ├── GameObject.svelte
│ ├── Grid.spec.js
│ ├── Grid.svelte
│ ├── IsoBox.spec.js
│ ├── IsoBox.svelte
│ ├── IsoTriangle.spec.js
│ ├── IsoTriangle.svelte
│ ├── Line.spec.js
│ ├── Line.svelte
│ ├── ObjectLayer.svelte
│ ├── Polygon.spec.js
│ ├── Polygon.svelte
│ ├── Rectangle.svelte
│ ├── Scene.svelte
│ ├── Shape.spec.js
│ ├── Shape.svelte
│ ├── Spawner.svelte
│ ├── Sprite.spec.js
│ ├── Sprite.svelte
│ ├── Star.spec.js
│ ├── Star.svelte
│ ├── Text.spec.js
│ ├── Text.svelte
│ ├── TileLayer.svelte
│ ├── TileSprite.spec.js
│ ├── TileSprite.svelte
│ ├── Tilemap.svelte
│ ├── Triangle.spec.js
│ ├── Triangle.svelte
│ ├── getCamera.js
│ ├── getContainer.js
│ ├── getGame.js
│ ├── getGameObject.js
│ ├── getScene.js
│ ├── getSpawner.js
│ ├── getTilemap.js
│ ├── index.mjs
│ ├── onArcadePhysicsEvent.js
│ ├── onGameEvent.js
│ ├── onInputEvent.js
│ ├── onSceneEvent.js
│ ├── phaser-components
│ ├── Alpha.spec.js
│ ├── Alpha.svelte
│ ├── BlendMode.spec.js
│ ├── BlendMode.svelte
│ ├── Crop.svelte
│ ├── Depth.spec.js
│ ├── Depth.svelte
│ ├── Flip.spec.js
│ ├── Flip.svelte
│ ├── Mask.spec.js
│ ├── Mask.svelte
│ ├── Origin.spec.js
│ ├── Origin.svelte
│ ├── PathFollower.spec.js
│ ├── PathFollower.svelte
│ ├── Pipeline.spec.js
│ ├── Pipeline.svelte
│ ├── ScrollFactor.spec.js
│ ├── ScrollFactor.svelte
│ ├── Size.spec.js
│ ├── Size.svelte
│ ├── Texture.spec.js
│ ├── Texture.svelte
│ ├── Tint.spec.js
│ ├── Tint.svelte
│ ├── Transform.spec.js
│ ├── Transform.svelte
│ ├── Visible.spec.js
│ └── Visible.svelte
│ ├── phaser.js
│ ├── test-utils
│ ├── createGame.js
│ ├── index.js
│ └── setup.js
│ └── util
│ ├── addInstance.js
│ ├── createPhaserEventDispatcher.js
│ ├── findGameObjectsByName.js
│ ├── index.js
│ ├── removeUndefined.js
│ ├── shouldApplyProps.js
│ └── toArray.js
├── templates
├── blank
│ ├── .gitignore
│ ├── App.svelte
│ ├── README.md
│ ├── index.js
│ ├── package.json
│ ├── public
│ │ ├── favicon.png
│ │ ├── global.css
│ │ └── index.html
│ └── rollup.config.js
└── snowpack
│ ├── .gitignore
│ ├── LICENSE
│ ├── README.md
│ ├── package.json
│ ├── public
│ ├── favicon.ico
│ ├── index.html
│ ├── logo.svg
│ └── robots.txt
│ ├── snowpack.config.js
│ └── src
│ ├── App.svelte
│ └── index.js
├── yarn-error.log
└── yarn.lock
/.eslintignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 | build
4 | __DOCS__
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: ['eslint:recommended'],
3 | parserOptions: {
4 | ecmaVersion: 2019,
5 | sourceType: 'module',
6 | },
7 | env: {
8 | es6: true,
9 | browser: true,
10 | node: true,
11 | },
12 |
13 | plugins: ['svelte3'],
14 | overrides: [
15 | {
16 | files: ['**/*.svelte'],
17 | processor: 'svelte3/svelte3',
18 | },
19 | {
20 | files: ['**/*.spec.js', '**/test-utils/**/*'],
21 | env: {
22 | jest: true,
23 | },
24 | // Can't extend in overrides: https://github.com/eslint/eslint/issues/8813
25 | plugins: ['jest'],
26 | rules: {
27 | 'jest/no-disabled-tests': 'warn',
28 | 'jest/no-focused-tests': 'error',
29 | 'jest/no-identical-title': 'error',
30 | 'jest/prefer-to-have-length': 'warn',
31 | 'jest/valid-expect': 'error',
32 | },
33 | },
34 | ],
35 | rules: {
36 | 'no-unused-vars': 1,
37 | },
38 | globals: {
39 | Phaser: true,
40 | },
41 | }
42 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 | ---
8 |
9 | **Describe the bug**
10 | A clear and concise description of what the bug is.
11 |
12 | **To Reproduce**
13 | Steps to reproduce the behavior:
14 |
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. See error
18 |
19 | If possible, a link to a reproduction repo or live example will always be best.
20 |
21 | **Expected behavior**
22 | A clear and concise description of what you expected to happen.
23 |
24 | **Additional context**
25 | Add any other context about the problem here.
26 |
--------------------------------------------------------------------------------
/.github/workflows/CI.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on: [pull_request]
4 |
5 | jobs:
6 | run-linters:
7 | name: Run linters
8 | runs-on: ubuntu-latest
9 | strategy:
10 | matrix:
11 | node-version: [12.x]
12 |
13 | steps:
14 | - name: Check out Git repository
15 | uses: actions/checkout@v2
16 | - name: Use Node.js ${{ matrix.node-version }}
17 | uses: actions/setup-node@v1
18 | with:
19 | node-version: ${{ matrix.node-version }}
20 |
21 | - name: yarn install
22 | run: yarn
23 |
24 | - name: Run linters
25 | uses: samuelmeuli/lint-action@v1
26 | with:
27 | github_token: ${{ secrets.github_token }}
28 | eslint: true
29 | prettier: true
30 | auto_fix: true
31 |
32 | run-tests:
33 | runs-on: ubuntu-latest
34 | strategy:
35 | matrix:
36 | node-version: [12.x]
37 |
38 | steps:
39 | - name: Check out Git repository
40 | uses: actions/checkout@v2
41 | - name: Use Node.js ${{ matrix.node-version }}
42 | uses: actions/setup-node@v1
43 | with:
44 | node-version: ${{ matrix.node-version }}
45 | - name: yarn install
46 | run: yarn
47 | - name: run tests
48 | run: yarn test
49 | env:
50 | CI: true
51 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | **/*/public/build
4 | **/*/yarn.lock
5 | .now
6 | .vercel
--------------------------------------------------------------------------------
/.prettierrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | printWidth: 80,
3 | semi: false,
4 | singleQuote: true,
5 | trailingComma: 'es5',
6 | tabWidth: 2,
7 | }
8 |
--------------------------------------------------------------------------------
/.vercelignore:
--------------------------------------------------------------------------------
1 | build
2 | dist
3 | __DOCS__
4 |
--------------------------------------------------------------------------------
/.vscode/svelte-helpers.code-snippets:
--------------------------------------------------------------------------------
1 | {
2 | // Place your svelte-phaser workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
3 | // description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
4 | // is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
5 | // used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
6 | // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
7 | // Placeholders with the same ids are connected.
8 | // Example:
9 | // "Print to console": {
10 | // "scope": "javascript,typescript",
11 | // "prefix": "log",
12 | // "body": [
13 | // "console.log('$1');",
14 | // "$2"
15 | // ],
16 | // "description": "Log output to console"
17 | // }
18 | "export prop": {
19 | "prefix": "el",
20 | "body": ["export let $1 = undefined", ""]
21 | },
22 | "apply prop": {
23 | "prefix": "ap",
24 | "body": [
25 | "$: shouldApplyProps($1) && $1 !== instance.$1 && (instance.$2)",
26 | ""
27 | ]
28 | },
29 | "apply prop if": {
30 | "prefix": "apif",
31 | "body": [
32 | "$: {",
33 | "\tif (shouldApplyProps($1)) {",
34 | "\t\tinstance$2",
35 | "\t}",
36 | "}",
37 | ""
38 | ]
39 | },
40 | "update instance": {
41 | "prefix": "ui",
42 | "body": ["$1 = instance.$1"]
43 | },
44 | "jsdoc": {
45 | "prefix": "/**",
46 | "body": ["/**", " * $1", " * @type {$2}", " */"]
47 | },
48 | "jsdoc number": {
49 | "prefix": "/**n",
50 | "body": ["/**", " * $1", " * @type {number}", " */"]
51 | },
52 | "jsdoc string": {
53 | "prefix": "/**s",
54 | "body": ["/**", " * $1", " * @type {string}", " */"]
55 | },
56 | "jsdoc boolean": {
57 | "prefix": "/**b",
58 | "body": ["/**", " * $1", " * @type {boolean}", " */"]
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ⚠️ No longer maintained ⚠️
2 |
3 | I am no longer maintaining this project. The documentation will stay up as the content here may still be useful to some, but I have no plans on continuing this library.
4 |
5 | # Documentation
6 |
7 | Check out the [documentation](https://svelte-phaser.com)
8 |
9 | # Getting Started
10 |
11 | ### Creating a new project
12 |
13 | The easiest way to get started is to create a new project using the blank template:
14 |
15 | ```shell
16 | npx degit mattjennings/svelte-phaser/templates/blank my-first-game
17 | cd my-first-game
18 | npm install
19 | npm run dev
20 | ```
21 |
22 | If a blank project is too boring, feel free to look through the [examples](https://github.com/mattjennings/svelte-phaser/tree/master/examples).
23 |
24 | ### Adding to an existing project
25 |
26 | If you have an existing svelte project you can just install `svelte-phaser`:
27 |
28 | ```shell
29 | npm install phaser svelte-phaser
30 | ```
31 |
32 | and then import it:
33 |
34 | ```svelte
35 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | ```
45 |
--------------------------------------------------------------------------------
/docs/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | __DOCS__
3 | dist
4 | .vercel
--------------------------------------------------------------------------------
/docs/README.md:
--------------------------------------------------------------------------------
1 | # Credits for Assets
2 |
3 | [rvos](https://rvros.itch.io/)
4 |
5 | - [adventurer-spritesheet.png](https://rvros.itch.io/animated-pixel-hero)
6 |
7 | Phaser
8 |
9 | - mushroom.png
10 | - mushroom2.png
11 | - starfield.png
12 |
--------------------------------------------------------------------------------
/docs/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "name": "docs",
4 | "version": "0.3.1",
5 | "dependencies": {
6 | "@svelte-docs/server": "^0.1.3",
7 | "svelte-phaser": "0.0.6",
8 | "svelte-fragment": "1.0.1"
9 | },
10 | "devDependencies": {
11 | "@svelte-docs/core": "^0.10.1",
12 | "@svelte-docs/publisher": "^0.2.3",
13 | "@svelte-docs/themes": "^1.0.0",
14 | "npm-run-all": "^4.1.5",
15 | "rollup": "^1.32.1",
16 | "svelte": "^3.21.0",
17 | "phaser": "^3.23.0"
18 | },
19 | "scripts": {
20 | "clean": "rm -rf __DOCS__",
21 | "copy-index-html": "cp src/index.html __DOCS__/dist",
22 | "build": "yarn clean && rollup -c node_modules/@svelte-docs/core/rollup.config.js",
23 | "autobuild": "rollup -c node_modules/@svelte-docs/core/rollup.config.js -w",
24 | "dev": "run-p start:dev start:pagewatch autobuild",
25 | "start": "node node_modules/@svelte-docs/server",
26 | "start:dev": "node ./server --dev --single --cors",
27 | "start:pagewatch": "node node_modules/@svelte-docs/core/watcher",
28 | "deploy": "npm run build && node node_modules/@svelte-docs/publisher",
29 | "post:build": "yarn copy-index-html"
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/docs/server.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | // taken from https://github.com/AlexxNB/svelte-docs/blob/master/packages/server/server.js
4 | // modified to enable CORS
5 |
6 | const path = require('path')
7 | const meow = require('meow')
8 | const sirv = require('sirv')
9 | const { createServer } = require('http')
10 | const clear = require('console-clear')
11 | const chalk = require('chalk')
12 | const importCWD = require('import-cwd')
13 |
14 | const config = importCWD('./svelte-docs.config.js')
15 |
16 | const cli = meow(
17 | `
18 | Usage
19 | $ node sirv.js [options]
20 |
21 | Options
22 | --dev, -d Development mode
23 | --single, -s SPA Mode
24 |
25 | Examples
26 | $ node sirv.js --dev --basepath subdir
27 | `,
28 | {
29 | flags: {
30 | dev: {
31 | type: 'boolean',
32 | alias: 'd',
33 | },
34 | single: {
35 | type: 'boolean',
36 | alias: 's',
37 | },
38 | },
39 | }
40 | )
41 |
42 | const CWD = process.cwd()
43 |
44 | const DEV = cli.flags.dev
45 | const SINGLE = cli.flags.single
46 |
47 | const DIR = DEV
48 | ? path.join(CWD, config.pathes.dev)
49 | : path.join(CWD, config.pathes.build)
50 |
51 | let port = process.env.PORT || 5000
52 | let hostname = process.env.HOST || '0.0.0.0'
53 |
54 | const mw = sirv(DIR, {
55 | setHeaders: (res) => {
56 | res.setHeader('Access-Control-Allow-Origin', '*')
57 | res.setHeader(
58 | 'Access-Control-Allow-Headers',
59 | 'Origin, Content-Type, Accept, Range'
60 | )
61 | },
62 | dev: DEV,
63 | maxAge: 31536000, // 1Y
64 | immutable: true,
65 | onNoMatch: SINGLE
66 | ? (req, res) => (
67 | (req.path = config.basepath),
68 | mw(req, res, () => ((res.statusCode = 404), res.end()))
69 | )
70 | : undefined,
71 | })
72 |
73 | createServer(mw).listen(port, hostname, (err) => {
74 | if (err) throw err
75 |
76 | const srv = DEV
77 | ? chalk.yellow('DEVELOPMENT server started...')
78 | : chalk.green('Server started...')
79 |
80 | clear(true)
81 | console.log(`
82 | ${chalk.bold('Svelte-Docs:')} ${srv}
83 | Please open: ${chalk.blue(
84 | 'http://' +
85 | (hostname === '0.0.0.0' ? 'localhost' : hostname) +
86 | ':' +
87 | port +
88 | config.basepath
89 | )}
90 | `)
91 | })
92 |
--------------------------------------------------------------------------------
/docs/src/components/Ball.svelte:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/docs/src/components/IFrameExample.svelte:
--------------------------------------------------------------------------------
1 |
6 |
7 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/docs/src/examples.css:
--------------------------------------------------------------------------------
1 | /* Styling of the examples view */
2 |
3 | body {
4 | color: #333;
5 | margin: 0;
6 | padding: 8px;
7 | box-sizing: border-box;
8 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
9 | Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
10 | }
11 |
12 | a {
13 | color: rgb(0, 100, 200);
14 | text-decoration: none;
15 | }
16 |
17 | a:hover {
18 | text-decoration: underline;
19 | }
20 |
21 | a:visited {
22 | color: rgb(0, 80, 160);
23 | }
24 |
25 | label {
26 | display: block;
27 | }
28 |
29 | input,
30 | button,
31 | select,
32 | textarea {
33 | font-family: inherit;
34 | font-size: inherit;
35 | padding: 0.4em;
36 | margin: 0 0 0.5em 0;
37 | box-sizing: border-box;
38 | border: 1px solid #ccc;
39 | border-radius: 2px;
40 | }
41 |
42 | input:disabled {
43 | color: #ccc;
44 | }
45 |
46 | input[type='range'] {
47 | height: 0;
48 | }
49 |
50 | button {
51 | background-color: #f4f4f4;
52 | outline: none;
53 | }
54 |
55 | button:active {
56 | background-color: #ddd;
57 | }
58 |
59 | button:focus {
60 | border-color: #666;
61 | }
62 |
63 | canvas {
64 | display: block;
65 | margin: auto;
66 | }
67 |
--------------------------------------------------------------------------------
/docs/src/includes/error.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: 'no_sidebar'
3 | ---
4 |
5 | # Page not found!
6 |
7 | [Go to start page](/)
8 |
9 |
13 |
--------------------------------------------------------------------------------
/docs/src/includes/logo.md:
--------------------------------------------------------------------------------
1 | # [svelte-phaser](/)
2 |
--------------------------------------------------------------------------------
/docs/src/includes/sidebar.md:
--------------------------------------------------------------------------------
1 | - [Getting Started](getting-started)
2 | - Components
3 |
4 | - [Arc](components/arc)
5 | - [Camera](components/camera)
6 | - [Container](components/container)
7 | - [Curve](components/curve)
8 | - [Ellipse](components/ellipse)
9 | - [Game](components/game)
10 | - [Grid](components/grid)
11 | - [IsoBox](components/iso-box)
12 | - [IsoTriangle](components/iso-triangle)
13 | - [Line](components/line)
14 | - [Polygon](components/polygon)
15 | - [Rectangle](components/rectangle)
16 | - [Scene](components/scene)
17 | - [Sprite](components/sprite)
18 | - [Star](components/star)
19 | - [TileSprite](components/tile-sprite)
20 | - [Text](components/text)
21 | - [Triangle](components/triangle)
22 | - Physics
23 | - [ArcadePhysics](components/physics/arcade-physics)
24 | - [ArcadeCollider](components/physics/arcade-collider)
25 | - Tilemaps
26 | - [Tilemap](components/tilemap)
27 | - [TileLayer](components/tile-layer)
28 | - [ObjectLayer](components/object-layer)
29 |
30 | - Animation
31 |
32 | - [svelte/motion](animation/svelte-motion)
33 |
34 | - [Examples](https://github.com/mattjennings/svelte-phaser/tree/master/examples)
35 |
36 | - [Breakout](examples/breakout)
37 | - [Invaders](examples/invaders)
38 | - [Platformer (WIP)](examples/platformer)
39 |
40 | - [Roadmap](roadmap)
41 |
--------------------------------------------------------------------------------
/docs/src/includes/topbar.md:
--------------------------------------------------------------------------------
1 | - [Docs](getting-started)
2 | - [Github](https://github.com/mattjennings/svelte-phaser)
3 |
--------------------------------------------------------------------------------
/docs/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | svelte-phaser
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/docs/src/pages/animation/svelte-motion.md:
--------------------------------------------------------------------------------
1 | # svelte/motion
2 |
3 | You can use `svelte/motion` for animations just as you would in other Svelte applications.
4 |
5 | ## Spring
6 |
7 | This is a recreation of an example from [a svelte.dev tutorial](https://svelte.dev/tutorial/actions)
8 |
9 | ```example
10 |
35 |
36 |
39 | {
42 | scene.load.image('mushroom', 'static/images/mushroom.png')
43 | }}>
44 |
45 |
53 |
54 |
55 | ```
56 |
57 | ## Tween
58 |
59 | ```example
60 |
86 |
87 |
90 |
91 |
99 |
107 |
108 |
109 | ```
110 |
--------------------------------------------------------------------------------
/docs/src/pages/components/arc.md:
--------------------------------------------------------------------------------
1 | # Arc
2 |
3 | Renders an "arc" shape. This can be used for circles or semi-circles.
4 |
5 | # Usage
6 |
7 | ```example
8 |
11 |
12 |
13 |
14 |
19 |
27 |
28 |
29 | ```
30 |
31 | ## Properties
32 |
33 | ```properties
34 | ./../packages/svelte-phaser/src/Arc.svelte
35 | ```
36 |
--------------------------------------------------------------------------------
/docs/src/pages/components/camera.md:
--------------------------------------------------------------------------------
1 | # Camera
2 |
3 | Creates a 2D Camera.
4 |
5 | [Read more about Cameras at the Phaser docs](https://photonstorm.github.io/phaser3-docs/Phaser.Cameras.Scene2D.Camera.html)
6 |
7 | ## Usage
8 |
9 | ```example
10 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | ```
24 |
25 | ## Properties
26 |
27 | ```properties
28 | ./../packages/svelte-phaser/src/Camera.svelte
29 | ```
30 |
--------------------------------------------------------------------------------
/docs/src/pages/components/container.md:
--------------------------------------------------------------------------------
1 | # Container
2 |
3 | Containers are used to group game objects together. All children are positioned relative to the parent container and inherit any transform properties (such as scale or angle).
4 |
5 | [Read more about Containers](https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.Container.html)
6 |
7 | # Usage
8 |
9 | ```example
10 |
37 |
38 |
39 |
40 |
41 |
47 |
53 |
54 |
55 |
56 |
57 | ```
58 |
59 | ## Properties
60 |
61 | ```properties
62 | ./../packages/svelte-phaser/src/Container.svelte
63 | ```
64 |
--------------------------------------------------------------------------------
/docs/src/pages/components/curve.md:
--------------------------------------------------------------------------------
1 | # Curve
2 |
3 | Renders a curve.
4 |
5 | # Usage
6 |
7 | ```example
8 |
12 |
13 |
14 |
15 |
28 |
29 |
30 | ```
31 |
32 | ## Properties
33 |
34 | ```properties
35 | ./../packages/svelte-phaser/src/Curve.svelte
36 | ```
37 |
--------------------------------------------------------------------------------
/docs/src/pages/components/ellipse.md:
--------------------------------------------------------------------------------
1 | # Ellipse
2 |
3 | Renders an ellipse.
4 |
5 | # Usage
6 |
7 | ```example
8 |
11 |
12 |
13 |
14 |
20 |
27 |
28 |
29 |
30 | ```
31 |
32 | ## Properties
33 |
34 | ```properties
35 | ./../packages/svelte-phaser/src/Ellipse.svelte
36 | ```
37 |
--------------------------------------------------------------------------------
/docs/src/pages/components/game.md:
--------------------------------------------------------------------------------
1 | # Game
2 |
3 | Creates a Phaser.Game instance. Only [Scene](/svelte-phaser/components/scene/) components can be children of Game.
4 |
5 | ## Usage
6 |
7 | ```example
8 |
11 |
12 |
13 | ```
14 |
15 | ## Properties
16 |
17 | ```properties
18 | ./../packages/svelte-phaser/src/Game.svelte
19 | ```
20 |
21 | ## Events
22 |
23 | ```properties
24 | on:preBoot | Called at the start of the boot sequence. | function
25 | on:postBoot | Called at the end of the boot sequence. At this point, all the game systems have started and plugins have been loaded. | function
26 | ```
27 |
--------------------------------------------------------------------------------
/docs/src/pages/components/grid.md:
--------------------------------------------------------------------------------
1 | # Grid
2 |
3 | Renders a grid.
4 |
5 | # Usage
6 |
7 | ```example
8 |
11 |
12 |
13 |
14 |
25 |
26 |
27 |
28 | ```
29 |
30 | ## Properties
31 |
32 | ```properties
33 | ./../packages/svelte-phaser/src/Grid.svelte
34 | ```
35 |
--------------------------------------------------------------------------------
/docs/src/pages/components/iso-box.md:
--------------------------------------------------------------------------------
1 | # IsoBox
2 |
3 | Renders an isometric rectangle.
4 |
5 | # Usage
6 |
7 | ```example
8 |
24 |
25 |
26 |
27 |
35 |
44 |
45 |
46 |
47 | ```
48 |
49 | ## Properties
50 |
51 | ```properties
52 | ./../packages/svelte-phaser/src/IsoBox.svelte
53 | ```
54 |
--------------------------------------------------------------------------------
/docs/src/pages/components/iso-triangle.md:
--------------------------------------------------------------------------------
1 | # IsoTriangle
2 |
3 | Renders an isometric triangle.
4 |
5 | Note: there is currently a [bug with Phaser 3.23.0](https://github.com/photonstorm/phaser/issues/5164) that causes the left-side of the first triangle not to render.
6 |
7 | # Usage
8 |
9 | ```example
10 |
26 |
27 |
28 |
29 |
37 |
47 |
48 |
49 |
50 | ```
51 |
52 | ## Properties
53 |
54 | ```properties
55 | ./../packages/svelte-phaser/src/IsoTriangle.svelte
56 | ```
57 |
--------------------------------------------------------------------------------
/docs/src/pages/components/line.md:
--------------------------------------------------------------------------------
1 | # Line
2 |
3 | Renders a line.
4 |
5 | # Usage
6 |
7 | ```example
8 |
11 |
12 |
13 |
14 |
22 |
23 |
24 |
25 | ```
26 |
27 | ## Properties
28 |
29 | ```properties
30 | ./../packages/svelte-phaser/src/Line.svelte
31 | ```
32 |
--------------------------------------------------------------------------------
/docs/src/pages/components/object-layer.md:
--------------------------------------------------------------------------------
1 | # ObjectLayer
2 |
3 | Spawns Svelte components using the object layer from the tilemap. It requires a `Spawner` component
4 | to be above it (usually above the ``).
5 |
6 | ObjectLayer will look for objects with a custom property "component". If this is defined, and the value exists in
7 | the `components` prop, it will spawn the component. Any other properties defined will be
8 | passed into the component as props.
9 |
10 | 
11 |
12 | ## Usage
13 |
14 | ```example
15 |
20 |
21 |
32 | {
35 | scene.load.image('textures/ball', '/static/images/ball.png')
36 | scene.load.tilemapTiledJSON('tilemaps/main-level', '/static/tilemaps/castle.json')
37 | scene.load.image('tilesets/castle', '/static/tilemaps/castle-tileset.png')
38 | }}
39 | >
40 |
41 |
44 |
45 |
46 |
49 |
54 |
55 |
56 |
57 |
58 |
59 | ```
60 |
61 | ## Properties
62 |
63 | ```properties
64 | ./../packages/svelte-phaser/src/ObjectLayer.svelte
65 | ```
66 |
--------------------------------------------------------------------------------
/docs/src/pages/components/physics/arcade-collider.md:
--------------------------------------------------------------------------------
1 | # Arcade Collider
2 |
3 | Enables collisions against another Arcade physics-enabled game object.
4 |
5 | ## Usage
6 |
7 | ```example
8 |
11 |
12 |
13 | scene.load.image('mushroom', '/static/images/mushroom.png')}>
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | ```
25 |
26 | ## Properties
27 |
28 | ```properties
29 | allowCollision | Called when objects are about to collide. If it returns false the collision will be skipped | function
30 | overlapOnly | Allows the objects to pass through eachother, but still fires collision events | boolean(false)
31 | with | The name of the other game objects you want to collide with, or the game object itself. | string/string[]/Phaser.GameObjects.GameObject/Phaser.GameObjects.GameObject[]
32 | ```
33 |
34 | ## Events
35 |
36 | ```properties
37 | on:collide | Fired when the objects collide | function
38 | ```
39 |
--------------------------------------------------------------------------------
/docs/src/pages/components/physics/arcade-physics.md:
--------------------------------------------------------------------------------
1 | # Arcade Physics
2 |
3 | Adds Arcade physics to the parent game object component. The Game or Scene must be configured to use arcade physics.
4 |
5 | Arcade offers basic physics and collision capabilities. You can read more about Arcade physics [from the Phaser 3 documentation](https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.ArcadePhysics.html).
6 |
7 | Alternatively, Phaser offers a Matter.js physics system, but svelte-phaser does not yet support it.
8 |
9 | ## Usage
10 |
11 | ```example
12 |
15 |
16 |
17 | scene.load.image('mushroom', 'static/images/mushroom.png')}>
18 |
19 |
20 |
21 |
22 |
23 | ```
24 |
25 | ## Properties
26 |
27 | ```properties
28 | ./../packages/svelte-phaser/src/ArcadePhysics.svelte
29 | ```
30 |
--------------------------------------------------------------------------------
/docs/src/pages/components/polygon.md:
--------------------------------------------------------------------------------
1 | # Polygon
2 |
3 | Renders a polygon.
4 |
5 | # Usage
6 |
7 | ```example
8 |
11 |
12 |
13 |
14 |
49 |
50 |
51 |
52 | ```
53 |
54 | ## Properties
55 |
56 | ```properties
57 | ./../packages/svelte-phaser/src/Polygon.svelte
58 | ```
59 |
--------------------------------------------------------------------------------
/docs/src/pages/components/rectangle.md:
--------------------------------------------------------------------------------
1 | # Rectangle
2 |
3 | Renders a rectangle.
4 |
5 | # Usage
6 |
7 | ```example
8 |
11 |
12 |
13 |
14 |
20 |
27 |
28 |
29 |
30 | ```
31 |
32 | ## Properties
33 |
34 | ```properties
35 | ./../packages/svelte-phaser/src/Rectangle.svelte
36 | ```
37 |
--------------------------------------------------------------------------------
/docs/src/pages/components/scene.md:
--------------------------------------------------------------------------------
1 | # Scene
2 |
3 | A Scene is required to render components into your game. Typically Scenes are used as levels, or stages; however,
4 | you can render more than one at a time if you wish.
5 |
6 | Every Scene requires a `key` which should be a unique identifier. If you have textures or other assets that are used in the scene
7 | you can load them with the `preload` prop.
8 |
9 | ## Usage
10 |
11 | ### Preloading Assets
12 |
13 | ```example
14 |
17 |
18 |
19 | {
22 | scene.load.image('mushroom', '/static/images/mushroom.png')
23 | }}
24 | >
25 |
26 |
27 |
28 | ```
29 |
30 | ### Loading Screen
31 |
32 | Scenes have a slot that can be used for loading screen. Svelte does not support slots on non-DOM elements,
33 | but we can make use of the `svelte-fragment` package to render a custom loading screen.
34 |
35 | ```example
36 |
40 |
41 |
42 | {
45 | scene.load.image('mushroom', '/static/images/mushroom.png')
46 | scene.load.image('mushroom2', '/static/images/mushroom2.png')
47 |
48 | // because we're only loading 2 assets the loading screen
49 | // will go by pretty quick. try throttling your network speed
50 | // in your browser dev tools and then clicking one of the mushrooms
51 | }}
52 | >
53 |
54 |
59 |
60 |
61 | window.location.reload()}/>
62 | window.location.reload()}/>
63 |
64 |
65 |
66 | ```
67 |
68 | ## Properties
69 |
70 | ```properties
71 | ./../packages/svelte-phaser/src/Scene.svelte
72 | ```
73 |
--------------------------------------------------------------------------------
/docs/src/pages/components/sprite.md:
--------------------------------------------------------------------------------
1 | # Sprite
2 |
3 | Renders an image onto the canvas. Sprites can be either static or animated.
4 |
5 | They require a texture to be loaded first, so be sure to load them in the Scene's `preload`.
6 |
7 | ## Usage
8 |
9 | ### Static
10 |
11 | ```example
12 |
15 |
16 |
17 | {
20 | scene.load.image('mushroom', '/static/images/mushroom.png')
21 | }}
22 | >
23 |
24 |
25 |
26 | ```
27 |
28 | ### Animated
29 |
30 | ```example
31 |
34 |
35 |
36 | {
39 | scene.load.spritesheet(
40 | 'adventurer',
41 | '/static/images/adventurer-spritesheet.png',
42 | {
43 | frameWidth: 50,
44 | frameHeight: 37,
45 | }
46 | )
47 | }}
48 | create={(scene) => {
49 | scene.anims.create({
50 | key: 'idle',
51 | frames: scene.anims.generateFrameNumbers('adventurer', {
52 | start: 0,
53 | end: 3,
54 | }),
55 | frameRate: 10,
56 | repeat: -1,
57 | })
58 | }}
59 | >
60 |
61 |
62 |
63 | ```
64 |
65 | ## Properties
66 |
67 | ```properties
68 | ./../packages/svelte-phaser/src/Sprite.svelte
69 | ```
70 |
71 | ## Events
72 |
73 | ```properties
74 | on:animationstart | Animation has started playing | function
75 | on:animationcomplete | Animation has finished playing | function
76 | on:animationrestart | Animation has restarted | function
77 | on:animationrepeat | A repeating animation has begun a repeat | function
78 | on:drag | Pointer drag input event | function
79 | on:dragend | Pointer drag end input event | function
80 | on:dragenter | Pointer drag enter input event | function
81 | on:dragleave | Pointer drag leave input event | function
82 | on:dragstart | Pointer drag start input event | function
83 | on:drop | Pointer drag drop input event | function
84 | on:pointerdown | Pointer down input event | function
85 | on:pointermove | Pointer move input event | function
86 | on:pointerout | Pointer out input event | function
87 | on:pointerover | Pointer over input event | function
88 | on:pointerup | Pointer up input event | function
89 | on:pointerwheel | Pointer wheel input event | function
90 | ```
91 |
--------------------------------------------------------------------------------
/docs/src/pages/components/star.md:
--------------------------------------------------------------------------------
1 | # Star
2 |
3 | Renders a star.
4 |
5 | # Usage
6 |
7 | ```example
8 |
11 |
12 |
13 |
14 |
21 |
29 |
30 |
31 |
32 | ```
33 |
34 | ## Properties
35 |
36 | ```properties
37 | ./../packages/svelte-phaser/src/Star.svelte
38 | ```
39 |
--------------------------------------------------------------------------------
/docs/src/pages/components/text.md:
--------------------------------------------------------------------------------
1 | # Text
2 |
3 | Renders text onto the canvas.
4 |
5 | ## Usage
6 |
7 | ```example
8 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | ```
18 |
19 | ## Properties
20 |
21 | ```properties
22 | ./../packages/svelte-phaser/src/Text.svelte
23 | ```
24 |
25 | ## Events
26 |
27 | These events will not be emitted on Text components unless you set the `interactive` prop.
28 |
29 | ```properties
30 | on:drag | Pointer drag input event | function
31 | on:dragend | Pointer drag end input event | function
32 | on:dragenter | Pointer drag enter input event | function
33 | on:dragleave | Pointer drag leave input event | function
34 | on:dragstart | Pointer drag start input event | function
35 | on:drop | Pointer drag drop input event | function
36 | on:pointerdown | Pointer down input event | function
37 | on:pointermove | Pointer move input event | function
38 | on:pointerout | Pointer out input event | function
39 | on:pointerover | Pointer over input event | function
40 | on:pointerup | Pointer up input event | function
41 | on:pointerwheel | Pointer wheel input event | function
42 | ```
43 |
--------------------------------------------------------------------------------
/docs/src/pages/components/tile-layer.md:
--------------------------------------------------------------------------------
1 | # TileLayer
2 |
3 | Renders a tile layer from the tilemap
4 |
5 | ## Usage
6 |
7 | ```example
8 |
12 |
13 |
14 | {
17 | scene.load.tilemapTiledJSON('tilemaps/main-level', '/static/tilemaps/castle.json')
18 | scene.load.image('tilesets/castle', '/static/tilemaps/castle-tileset.png')
19 | }}
20 | >
21 |
24 |
27 |
30 |
31 |
32 |
33 |
34 | ```
35 |
36 | ## Properties
37 |
38 | ```properties
39 | ./../packages/svelte-phaser/src/TileLayer.svelte
40 | ```
41 |
--------------------------------------------------------------------------------
/docs/src/pages/components/tile-sprite.md:
--------------------------------------------------------------------------------
1 | # TileSprite
2 |
3 | TileSprites are Sprites that have repeating textures.
4 |
5 | The texture can be scrolled and scaled independently of the TileSprite itself. Textures will automatically wrap and are designed so that you can create game backdrops using seamless textures as a source.
6 |
7 | ## Usage
8 |
9 | ```example
10 |
23 |
24 |
25 | {
28 | scene.load.image('starfield', '/static/images/starfield.png')
29 | }}
30 | >
31 |
40 |
41 |
42 |
43 | ```
44 |
45 | ## Properties
46 |
47 | ```properties
48 | ./../packages/svelte-phaser/src/TileSprite.svelte
49 | ```
50 |
51 | ## Events
52 |
53 | ```properties
54 | on:drag | Pointer drag input event | function
55 | on:dragend | Pointer drag end input event | function
56 | on:dragenter | Pointer drag enter input event | function
57 | on:dragleave | Pointer drag leave input event | function
58 | on:dragstart | Pointer drag start input event | function
59 | on:drop | Pointer drag drop input event | function
60 | on:pointerdown | Pointer down input event | function
61 | on:pointermove | Pointer move input event | function
62 | on:pointerout | Pointer out input event | function
63 | on:pointerover | Pointer over input event | function
64 | on:pointerup | Pointer up input event | function
65 | on:pointerwheel | Pointer wheel input event | function
66 | ```
67 |
--------------------------------------------------------------------------------
/docs/src/pages/components/tilemap.md:
--------------------------------------------------------------------------------
1 | # Tilemap
2 |
3 | Creates a Tilemap. It won't render anything on its own, so see [TileLayer](components/tile-layer) for rendering the layers.
4 |
5 | # Using Tiled
6 |
7 | It is recommended to use [Tiled](https://www.mapeditor.org/) to create your tilemaps. I have only used this component with Tiled, so YMMV if you decide to create your tilemaps on your own.
8 |
9 | ### Creating a Tilemap
10 |
11 | If you've opened Tiled for the first time, you should see a blank page with a "New map..." button. Click that to create a new tilemap, otherwise you can use `File -> New -> New map`
12 |
13 | Make sure the following settings are set, and then save.
14 |
15 | - **Orientation** - Orthogonal
16 | - **Tile layer format** - Base64 (uncompressed)
17 |
18 | 
19 |
20 | ### Creating a Tileset
21 |
22 | Now we need to add a tileset. Go to `File -> New -> New tileset`
23 |
24 | Make sure the following settings are set, and then save.
25 |
26 | - **Type** - Based on Tileset Image
27 | - **Embed in Map** - checked
28 |
29 | 
30 |
31 | Now you're ready to start making your tilemap.
32 |
33 | ### Exporting a Tilemap
34 |
35 | Once you're ready to try it out in your game, go to `File -> Export As` and save it as a JSON file. This is the file that you want to load
36 | in your game, as well as each of the tileset images.
37 |
38 | Pro tip: You can open the JSON file with Tiled rather than the .tmx file, meaning saves will update the JSON file and you won't
39 | have to keep exporting each time.
40 |
41 | ## Usage
42 |
43 | ```example
44 |
48 |
49 |
50 | {
53 | scene.load.tilemapTiledJSON('tilemaps/main-level', '/static/tilemaps/castle.json')
54 | scene.load.image('tilesets/castle', '/static/tilemaps/castle-tileset.png')
55 | }}
56 | >
57 |
60 |
63 |
66 |
67 |
68 |
69 |
70 | ```
71 |
72 | ## Properties
73 |
74 | ```properties
75 | ./../packages/svelte-phaser/src/Tilemap.svelte
76 | ```
77 |
--------------------------------------------------------------------------------
/docs/src/pages/components/triangle.md:
--------------------------------------------------------------------------------
1 | # Triangle
2 |
3 | Renders a triangle.
4 |
5 | # Usage
6 |
7 | ```example
8 |
11 |
12 |
13 |
14 |
24 |
35 |
36 |
37 |
38 | ```
39 |
40 | ## Properties
41 |
42 | ```properties
43 | ./../packages/svelte-phaser/src/Triangle.svelte
44 | ```
45 |
--------------------------------------------------------------------------------
/docs/src/pages/examples/breakout.md:
--------------------------------------------------------------------------------
1 | import IFrameExample from '../../components/IFrameExample.svelte'
2 |
3 | # Breakout
4 |
5 | Mouse cursor to move paddle, click to launch ball
6 |
7 | [View the source](https://github.com/mattjennings/svelte-phaser/tree/master/examples/breakout)
8 |
9 |
10 |
--------------------------------------------------------------------------------
/docs/src/pages/examples/invaders.md:
--------------------------------------------------------------------------------
1 | import IFrameExample from '../../components/IFrameExample.svelte'
2 |
3 | # Invaders
4 |
5 | Arrow keys to move, spacebar to shoot
6 |
7 | [View the source](https://github.com/mattjennings/svelte-phaser/tree/master/examples/invaders)
8 |
9 |
10 |
--------------------------------------------------------------------------------
/docs/src/pages/examples/platformer.md:
--------------------------------------------------------------------------------
1 | import IFrameExample from '../../components/IFrameExample.svelte'
2 |
3 | # Platformer
4 |
5 | Arrow keys to move, spacebar to jump
6 |
7 | [View the source](https://github.com/mattjennings/svelte-phaser/tree/master/examples/platformer)
8 |
9 |
10 |
--------------------------------------------------------------------------------
/docs/src/pages/getting-started.md:
--------------------------------------------------------------------------------
1 | # Getting Started
2 |
3 | This is still very much a work in progress! Many features of Phaser are still missing. Please be aware that breaking changes **will** happen during these early stages, but don't let that scare you from giving it a try.
4 |
5 | ### Creating a new project
6 |
7 | The easiest way to get started is to create a new project using the blank template:
8 |
9 | ```shell
10 | npx degit mattjennings/svelte-phaser/templates/blank my-first-game
11 | cd my-first-game
12 | npm install
13 | npm run dev
14 | ```
15 |
16 | If a blank project is too boring, feel free to look through the [examples](https://github.com/mattjennings/svelte-phaser/tree/master/examples).
17 |
18 | ### Adding to an existing project
19 |
20 | If you have an existing svelte project, run:
21 |
22 | ```shell
23 | npm install phaser svelte-phaser
24 | ```
25 |
26 | and then import it:
27 |
28 | ```svelte
29 |
32 |
33 |
34 |
35 |
36 |
37 |
38 | ```
39 |
--------------------------------------------------------------------------------
/docs/src/pages/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: 'no_sidebar'
3 | title: false
4 | ---
5 |
6 |
7 |
8 |
svelte-phaser
9 |
Create Phaser games with Svelte
10 |
11 |
12 |
15 |
16 |
17 |
18 |
55 |
--------------------------------------------------------------------------------
/docs/src/pages/roadmap.md:
--------------------------------------------------------------------------------
1 | # Roadmap
2 |
3 | I have no timelines for anything. I am slowly chipping away at making components and using them for my own little games. Pull Requests are welcome!
4 |
5 | ## Phaser Components
6 |
7 | - BitmapText
8 | - Blitter
9 | - Bob
10 | - Sprite3D
11 | - Video
12 | - Zone
13 | - Rope
14 | - Shader
15 | - Lights
16 | - Mesh
17 | - Quad
18 |
19 | ## Physics
20 |
21 | Matter Physics
22 |
--------------------------------------------------------------------------------
/docs/src/static/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/docs/src/static/favicon.png
--------------------------------------------------------------------------------
/docs/src/static/images/adventurer-spritesheet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/docs/src/static/images/adventurer-spritesheet.png
--------------------------------------------------------------------------------
/docs/src/static/images/ball.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/docs/src/static/images/ball.png
--------------------------------------------------------------------------------
/docs/src/static/images/mushroom.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/docs/src/static/images/mushroom.png
--------------------------------------------------------------------------------
/docs/src/static/images/mushroom2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/docs/src/static/images/mushroom2.png
--------------------------------------------------------------------------------
/docs/src/static/images/starfield.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/docs/src/static/images/starfield.png
--------------------------------------------------------------------------------
/docs/src/static/images/tile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/docs/src/static/images/tile.png
--------------------------------------------------------------------------------
/docs/src/static/images/tiled-create-tileset.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/docs/src/static/images/tiled-create-tileset.png
--------------------------------------------------------------------------------
/docs/src/static/images/tiled-new-map-0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/docs/src/static/images/tiled-new-map-0.png
--------------------------------------------------------------------------------
/docs/src/static/images/tiled-new-map-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/docs/src/static/images/tiled-new-map-1.png
--------------------------------------------------------------------------------
/docs/src/static/images/tiled-object-layer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/docs/src/static/images/tiled-object-layer.png
--------------------------------------------------------------------------------
/docs/src/static/tilemaps/castle-tileset.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/docs/src/static/tilemaps/castle-tileset.png
--------------------------------------------------------------------------------
/docs/src/theme.css:
--------------------------------------------------------------------------------
1 | /* Theme tunning: for full list ov variables visit the https://alexxnb.github.io/svelte-docs/theming */
2 |
3 | :root {
4 | --hl-keyword: #3ca7b9;
5 | }
6 |
--------------------------------------------------------------------------------
/docs/svelte-docs.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | // if you will serve docs in subdirictory use '/subdir/'
3 | basepath: '/',
4 |
5 | // theme
6 | theme: './theme',
7 |
8 | title: {
9 | // constant part of page title
10 | main: 'svelte-phaser',
11 |
12 | // use first header's content as a part of page's title
13 | // it looks for `# Header` and `## Header` on the current page
14 | header: true,
15 | },
16 |
17 | // URL to your favicon
18 | favicon: 'static/favicon.png',
19 |
20 | pathes: {
21 | // directory for files, generated in development mode
22 | dev: '__DOCS__/dev',
23 |
24 | // directory for builted documentaton
25 | build: '__DOCS__/dist',
26 | },
27 |
28 | aliases: {
29 | './Ball.svelte': './src/components/Ball.svelte',
30 | // Virtual packages
31 | // : ,
32 | //
33 | // Ex1: './Button.svelte': './../dist/Button.svelte',
34 | // Ex2: 'mylib': './../dist/index.js', (don't miss `index` and `.js` at the end!)
35 | //
36 | // Then you can use:
37 | // import Button from './Button.svelte';
38 | // import { Input } from 'mylib';
39 | },
40 |
41 | preprocess: [
42 | // preprocessors for Svelte if needed in Examples
43 | // syntax same as for `preprocess` option in `rollup-plugin-svelte`
44 | // Ex: Import preprocessor at top of the config file:
45 | // import {markdown} from 'svelte-preprocess-markdown';
46 | // Then add it here:
47 | // markdown({filetype: 'svelte'}),
48 | ],
49 | }
50 |
--------------------------------------------------------------------------------
/docs/theme/assets/burger.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/theme/assets/fonts/fira-mono-400.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/docs/theme/assets/fonts/fira-mono-400.woff2
--------------------------------------------------------------------------------
/docs/theme/assets/fonts/overpass-300.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/docs/theme/assets/fonts/overpass-300.woff2
--------------------------------------------------------------------------------
/docs/theme/assets/fonts/overpass-400.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/docs/theme/assets/fonts/overpass-400.woff2
--------------------------------------------------------------------------------
/docs/theme/assets/fonts/overpass-600.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/docs/theme/assets/fonts/overpass-600.woff2
--------------------------------------------------------------------------------
/docs/theme/components/Document.svelte:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/docs/theme/components/Example.svelte:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/theme/components/Layout.svelte:
--------------------------------------------------------------------------------
1 |
62 |
63 |
64 |
65 |
66 | {title}
67 |
68 |
69 |
70 |
73 |
74 | {#if layout === 'no_sidebar'}
75 |
76 |
77 |
78 |
79 | {/if}
80 |
81 | {#if layout === 'default'}
82 | {#if $mobile}
83 |
84 |
92 | {/if}
93 |
94 | {#if !$mobile || show_sidebar}
95 |
98 | {/if}
99 |
100 |
101 |
102 |
103 |
104 | {/if}
105 |
--------------------------------------------------------------------------------
/docs/theme/components/Sections.svelte:
--------------------------------------------------------------------------------
1 |
4 |
5 |
--------------------------------------------------------------------------------
/docs/theme/components/Topbar.svelte:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
--------------------------------------------------------------------------------
/docs/theme/info.md:
--------------------------------------------------------------------------------
1 | Theme based on [offical Svelte documentation site](https://svelte.dev/docs).
2 |
3 | _by Alexey Schebelev_
4 |
5 | ## Theme variables
6 |
7 | | Variable | Default | Comment |
8 | | ---------------------- | ---------------------- | --------------------------------- |
9 | | `--font` | "Overpass", sans-serif | |
10 | | `--font-mono` | "Fira Mono", monospace | |
11 | | `--primary` | #ff3e00 | |
12 | | `--secondary` | #676778 | |
13 | | `--dark` | #34343d | |
14 | | `--light` | #c0c0d8 | |
15 | | `--white` | #ffffff | |
16 | | `--code` | #f6fafd | |
17 | | `--text` | --dark | |
18 | | `--text-sidebar` | #d4d4d4 | |
19 | | `--text-sidebar-links` | --white | |
20 | | `--topbar-height` | 50px | |
21 | | `--sidebar-width` | 300px | |
22 | | `--example-border` | --light | Border color of the example block |
23 | | `--props-border` | --light | Colors of the properties block |
24 | | `--props-devider` | --code | |
25 | | `--props-types-bg` | --code | |
26 | | `--props-types-border` | --light | |
27 | | `--props-types-text` | --hl-keyword | |
28 | | `--props-oneof-text` | --hl-string | |
29 | | `--props-default-text` | --light | |
30 | | `--hl-background` | --code | Code highlighting colors |
31 | | `--hl-text` | #505050 | |
32 | | `--hl-comment` | #8da4bc | |
33 | | `--hl-keyword` | #3c87b9 | |
34 | | `--hl-string` | #a18851 | |
35 | | `--hl-number` | #76a562 | |
36 | | `--hl-name` | #c36031 | |
37 | | `--hl-attr` | #a18851 | |
38 | | `--hl-builtin` | #505050 | |
39 |
40 | ## Layouts
41 |
42 | | Name | Description |
43 | | ------------ | --------------------------------------------------- |
44 | | `default` | Layout with topbar, sidebar on the left and content |
45 | | `no_sidebar` | Layout without sidebar |
46 |
--------------------------------------------------------------------------------
/docs/theme/style.css:
--------------------------------------------------------------------------------
1 | @import 'styles/layout.css';
2 | @import 'styles/typography.css';
3 | @import 'styles/fonts.css';
4 | @import 'styles/highlight.css';
5 |
6 | :root {
7 | --font: 'Overpass', sans-serif;
8 | --font-mono: 'Fira Mono', monospace;
9 |
10 | --primary: #ff3e00;
11 | --secondary: #676778;
12 | --dark: #34343d;
13 | --light: #c0c0d8;
14 |
15 | --white: #ffffff;
16 | --code: #f6fafd;
17 |
18 | --text: var(--dark);
19 | --text-sidebar: #d4d4d4;
20 | --text-sidebar-links: var(--white);
21 |
22 | --topbar-height: 50px;
23 | --sidebar-width: 300px;
24 |
25 | --example-border: var(--light);
26 |
27 | --props-border: var(--light);
28 | --props-devider: var(--code);
29 | --props-types-bg: var(--code);
30 | --props-types-border: var(--light);
31 | --props-types-text: var(--hl-keyword);
32 | --props-oneof-text: var(--hl-string);
33 | --props-default-text: var(--light);
34 |
35 | --hl-background: var(--code);
36 | --hl-text: #505050;
37 | --hl-comment: #8da4bc;
38 | --hl-keyword: #3c87b9;
39 | --hl-string: #a18851;
40 | --hl-number: #76a562;
41 | --hl-name: #c36031;
42 | --hl-attr: #a18851;
43 | --hl-builtin: #505050;
44 | }
45 |
46 | article img {
47 | max-height: 600px;
48 | }
49 |
--------------------------------------------------------------------------------
/docs/theme/styles/fonts.css:
--------------------------------------------------------------------------------
1 | /* overpass-300normal */
2 | @font-face {
3 | font-family: 'Overpass';
4 | font-style: normal;
5 | font-weight: 300;
6 | font-display: fallback;
7 | src: local('Overpass Light '), local('Overpass-Light'),
8 | url('assets/fonts/overpass-300.woff2') format('woff2');
9 | }
10 |
11 | /* overpass-400normal */
12 | @font-face {
13 | font-family: 'Overpass';
14 | font-style: normal;
15 | font-weight: 400;
16 | font-display: fallback;
17 | src: local('Overpass Light '), local('Overpass-Light'),
18 | url('assets/fonts/overpass-400.woff2') format('woff2');
19 | }
20 |
21 | /* overpass-600normal */
22 | @font-face {
23 | font-family: 'Overpass';
24 | font-style: normal;
25 | font-weight: 600;
26 | font-display: fallback;
27 | src: local('Overpass Bold '), local('Overpass-Bold'),
28 | url('assets/fonts/overpass-600.woff2') format('woff2');
29 | }
30 |
31 | /* fira-mono-400normal */
32 | @font-face {
33 | font-family: 'Fira Mono';
34 | font-style: normal;
35 | font-weight: 400;
36 | font-display: fallback;
37 | src: local('Fira Mono'), local('Fira-Mono'),
38 | url('assets/fonts/fira-mono-400.woff2') format('woff2');
39 | }
40 |
--------------------------------------------------------------------------------
/docs/theme/styles/highlight.css:
--------------------------------------------------------------------------------
1 | /*
2 | * You can just import theme from the higlight.js package:
3 | * Example: @import 'highlight.js/styles/solarized-light.css'
4 | */
5 |
6 | .hljs {
7 | display: block;
8 | overflow-x: auto;
9 | padding: 0.5em;
10 | background: var(--hl-background);
11 | color: var(--hl-text);
12 | font-family: var(--font-mono);
13 | line-height: 1;
14 | }
15 |
16 | .hljs-comment,
17 | .hljs-quote {
18 | color: var(--hl-comment);
19 | }
20 |
21 | .hljs-keyword,
22 | .hljs-selector-tag,
23 | .hljs-addition {
24 | color: var(--hl-keyword);
25 | }
26 |
27 | .hljs-number {
28 | color: var(--hl-number);
29 | }
30 |
31 | .hljs-string,
32 | .hljs-meta .hljs-meta-string,
33 | .hljs-literal,
34 | .hljs-doctag,
35 | .hljs-regexp {
36 | color: var(--hl-string);
37 | }
38 |
39 | .hljs-title,
40 | .hljs-section,
41 | .hljs-name,
42 | .hljs-selector-id,
43 | .hljs-selector-class {
44 | color: var(--hl-name);
45 | }
46 |
47 | .hljs-attribute,
48 | .hljs-attr,
49 | .hljs-variable,
50 | .hljs-template-variable,
51 | .hljs-class .hljs-title,
52 | .hljs-type {
53 | color: var(--hl-attr);
54 | }
55 |
56 | .hljs-symbol,
57 | .hljs-bullet,
58 | .hljs-subst,
59 | .hljs-meta,
60 | .hljs-meta .hljs-keyword,
61 | .hljs-selector-attr,
62 | .hljs-selector-pseudo,
63 | .hljs-link {
64 | color: var(--hl-string);
65 | }
66 |
67 | .hljs-built_in {
68 | color: var(--hl-builtin);
69 | }
70 |
71 | .hljs-deletion {
72 | color: #dc322f;
73 | }
74 |
75 | .hljs-formula {
76 | background: #eee8d5;
77 | }
78 |
79 | .hljs-emphasis {
80 | font-style: italic;
81 | }
82 |
83 | .hljs-strong {
84 | font-weight: bold;
85 | }
86 |
--------------------------------------------------------------------------------
/docs/theme/styles/typography.css:
--------------------------------------------------------------------------------
1 | body {
2 | color: var(--text);
3 | font-family: 'Overpass', sans-serif;
4 | font-weight: 300;
5 | line-height: 1.6;
6 | }
7 |
8 | strong {
9 | font-weight: 600;
10 | }
11 |
12 | a {
13 | color: rgb(0, 100, 200);
14 | text-decoration: none;
15 | }
16 |
17 | a:hover {
18 | text-decoration: underline;
19 | }
20 |
21 | label {
22 | display: block;
23 | }
24 |
25 | input,
26 | button,
27 | select,
28 | textarea {
29 | font-family: inherit;
30 | font-size: inherit;
31 | padding: 0.4em;
32 | margin: 0 0 0.5em 0;
33 | box-sizing: border-box;
34 | border: 1px solid #ccc;
35 | border-radius: 2px;
36 | }
37 |
38 | input:disabled {
39 | color: #ccc;
40 | }
41 |
42 | input[type='range'] {
43 | height: 0;
44 | }
45 |
46 | button {
47 | color: #333;
48 | background-color: #f4f4f4;
49 | outline: none;
50 | }
51 |
52 | button:active {
53 | background-color: #ddd;
54 | }
55 |
56 | button:focus {
57 | border-color: #666;
58 | }
59 |
60 | code {
61 | font-family: var(--font-mono);
62 | font-size: 0.8rem;
63 | background: var(--code);
64 | border: 1px solid var(--light);
65 | color: var(--secondary);
66 | padding: 0 0.2em;
67 | border-radius: 0.2em;
68 | white-space: nowrap;
69 | }
70 |
71 | pre {
72 | background-color: var(--code);
73 | font-size: 1em;
74 | padding: 1rem;
75 | overflow-x: auto;
76 | border-radius: 0.3em;
77 | margin: 25px;
78 | }
79 |
80 | pre code {
81 | background: none;
82 | border: none;
83 | padding: 0;
84 | white-space: pre;
85 | line-height: 0.8rem;
86 | }
87 |
88 | blockquote {
89 | background-color: var(--code);
90 | padding: 1rem 2rem;
91 | border-left: 3px solid var(--light);
92 | }
93 |
--------------------------------------------------------------------------------
/examples/.gitignore:
--------------------------------------------------------------------------------
1 | .vercel
--------------------------------------------------------------------------------
/examples/breakout/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | public/build
4 |
--------------------------------------------------------------------------------
/examples/breakout/README.md:
--------------------------------------------------------------------------------
1 | Give it a try!
2 |
3 | ```shell
4 | npx degit mattjennings/svelte-phaser/examples/breakout breakout
5 | cd breakout
6 | npm install
7 | npm run dev
8 | ```
9 |
10 | Assets were taken from official [Phaser 3 example](https://phaser.io/examples/v3/view/games/breakout/breakout)
11 |
--------------------------------------------------------------------------------
/examples/breakout/index.js:
--------------------------------------------------------------------------------
1 | import App from './src/App.svelte'
2 |
3 | const app = new App({
4 | target: document.body,
5 | })
6 |
7 | export default app
8 |
--------------------------------------------------------------------------------
/examples/breakout/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "breakout",
3 | "version": "1.0.0",
4 | "devDependencies": {
5 | "@rollup/plugin-commonjs": "^11.0.0",
6 | "@rollup/plugin-node-resolve": "^7.0.0",
7 | "rollup": "^1.20.0",
8 | "rollup-plugin-livereload": "^1.0.0",
9 | "rollup-plugin-svelte": "^5.0.3",
10 | "rollup-plugin-terser": "^5.1.2"
11 | },
12 | "dependencies": {
13 | "svelte": "^3.0.0",
14 | "svelte-phaser": "0.0.6",
15 | "svelte-fragment": "^1.0.1",
16 | "phaser": "^3.23.0",
17 | "sirv-cli": "^0.4.4"
18 | },
19 | "scripts": {
20 | "build": "rollup -c",
21 | "dev": "rollup -c -w",
22 | "start": "sirv public"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/examples/breakout/public/assets/breakout.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/examples/breakout/public/assets/breakout.png
--------------------------------------------------------------------------------
/examples/breakout/public/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/examples/breakout/public/favicon.png
--------------------------------------------------------------------------------
/examples/breakout/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Breakout
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/examples/breakout/rollup.config.js:
--------------------------------------------------------------------------------
1 | import svelte from 'rollup-plugin-svelte'
2 | import resolve from '@rollup/plugin-node-resolve'
3 | import commonjs from '@rollup/plugin-commonjs'
4 | import livereload from 'rollup-plugin-livereload'
5 | import { terser } from 'rollup-plugin-terser'
6 |
7 | const production = !process.env.ROLLUP_WATCH
8 |
9 | export default {
10 | input: './index.js',
11 | output: {
12 | sourcemap: true,
13 | format: 'iife',
14 | name: 'app',
15 | file: 'public/build/bundle.js',
16 | },
17 | plugins: [
18 | svelte({
19 | // enable run-time checks when not in production
20 | dev: !production,
21 | // we'll extract any component CSS out into
22 | // a separate file - better for performance
23 | css: (css) => {
24 | css.write('public/build/bundle.css')
25 | },
26 | }),
27 |
28 | // If you have external dependencies installed from
29 | // npm, you'll most likely need these plugins. In
30 | // some cases you'll need additional configuration -
31 | // consult the documentation for details:
32 | // https://github.com/rollup/plugins/tree/master/packages/commonjs
33 | resolve({
34 | browser: true,
35 | dedupe: ['svelte'],
36 | }),
37 | commonjs(),
38 |
39 | // In dev mode, call `npm run start` once
40 | // the bundle has been generated
41 | !production && serve(),
42 |
43 | // Watch the `public` directory and refresh the
44 | // browser on changes when not in production
45 | !production && livereload('public'),
46 |
47 | // If we're building for production (npm run build
48 | // instead of npm run dev), minify
49 | production && terser(),
50 | ],
51 | watch: {
52 | clearScreen: false,
53 | },
54 | }
55 |
56 | function serve() {
57 | let started = false
58 |
59 | return {
60 | writeBundle() {
61 | if (!started) {
62 | started = true
63 |
64 | require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
65 | stdio: ['ignore', 'inherit', 'inherit'],
66 | shell: true,
67 | })
68 | }
69 | },
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/examples/breakout/src/App.svelte:
--------------------------------------------------------------------------------
1 |
14 |
15 |
23 |
24 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/examples/breakout/src/Ball.svelte:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/examples/breakout/src/Block.svelte:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/examples/breakout/src/Breakout.svelte:
--------------------------------------------------------------------------------
1 |
72 |
73 |
74 |
75 | {#each blocks as block (block.key)}
76 | {
81 | blocks = blocks.filter(b => b !== block)
82 | }} />
83 | {/each}
84 |
--------------------------------------------------------------------------------
/examples/breakout/src/LoadingBar.svelte:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
23 |
28 |
29 |
36 |
37 |
--------------------------------------------------------------------------------
/examples/breakout/src/Paddle.svelte:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/examples/invaders/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | public/build
4 |
--------------------------------------------------------------------------------
/examples/invaders/README.md:
--------------------------------------------------------------------------------
1 | Give it a try!
2 |
3 | ```shell
4 | npx degit mattjennings/svelte-phaser/examples/invaders invaders
5 | cd invaders
6 | npm install
7 | npm run dev
8 | ```
9 |
10 | Assets were taken from official [Phaser 2 example](http://examples.phaser.io/_site/view_full.html?d=games&f=invaders.js&t=invaders)
11 |
--------------------------------------------------------------------------------
/examples/invaders/index.js:
--------------------------------------------------------------------------------
1 | import App from './src/App.svelte'
2 |
3 | const app = new App({
4 | target: document.body,
5 | })
6 |
7 | export default app
8 |
--------------------------------------------------------------------------------
/examples/invaders/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "invaders",
3 | "version": "1.0.0",
4 | "devDependencies": {
5 | "@rollup/plugin-commonjs": "^11.0.0",
6 | "@rollup/plugin-node-resolve": "^7.0.0",
7 | "rollup": "^1.20.0",
8 | "rollup-plugin-livereload": "^1.0.0",
9 | "rollup-plugin-svelte": "^5.0.3",
10 | "rollup-plugin-terser": "^5.1.2"
11 | },
12 | "dependencies": {
13 | "svelte": "^3.0.0",
14 | "svelte-phaser": "0.0.6",
15 | "svelte-fragment": "^1.0.1",
16 | "phaser": "^3.23.0",
17 | "sirv-cli": "^0.4.4"
18 | },
19 | "scripts": {
20 | "build": "rollup -c",
21 | "dev": "rollup -c -w",
22 | "start": "sirv public"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/examples/invaders/public/assets/bullet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/examples/invaders/public/assets/bullet.png
--------------------------------------------------------------------------------
/examples/invaders/public/assets/enemy-bullet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/examples/invaders/public/assets/enemy-bullet.png
--------------------------------------------------------------------------------
/examples/invaders/public/assets/explode.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/examples/invaders/public/assets/explode.png
--------------------------------------------------------------------------------
/examples/invaders/public/assets/invader.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/examples/invaders/public/assets/invader.png
--------------------------------------------------------------------------------
/examples/invaders/public/assets/ship.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/examples/invaders/public/assets/ship.png
--------------------------------------------------------------------------------
/examples/invaders/public/assets/starfield.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/examples/invaders/public/assets/starfield.png
--------------------------------------------------------------------------------
/examples/invaders/public/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/examples/invaders/public/favicon.png
--------------------------------------------------------------------------------
/examples/invaders/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Invaders
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/examples/invaders/rollup.config.js:
--------------------------------------------------------------------------------
1 | import svelte from 'rollup-plugin-svelte'
2 | import resolve from '@rollup/plugin-node-resolve'
3 | import commonjs from '@rollup/plugin-commonjs'
4 | import livereload from 'rollup-plugin-livereload'
5 | import { terser } from 'rollup-plugin-terser'
6 |
7 | const production = !process.env.ROLLUP_WATCH
8 |
9 | export default {
10 | input: './index.js',
11 | output: {
12 | sourcemap: true,
13 | format: 'iife',
14 | name: 'app',
15 | file: 'public/build/bundle.js',
16 | },
17 | plugins: [
18 | svelte({
19 | // enable run-time checks when not in production
20 | dev: !production,
21 | // we'll extract any component CSS out into
22 | // a separate file - better for performance
23 | css: (css) => {
24 | css.write('public/build/bundle.css')
25 | },
26 | }),
27 |
28 | // If you have external dependencies installed from
29 | // npm, you'll most likely need these plugins. In
30 | // some cases you'll need additional configuration -
31 | // consult the documentation for details:
32 | // https://github.com/rollup/plugins/tree/master/packages/commonjs
33 | resolve({
34 | browser: true,
35 | dedupe: ['svelte'],
36 | }),
37 | commonjs(),
38 |
39 | // In dev mode, call `npm run start` once
40 | // the bundle has been generated
41 | !production && serve(),
42 |
43 | // Watch the `public` directory and refresh the
44 | // browser on changes when not in production
45 | !production && livereload('public'),
46 |
47 | // If we're building for production (npm run build
48 | // instead of npm run dev), minify
49 | production && terser(),
50 | ],
51 | watch: {
52 | clearScreen: false,
53 | },
54 | }
55 |
56 | function serve() {
57 | let started = false
58 |
59 | return {
60 | writeBundle() {
61 | if (!started) {
62 | started = true
63 |
64 | require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
65 | stdio: ['ignore', 'inherit', 'inherit'],
66 | shell: true,
67 | })
68 | }
69 | },
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/examples/invaders/src/App.svelte:
--------------------------------------------------------------------------------
1 |
52 |
53 |
61 |
62 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | {#if $lives > 0}
77 |
78 | {/if}
79 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/examples/invaders/src/Background.svelte:
--------------------------------------------------------------------------------
1 |
9 |
10 |
20 |
--------------------------------------------------------------------------------
/examples/invaders/src/Bullet.svelte:
--------------------------------------------------------------------------------
1 |
38 |
39 | {#if destroyed}
40 | onDestroy()} />
44 | {:else}
45 |
46 | {
50 | destroyed = true
51 | destroyedPosition = { x: instance.x, y: instance.y }
52 | }} />
53 |
54 |
55 | {/if}
56 |
--------------------------------------------------------------------------------
/examples/invaders/src/Enemies.svelte:
--------------------------------------------------------------------------------
1 |
94 |
95 | {#each enemies as enemy (enemy.key)}
96 | {
101 | enemies = enemies.filter(e => e !== enemy)
102 | score.update(prev => prev + 100)
103 | }} />
104 | {/each}
105 |
--------------------------------------------------------------------------------
/examples/invaders/src/Enemy.svelte:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/examples/invaders/src/Explosion.svelte:
--------------------------------------------------------------------------------
1 |
8 |
9 |
16 |
--------------------------------------------------------------------------------
/examples/invaders/src/LoadingBar.svelte:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
23 |
28 |
29 |
36 |
37 |
--------------------------------------------------------------------------------
/examples/invaders/src/Player.svelte:
--------------------------------------------------------------------------------
1 |
56 |
57 |
64 | lives.update(prev => prev - 1)} />
68 |
69 |
70 |
--------------------------------------------------------------------------------
/examples/invaders/src/UI.svelte:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
16 | {#if $gameStatus !== 'playing'}
17 |
23 |
24 | {/if}
25 |
--------------------------------------------------------------------------------
/examples/invaders/src/store.js:
--------------------------------------------------------------------------------
1 | import { writable, derived } from 'svelte/store'
2 |
3 | export const score = writable(0)
4 | export const lives = writable(3)
5 |
6 | export const enemiesDefeated = writable(false)
7 |
8 | export const gameStatus = derived(
9 | [lives, enemiesDefeated],
10 | ([$lives, $enemiesDefeated]) => {
11 | if ($lives <= 0) {
12 | return 'gameover'
13 | }
14 |
15 | if ($enemiesDefeated) {
16 | return 'win'
17 | }
18 |
19 | return 'playing'
20 | }
21 | )
22 |
23 | export const reset = () => {
24 | score.set(0)
25 | lives.set(3)
26 | enemiesDefeated.set(false)
27 | }
28 |
--------------------------------------------------------------------------------
/examples/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "svelte-phaser-examples",
3 | "private": true,
4 | "scripts": {
5 | "build": "(cd breakout && yarn build); (cd invaders && yarn build); (cd platforme && yarn build)"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/examples/platformer/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | public/build
4 |
5 | .now
--------------------------------------------------------------------------------
/examples/platformer/README.md:
--------------------------------------------------------------------------------
1 | Give it a try!
2 |
3 | ```shell
4 | npx degit mattjennings/svelte-phaser/examples/platformer platformer
5 | cd platformer
6 | npm install
7 | npm run dev
8 | ```
9 |
10 | Adventurer sprite is from [rvos](https://rvros.itch.io/)
11 |
12 | Tilest from [RottingPixels](https://rottingpixels.itch.io/castle-platformer-tileset-16x16free)
13 |
--------------------------------------------------------------------------------
/examples/platformer/index.js:
--------------------------------------------------------------------------------
1 | import App from './src/App.svelte'
2 |
3 | const app = new App({
4 | target: document.body,
5 | })
6 |
7 | export default app
8 |
--------------------------------------------------------------------------------
/examples/platformer/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "platformer",
3 | "version": "1.0.0",
4 | "devDependencies": {
5 | "@rollup/plugin-commonjs": "^11.0.0",
6 | "@rollup/plugin-node-resolve": "^7.0.0",
7 | "rollup": "^1.20.0",
8 | "rollup-plugin-livereload": "^1.0.0",
9 | "rollup-plugin-svelte": "^5.0.3",
10 | "rollup-plugin-terser": "^5.1.2"
11 | },
12 | "dependencies": {
13 | "svelte": "^3.0.0",
14 | "svelte-phaser": "0.0.6",
15 | "svelte-fragment": "^1.0.1",
16 | "phaser": "^3.23.0",
17 | "sirv-cli": "^0.4.4"
18 | },
19 | "scripts": {
20 | "build": "rollup -c",
21 | "dev": "rollup -c -w",
22 | "start": "sirv public"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/examples/platformer/public/assets/adventurer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/examples/platformer/public/assets/adventurer.png
--------------------------------------------------------------------------------
/examples/platformer/public/assets/castle-tileset.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/examples/platformer/public/assets/castle-tileset.png
--------------------------------------------------------------------------------
/examples/platformer/public/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/examples/platformer/public/favicon.png
--------------------------------------------------------------------------------
/examples/platformer/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Platformer
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/examples/platformer/rollup.config.js:
--------------------------------------------------------------------------------
1 | import svelte from 'rollup-plugin-svelte'
2 | import resolve from '@rollup/plugin-node-resolve'
3 | import commonjs from '@rollup/plugin-commonjs'
4 | import livereload from 'rollup-plugin-livereload'
5 | import { terser } from 'rollup-plugin-terser'
6 |
7 | const production = !process.env.ROLLUP_WATCH
8 |
9 | export default {
10 | input: './index.js',
11 | output: {
12 | sourcemap: true,
13 | format: 'iife',
14 | name: 'app',
15 | file: 'public/build/bundle.js',
16 | },
17 | plugins: [
18 | svelte({
19 | // enable run-time checks when not in production
20 | dev: !production,
21 | // we'll extract any component CSS out into
22 | // a separate file - better for performance
23 | css: (css) => {
24 | css.write('public/build/bundle.css')
25 | },
26 | }),
27 |
28 | // If you have external dependencies installed from
29 | // npm, you'll most likely need these plugins. In
30 | // some cases you'll need additional configuration -
31 | // consult the documentation for details:
32 | // https://github.com/rollup/plugins/tree/master/packages/commonjs
33 | resolve({
34 | browser: true,
35 | dedupe: ['svelte'],
36 | }),
37 | commonjs(),
38 |
39 | // In dev mode, call `npm run start` once
40 | // the bundle has been generated
41 | !production && serve(),
42 |
43 | // Watch the `public` directory and refresh the
44 | // browser on changes when not in production
45 | !production && livereload('public'),
46 |
47 | // If we're building for production (npm run build
48 | // instead of npm run dev), minify
49 | production && terser(),
50 | ],
51 | watch: {
52 | clearScreen: false,
53 | },
54 | }
55 |
56 | function serve() {
57 | let started = false
58 |
59 | return {
60 | writeBundle() {
61 | if (!started) {
62 | started = true
63 |
64 | require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
65 | stdio: ['ignore', 'inherit', 'inherit'],
66 | shell: true,
67 | })
68 | }
69 | },
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/examples/platformer/src/App.svelte:
--------------------------------------------------------------------------------
1 |
66 |
67 |
75 |
76 |
83 |
88 |
89 |
90 |
91 |
92 |
93 |
96 |
101 |
102 |
103 |
104 |
105 |
113 |
114 |
115 |
116 |
117 |
--------------------------------------------------------------------------------
/examples/platformer/src/LoadingBar.svelte:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
23 |
28 |
29 |
36 |
37 |
--------------------------------------------------------------------------------
/examples/platformer/src/Player.svelte:
--------------------------------------------------------------------------------
1 |
73 |
74 |
82 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/examples/vercel.json:
--------------------------------------------------------------------------------
1 | {
2 | "builds": [
3 | {
4 | "src": "/breakout/package.json",
5 | "use": "@now/static-build",
6 | "config": { "distDir": "public" }
7 | },
8 | {
9 | "src": "/invaders/package.json",
10 | "use": "@now/static-build",
11 | "config": { "distDir": "public" }
12 | },
13 | {
14 | "src": "/platformer/package.json",
15 | "use": "@now/static-build",
16 | "config": { "distDir": "public" }
17 | }
18 | ],
19 | "routes": [
20 | {
21 | "src": "^/(.*)",
22 | "dest": "/$1"
23 | }
24 | ]
25 | }
26 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "svelte-phaser-monorepo",
3 | "author": "Matt Jennings",
4 | "license": "MIT",
5 | "private": true,
6 | "scripts": {
7 | "clean:node_modules": "find . -name \"node_modules\" -exec rm -rf '{}' +",
8 | "deploy:site:prod": "(vercel --prod); (cd examples && vercel --prod);",
9 | "deploy:site:staging": "(vercel); (cd examples && vercel)",
10 | "build": "yarn build:docs && yarn build:examples",
11 | "build:docs": "cd docs && yarn build",
12 | "build:examples": "cd examples && yarn build",
13 | "test": "cd packages/svelte-phaser && yarn test",
14 | "lint": "yarn lint:packages && yarn lint:examples && yarn lint:docs",
15 | "lint:packages": "eslint packages --ext .js,.svelte --ignore-pattern node_modules",
16 | "lint:examples": "eslint examples --ext .js,.svelte --ignore-pattern node_modules",
17 | "lint:docs": "eslint docs --ext .js,.svelte --ignore-pattern node_modules"
18 | },
19 | "workspaces": {
20 | "packages": [
21 | "examples/*",
22 | "templates/*",
23 | "packages/*",
24 | "docs"
25 | ],
26 | "nohoist": [
27 | "**/svelte",
28 | "**/@svelte-docs/core",
29 | "**/@svelte-docs/core/**",
30 | "**/@svelte-docs/server",
31 | "**/@svelte-docs/server/**",
32 | "**/@svelte-docs/publisher",
33 | "**/@svelte-docs/publisher/**",
34 | "**/@svelte-docs/themes",
35 | "**/@svelte-docs/themes/**"
36 | ]
37 | },
38 | "resolutions": {
39 | "svelte": "^3.24.0"
40 | },
41 | "devDependencies": {
42 | "eslint": "6.8.0",
43 | "eslint-plugin-svelte3": "^2.7.3",
44 | "eslint-plugin-jest": "^23.11.0",
45 | "phaser": "^3.23.0",
46 | "prettier": "^2.0.5",
47 | "svelte": "^3.24.0"
48 | },
49 | "keywords": [
50 | "svelte",
51 | "phaser"
52 | ]
53 | }
54 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [["@babel/preset-env", { "targets": { "node": "current" } }]]
3 | }
4 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | /dist/
4 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/README.md:
--------------------------------------------------------------------------------
1 | # Documentation
2 |
3 | Check out the [documentation](https://svelte-phaser.com)
4 |
5 | # Getting Started
6 |
7 | ### Creating a new project
8 |
9 | The easiest way to get started is to create a new project using the blank template:
10 |
11 | ```shell
12 | npx degit mattjennings/svelte-phaser/templates/blank my-first-game
13 | cd my-first-game
14 | npm install
15 | npm run dev
16 | ```
17 |
18 | If a blank project is too boring, feel free to look through the [examples](https://github.com/mattjennings/svelte-phaser/tree/master/examples).
19 |
20 | ### Adding to an existing project
21 |
22 | If you have an existing svelte project you can just install `svelte-phaser`:
23 |
24 | ```shell
25 | npm install phaser svelte-phaser
26 | ```
27 |
28 | and then import it:
29 |
30 | ```svelte
31 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | ```
41 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | testRegex: 'src/.*.spec.js',
3 | transform: {
4 | '^.+\\.js$': 'babel-jest',
5 | '^.+\\.svelte$': 'svelte-jester',
6 | },
7 | moduleFileExtensions: ['js'],
8 | setupFiles: ['./src/test-utils/setup.js'],
9 | testEnvironmentOptions: {
10 | runScripts: 'dangerously',
11 | resources: 'usable',
12 | pretendToBeVisual: true,
13 | },
14 | }
15 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "svelte-phaser",
3 | "version": "0.0.6",
4 | "description": "Create Phaser 3 games with Svelte 3",
5 | "repository": "https://github.com/mattjennings/svelte-phaser",
6 | "svelte": "src/index.mjs",
7 | "main": "src/index.mjs",
8 | "scripts": {
9 | "publish:prod": "yarn publish --tag latest",
10 | "publish:next": "yarn publish --tag next",
11 | "prepublishOnly": "yarn test",
12 | "test": "NODE_ENV=test jest",
13 | "test:watch": "yarn test -- --watch"
14 | },
15 | "devDependencies": {
16 | "@babel/preset-env": "^7.9.6",
17 | "@testing-library/jest-dom": "^5.7.0",
18 | "@testing-library/svelte": "^3.0.0",
19 | "babel-jest": "^26.0.1",
20 | "canvas": "^2.6.1",
21 | "datauri": "^3.0.0",
22 | "jest": "^26.0.1",
23 | "jsdom": "^16.2.2",
24 | "svelte": "^3.0.0",
25 | "svelte-jester": "^1.0.5"
26 | },
27 | "keywords": [
28 | "svelte"
29 | ],
30 | "files": [
31 | "src",
32 | "dist"
33 | ]
34 | }
35 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/Arc.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { tick, getContext } from 'svelte'
3 | import Arc from './Arc.svelte'
4 | import { createGame } from './test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | beforeAll(async () => {
15 | const setup = await createGame()
16 |
17 | game = setup.game
18 | scene = setup.scene
19 | getContext.mockImplementation((name) => {
20 | switch (name) {
21 | case 'phaser/scene':
22 | return scene
23 | case 'phaser/game':
24 | return game
25 | }
26 | })
27 | })
28 |
29 | test('arc props', async () => {
30 | const {
31 | component: { instance, $set },
32 | } = render(Arc, {
33 | radius: 5,
34 | startAngle: 20,
35 | endAngle: 30,
36 | anticlockwise: true,
37 | })
38 |
39 | // test constructor
40 | expect(instance.radius).toEqual(5)
41 | expect(instance._startAngle).toEqual(20)
42 | expect(instance._endAngle).toEqual(30)
43 | expect(instance._anticlockwise).toEqual(true)
44 |
45 | $set({
46 | radius: 10,
47 | startAngle: 30,
48 | endAngle: 40,
49 | anticlockwise: false,
50 | })
51 | await tick()
52 |
53 | // test reactive statements
54 | expect(instance.radius).toEqual(10)
55 | expect(instance._startAngle).toEqual(30)
56 | expect(instance._endAngle).toEqual(40)
57 | expect(instance._anticlockwise).toEqual(false)
58 | })
59 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/ArcadeCollider.svelte:
--------------------------------------------------------------------------------
1 |
64 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/GameObject.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { getContext, tick } from 'svelte'
3 | import GameObject from './GameObject.svelte'
4 | import { createGame } from './test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | let instance
15 |
16 | beforeAll(async () => {
17 | const setup = await createGame()
18 |
19 | game = setup.game
20 | scene = setup.scene
21 |
22 | getContext.mockImplementation((name) => {
23 | switch (name) {
24 | case 'phaser/scene':
25 | return scene
26 | case 'phaser/game':
27 | return game
28 | case 'phaser/game-object':
29 | return instance
30 | }
31 | })
32 | })
33 |
34 | beforeEach(() => {
35 | instance = scene.add.text(0, 0, 'hello')
36 | })
37 |
38 | afterEach(() => {
39 | instance.destroy()
40 | })
41 |
42 | test('active', async () => {
43 | render(GameObject, {
44 | instance,
45 | active: false,
46 | })
47 |
48 | expect(instance.active).toEqual(false)
49 | })
50 |
51 | test('draggable', async () => {
52 | const {
53 | component: { $set },
54 | } = render(GameObject, {
55 | instance,
56 | interactive: { shape: new Phaser.Geom.Rectangle(0, 0, 10, 10) },
57 | })
58 |
59 | jest.spyOn(scene.input, 'setDraggable')
60 | $set({ draggable: true })
61 | await tick()
62 |
63 | expect(scene.input.setDraggable).toHaveBeenCalledWith(instance, true)
64 | $set({ draggable: false })
65 | await tick()
66 |
67 | expect(scene.input.setDraggable).toHaveBeenCalledWith(instance, false)
68 | })
69 |
70 | test('name', async () => {
71 | render(GameObject, {
72 | instance,
73 | name: 'bob',
74 | })
75 |
76 | expect(instance.name).toEqual('bob')
77 | })
78 |
79 | test('renderFlags', async () => {
80 | render(GameObject, {
81 | instance,
82 | renderFlags: 1,
83 | })
84 |
85 | expect(instance.renderFlags).toEqual(1)
86 | })
87 |
88 | test('tabIndex', async () => {
89 | render(GameObject, {
90 | instance,
91 | tabIndex: 1,
92 | })
93 |
94 | expect(instance.tabIndex).toEqual(1)
95 | })
96 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/Grid.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { tick, getContext } from 'svelte'
3 | import Grid from './Grid.svelte'
4 | import { createGame } from './test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | beforeAll(async () => {
15 | const setup = await createGame()
16 |
17 | game = setup.game
18 | scene = setup.scene
19 | getContext.mockImplementation((name) => {
20 | switch (name) {
21 | case 'phaser/scene':
22 | return scene
23 | case 'phaser/game':
24 | return game
25 | }
26 | })
27 | })
28 |
29 | test('outline props', () => {
30 | const {
31 | component: { instance },
32 | } = render(Grid, {
33 | outlineFillColor: 0xff,
34 | outlineFillAlpha: 6,
35 | })
36 |
37 | expect(instance.outlineFillColor).toEqual(0xff)
38 | expect(instance.outlineFillAlpha).toEqual(6)
39 | })
40 |
41 | test('cell props', async () => {
42 | const {
43 | component: { instance, $set },
44 | } = render(Grid, {
45 | cellWidth: 10,
46 | cellHeight: 20,
47 | })
48 |
49 | expect(instance.cellWidth).toEqual(10)
50 | expect(instance.cellHeight).toEqual(20)
51 |
52 | $set({ cellWidth: 1, cellHeight: 2 })
53 | await tick()
54 | expect(instance.cellWidth).toEqual(1)
55 | expect(instance.cellHeight).toEqual(2)
56 | })
57 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/IsoBox.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { tick, getContext } from 'svelte'
3 | import IsoBox from './IsoBox.svelte'
4 | import { createGame } from './test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | beforeAll(async () => {
15 | const setup = await createGame()
16 |
17 | game = setup.game
18 | scene = setup.scene
19 | getContext.mockImplementation((name) => {
20 | switch (name) {
21 | case 'phaser/scene':
22 | return scene
23 | case 'phaser/game':
24 | return game
25 | }
26 | })
27 | })
28 |
29 | test('fill props', () => {
30 | const {
31 | component: { instance },
32 | } = render(IsoBox, {
33 | fillTop: 1,
34 | fillLeft: 2,
35 | fillRight: 3,
36 | })
37 |
38 | expect(instance.fillTop).toEqual(1)
39 | expect(instance.fillLeft).toEqual(2)
40 | expect(instance.fillRight).toEqual(3)
41 | })
42 |
43 | test('show props', async () => {
44 | const {
45 | component: { instance, $set },
46 | } = render(IsoBox, {
47 | showTop: false,
48 | showLeft: false,
49 | showRight: false,
50 | })
51 |
52 | expect(instance.showTop).toEqual(false)
53 | expect(instance.showLeft).toEqual(false)
54 | expect(instance.showRight).toEqual(false)
55 |
56 | $set({ showTop: true, showLeft: true, showRight: true })
57 | await tick()
58 |
59 | expect(instance.showTop).toEqual(true)
60 | expect(instance.showLeft).toEqual(true)
61 | expect(instance.showRight).toEqual(true)
62 | })
63 |
64 | test('projection prop', () => {
65 | const {
66 | component: { instance },
67 | } = render(IsoBox, {
68 | projection: 10,
69 | })
70 |
71 | expect(instance.projection).toEqual(10)
72 | })
73 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/IsoTriangle.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { tick, getContext } from 'svelte'
3 | import IsoTriangle from './IsoTriangle.svelte'
4 | import { createGame } from './test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | beforeAll(async () => {
15 | const setup = await createGame()
16 |
17 | game = setup.game
18 | scene = setup.scene
19 | getContext.mockImplementation((name) => {
20 | switch (name) {
21 | case 'phaser/scene':
22 | return scene
23 | case 'phaser/game':
24 | return game
25 | }
26 | })
27 | })
28 |
29 | test('fill props', () => {
30 | const {
31 | component: { instance },
32 | } = render(IsoTriangle, {
33 | fillTop: 1,
34 | fillLeft: 2,
35 | fillRight: 3,
36 | })
37 |
38 | expect(instance.fillTop).toEqual(1)
39 | expect(instance.fillLeft).toEqual(2)
40 | expect(instance.fillRight).toEqual(3)
41 | })
42 |
43 | test('show props', async () => {
44 | const {
45 | component: { instance, $set },
46 | } = render(IsoTriangle, {
47 | showTop: false,
48 | showLeft: false,
49 | showRight: false,
50 | })
51 |
52 | expect(instance.showTop).toEqual(false)
53 | expect(instance.showLeft).toEqual(false)
54 | expect(instance.showRight).toEqual(false)
55 |
56 | $set({ showTop: true, showLeft: true, showRight: true })
57 | await tick()
58 |
59 | expect(instance.showTop).toEqual(true)
60 | expect(instance.showLeft).toEqual(true)
61 | expect(instance.showRight).toEqual(true)
62 | })
63 |
64 | test('projection prop', () => {
65 | const {
66 | component: { instance },
67 | } = render(IsoTriangle, {
68 | projection: 10,
69 | })
70 |
71 | expect(instance.projection).toEqual(10)
72 | })
73 | test('reversed prop', async () => {
74 | const {
75 | component: { instance, $set },
76 | } = render(IsoTriangle, {
77 | reversed: true,
78 | })
79 |
80 | expect(instance.isReversed).toEqual(true)
81 |
82 | $set({ reversed: false })
83 | await tick()
84 |
85 | expect(instance.isReversed).toEqual(false)
86 | })
87 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/Line.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { tick, getContext } from 'svelte'
3 | import Line from './Line.svelte'
4 | import { createGame } from './test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | beforeAll(async () => {
15 | const setup = await createGame()
16 |
17 | game = setup.game
18 | scene = setup.scene
19 | getContext.mockImplementation((name) => {
20 | switch (name) {
21 | case 'phaser/scene':
22 | return scene
23 | case 'phaser/game':
24 | return game
25 | }
26 | })
27 | })
28 |
29 | const commonProps = {
30 | x1: 0,
31 | y1: 0,
32 | x2: 10,
33 | y2: 10,
34 | }
35 |
36 | test('line props', async () => {
37 | const {
38 | component: { instance, $set },
39 | } = render(Line, {
40 | ...commonProps,
41 | x1: 10,
42 | y1: 20,
43 | x2: 100,
44 | y2: 200,
45 | })
46 |
47 | expect(instance.geom.x1).toEqual(10)
48 | expect(instance.geom.y1).toEqual(20)
49 | expect(instance.geom.x2).toEqual(100)
50 | expect(instance.geom.y2).toEqual(200)
51 |
52 | $set({
53 | x1: 20,
54 | y1: 30,
55 | x2: 200,
56 | y2: 300,
57 | })
58 | await tick()
59 |
60 | expect(instance.geom.x1).toEqual(20)
61 | expect(instance.geom.y1).toEqual(30)
62 | expect(instance.geom.x2).toEqual(200)
63 | expect(instance.geom.y2).toEqual(300)
64 | })
65 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/ObjectLayer.svelte:
--------------------------------------------------------------------------------
1 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/Polygon.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { tick, getContext } from 'svelte'
3 | import Polygon from './Polygon.svelte'
4 | import { createGame } from './test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | beforeAll(async () => {
15 | const setup = await createGame()
16 |
17 | game = setup.game
18 | scene = setup.scene
19 | getContext.mockImplementation((name) => {
20 | switch (name) {
21 | case 'phaser/scene':
22 | return scene
23 | case 'phaser/game':
24 | return game
25 | }
26 | })
27 | })
28 |
29 | const commonProps = {
30 | points: [
31 | {
32 | x: 0,
33 | y: 0,
34 | },
35 | {
36 | x: 10,
37 | y: 10,
38 | },
39 | ],
40 | }
41 |
42 | test('points', () => {
43 | const points = [
44 | {
45 | x: 10,
46 | y: 10,
47 | },
48 | {
49 | x: 20,
50 | y: 20,
51 | },
52 | ]
53 | const {
54 | component: { instance },
55 | } = render(Polygon, {
56 | points,
57 | })
58 |
59 | expect(instance.geom.points).toEqual(points)
60 | })
61 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/Shape.spec.js:
--------------------------------------------------------------------------------
1 | import Phaser from 'phaser'
2 | import { render } from '@testing-library/svelte'
3 | import { tick, getContext } from 'svelte'
4 | import Shape from './Shape.svelte'
5 | import { createGame } from './test-utils'
6 |
7 | jest.mock('svelte', () => ({
8 | ...jest.requireActual('svelte'),
9 | getContext: jest.fn(),
10 | }))
11 |
12 | let scene
13 | let game
14 |
15 | beforeAll(async () => {
16 | const setup = await createGame()
17 |
18 | game = setup.game
19 | scene = setup.scene
20 | getContext.mockImplementation((name) => {
21 | switch (name) {
22 | case 'phaser/scene':
23 | return scene
24 | case 'phaser/game':
25 | return game
26 | }
27 | })
28 | })
29 |
30 | test('stroke and fill', () => {
31 | const {
32 | component: { instance },
33 | } = render(Shape, {
34 | fillAlpha: 0.5,
35 | fillColor: 2,
36 | strokeAlpha: 3,
37 | strokeColor: 4,
38 | strokeWidth: 5,
39 | })
40 |
41 | expect(instance.fillAlpha).toEqual(0.5)
42 | expect(instance.fillColor).toEqual(2)
43 | expect(instance.strokeAlpha).toEqual(3)
44 | expect(instance.strokeColor).toEqual(4)
45 | expect(instance.lineWidth).toEqual(5)
46 | })
47 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/Spawner.svelte:
--------------------------------------------------------------------------------
1 |
24 |
25 | {#each instances as instance (instance.key)}
26 | onDestroy(instance)}
29 | {...instance.props} />
30 | {/each}
31 |
32 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/Sprite.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { tick, getContext } from 'svelte'
3 | import Sprite from './Sprite.svelte'
4 | import { createGame } from './test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | beforeAll(async () => {
15 | const setup = await createGame()
16 |
17 | game = setup.game
18 | scene = setup.scene
19 | getContext.mockImplementation((name) => {
20 | switch (name) {
21 | case 'phaser/scene':
22 | return scene
23 | case 'phaser/game':
24 | return game
25 | }
26 | })
27 | })
28 |
29 | test('animation props', async () => {
30 | const {
31 | component: { instance, $set },
32 | } = render(Sprite, {
33 | delay: 2,
34 | duration: 10,
35 | forward: false,
36 | isPlaying: false,
37 | msPerFrame: 100,
38 | skipMissedFrames: false,
39 | repeat: 5,
40 | repeatDelay: 10,
41 | timeScale: 10,
42 | yoyo: true,
43 | })
44 |
45 | expect(instance.anims.getDelay()).toEqual(2)
46 | expect(instance.anims.duration).toEqual(10)
47 | expect(instance.anims.forward).toEqual(false)
48 | expect(instance.anims.isPlaying).toEqual(false)
49 | expect(instance.anims.msPerFrame).toEqual(100)
50 | expect(instance.anims.skipMissedFrames).toEqual(false)
51 | expect(instance.anims.getRepeat()).toEqual(5)
52 | expect(instance.anims.getRepeatDelay()).toEqual(10)
53 | expect(instance.anims.getTimeScale()).toEqual(10)
54 | expect(instance.anims.getYoyo()).toEqual(true)
55 |
56 | // animation prop
57 | jest.spyOn(instance.anims, 'play')
58 | $set({ animation: 'run' })
59 | await tick()
60 | expect(instance.anims.play).toHaveBeenCalledWith('run', true)
61 | })
62 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/Star.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { tick, getContext } from 'svelte'
3 | import Star from './Star.svelte'
4 | import { createGame } from './test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | beforeAll(async () => {
15 | const setup = await createGame()
16 |
17 | game = setup.game
18 | scene = setup.scene
19 | getContext.mockImplementation((name) => {
20 | switch (name) {
21 | case 'phaser/scene':
22 | return scene
23 | case 'phaser/game':
24 | return game
25 | }
26 | })
27 | })
28 |
29 | const commonProps = {
30 | points: [
31 | {
32 | x: 0,
33 | y: 0,
34 | },
35 | {
36 | x: 10,
37 | y: 10,
38 | },
39 | ],
40 | }
41 |
42 | test('points', () => {
43 | const {
44 | component: { instance },
45 | } = render(Star, {
46 | points: 10,
47 | })
48 |
49 | expect(instance._points).toEqual(10)
50 | })
51 | test('radius', () => {
52 | const {
53 | component: { instance },
54 | } = render(Star, {
55 | innerRadius: 10,
56 | outerRadius: 20,
57 | })
58 |
59 | expect(instance._innerRadius).toEqual(10)
60 | expect(instance._outerRadius).toEqual(20)
61 | })
62 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/Text.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { tick, getContext } from 'svelte'
3 | import Text from './Text.svelte'
4 | import { createGame } from './test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | beforeAll(async () => {
15 | const setup = await createGame()
16 |
17 | game = setup.game
18 | scene = setup.scene
19 | getContext.mockImplementation((name) => {
20 | switch (name) {
21 | case 'phaser/scene':
22 | return scene
23 | case 'phaser/game':
24 | return game
25 | }
26 | })
27 | })
28 |
29 | test('style props', async () => {
30 | const {
31 | component: { instance },
32 | } = render(Text, {
33 | text: 'test',
34 | color: 'white',
35 | backgroundColor: 'green',
36 | fixedHeight: 20,
37 | fixedWidth: 30,
38 | fontFamily: 'Arial',
39 | fontSize: 10,
40 | fontStyle: 'italic',
41 | rtl: true,
42 | shadow: {
43 | x: 1,
44 | y: 2,
45 | color: 'blue',
46 | blur: 3,
47 | stroke: 4,
48 | fill: 'red',
49 | },
50 | wordWrap: 100,
51 | useAdvancedWordWrap: true,
52 | })
53 |
54 | expect(instance.style.color).toEqual('white')
55 | expect(instance.style.backgroundColor).toEqual('green')
56 | expect(instance.style.fixedHeight).toEqual(20)
57 | expect(instance.style.fixedWidth).toEqual(30)
58 | expect(instance.style.fontFamily).toEqual('Arial')
59 | expect(instance.style.fontSize).toEqual('10px')
60 | expect(instance.style.fontStyle).toEqual('italic')
61 | expect(instance.style.rtl).toEqual(true)
62 | expect(instance.style.shadowOffsetX).toEqual(1)
63 | expect(instance.style.shadowOffsetY).toEqual(2)
64 | expect(instance.style.shadowColor).toEqual('blue')
65 | expect(instance.style.shadowBlur).toEqual(3)
66 | expect(instance.style.shadowStroke).toEqual(4)
67 | expect(instance.style.shadowFill).toEqual('red')
68 | expect(instance.style.wordWrapWidth).toEqual(100)
69 | expect(instance.style.wordWrapUseAdvanced).toEqual(true)
70 | })
71 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/TileSprite.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { tick, getContext } from 'svelte'
3 | import TileSprite from './TileSprite.svelte'
4 | import { createGame } from './test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | beforeAll(async () => {
15 | const setup = await createGame()
16 |
17 | game = setup.game
18 | scene = setup.scene
19 | getContext.mockImplementation((name) => {
20 | switch (name) {
21 | case 'phaser/scene':
22 | return scene
23 | case 'phaser/game':
24 | return game
25 | }
26 | })
27 | })
28 |
29 | test('tile props', async () => {
30 | const {
31 | component: { instance },
32 | } = render(TileSprite, {
33 | tilePositionX: 10,
34 | tilePositionY: 20,
35 | tileScaleX: 1,
36 | tileScaleY: 2,
37 | })
38 |
39 | expect(instance.tilePositionX).toEqual(10)
40 | expect(instance.tilePositionY).toEqual(20)
41 | expect(instance.tileScaleX).toEqual(1)
42 | expect(instance.tileScaleY).toEqual(2)
43 | })
44 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/Tilemap.svelte:
--------------------------------------------------------------------------------
1 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/Triangle.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { tick, getContext } from 'svelte'
3 | import Triangle from './Triangle.svelte'
4 | import { createGame } from './test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | beforeAll(async () => {
15 | const setup = await createGame()
16 |
17 | game = setup.game
18 | scene = setup.scene
19 | getContext.mockImplementation((name) => {
20 | switch (name) {
21 | case 'phaser/scene':
22 | return scene
23 | case 'phaser/game':
24 | return game
25 | }
26 | })
27 | })
28 |
29 | test('points', () => {
30 | const {
31 | component: { instance },
32 | } = render(Triangle, {
33 | x1: 1,
34 | y1: 2,
35 | x2: 3,
36 | y2: 4,
37 | x3: 5,
38 | y3: 6,
39 | })
40 |
41 | expect(instance.geom.x1).toEqual(1)
42 | expect(instance.geom.y1).toEqual(2)
43 | expect(instance.geom.x2).toEqual(3)
44 | expect(instance.geom.y2).toEqual(4)
45 | expect(instance.geom.x3).toEqual(5)
46 | expect(instance.geom.y3).toEqual(6)
47 | })
48 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/getCamera.js:
--------------------------------------------------------------------------------
1 | import { getContext } from 'svelte'
2 |
3 | export function getCamera() {
4 | return getContext('phaser/camera')
5 | }
6 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/getContainer.js:
--------------------------------------------------------------------------------
1 | import { getContext } from 'svelte'
2 |
3 | export function getContainer() {
4 | return getContext('phaser/container')
5 | }
6 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/getGame.js:
--------------------------------------------------------------------------------
1 | import { getContext } from 'svelte'
2 |
3 | export function getGame() {
4 | return getContext('phaser/game')
5 | }
6 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/getGameObject.js:
--------------------------------------------------------------------------------
1 | import { getContext } from 'svelte'
2 |
3 | export function getGameObject() {
4 | return getContext('phaser/game-object')
5 | }
6 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/getScene.js:
--------------------------------------------------------------------------------
1 | import { getContext } from 'svelte'
2 |
3 | export function getScene() {
4 | return getContext('phaser/scene')
5 | }
6 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/getSpawner.js:
--------------------------------------------------------------------------------
1 | import { getContext } from 'svelte'
2 |
3 | export function getSpawner() {
4 | return getContext('phaser/spawner')
5 | }
6 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/getTilemap.js:
--------------------------------------------------------------------------------
1 | import { getContext } from 'svelte'
2 |
3 | export function getTilemap() {
4 | return getContext('phaser/tilemap')
5 | }
6 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/index.mjs:
--------------------------------------------------------------------------------
1 | export { default as Arc } from './Arc.svelte'
2 | export { default as ArcadeCollider } from './ArcadeCollider.svelte'
3 | export { default as ArcadePhysics } from './ArcadePhysics.svelte'
4 | export { default as Camera } from './Camera.svelte'
5 | export { default as Container } from './Container.svelte'
6 | export { default as Curve } from './Curve.svelte'
7 | export { default as Ellipse } from './Ellipse.svelte'
8 | export { default as Game } from './Game.svelte'
9 | export { default as Grid } from './Grid.svelte'
10 | export { default as IsoBox } from './IsoBox.svelte'
11 | export { default as IsoTriangle } from './IsoTriangle.svelte'
12 | export { default as Line } from './Line.svelte'
13 | export { default as ObjectLayer } from './ObjectLayer.svelte'
14 | export { default as Polygon } from './Polygon.svelte'
15 | export { default as Rectangle } from './Rectangle.svelte'
16 | export { default as Scene } from './Scene.svelte'
17 | export { default as Spawner } from './Spawner.svelte'
18 | export { default as Sprite } from './Sprite.svelte'
19 | export { default as Star } from './Star.svelte'
20 | export { default as Text } from './Text.svelte'
21 | export { default as TileLayer } from './TileLayer.svelte'
22 | export { default as Tilemap } from './Tilemap.svelte'
23 | export { default as TileSprite } from './TileSprite.svelte'
24 | export { default as Triangle } from './Triangle.svelte'
25 |
26 | export * from './getCamera'
27 | export * from './getContainer'
28 | export * from './getGame'
29 | export * from './getGameObject'
30 | export * from './getScene'
31 | export * from './getSpawner'
32 | export * from './getTilemap'
33 | export * from './onArcadePhysicsEvent'
34 | export * from './onGameEvent'
35 | export * from './onInputEvent'
36 | export * from './onSceneEvent'
37 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/onArcadePhysicsEvent.js:
--------------------------------------------------------------------------------
1 | import { onMount } from 'svelte'
2 | import { getScene } from './getScene'
3 |
4 | export function onArcadePhysicsEvent(event, callback) {
5 | const scene = getScene()
6 |
7 | onMount(() => {
8 | scene.physics.world.on(event, callback)
9 |
10 | return () => scene.physics.world.off(event, callback)
11 | })
12 | }
13 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/onGameEvent.js:
--------------------------------------------------------------------------------
1 | import { getContext, onMount } from 'svelte'
2 |
3 | export function onGameEvent(event, callback) {
4 | const game = getContext('phaser/game')
5 |
6 | onMount(() => {
7 | game.events.on(event, callback)
8 |
9 | return () => game.events.off(event, callback)
10 | })
11 | }
12 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/onInputEvent.js:
--------------------------------------------------------------------------------
1 | import { getContext, onMount } from 'svelte'
2 | import { getScene } from './getScene.js'
3 |
4 | export function onInputEvent(event, callback) {
5 | const scene = getScene()
6 |
7 | onMount(() => {
8 | scene.input.on(event, callback)
9 |
10 | return () => scene.input.off(event, callback)
11 | })
12 | }
13 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/onSceneEvent.js:
--------------------------------------------------------------------------------
1 | import { getContext, onMount } from 'svelte'
2 | import { getScene } from './getScene.js'
3 |
4 | export function onSceneEvent(event, callback) {
5 | const scene = getScene()
6 |
7 | onMount(() => {
8 | scene.events.on(event, callback)
9 |
10 | return () => scene.events.off(event, callback)
11 | })
12 | }
13 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Alpha.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { getContext } from 'svelte'
3 | import Alpha from './Alpha.svelte'
4 | import { createGame } from '../test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | let instance
15 |
16 | beforeAll(async () => {
17 | const setup = await createGame()
18 |
19 | game = setup.game
20 | scene = setup.scene
21 |
22 | getContext.mockImplementation((name) => {
23 | switch (name) {
24 | case 'phaser/scene':
25 | return scene
26 | case 'phaser/game':
27 | return game
28 | case 'phaser/game-object':
29 | return instance
30 | }
31 | })
32 | })
33 |
34 | beforeEach(() => {
35 | instance = scene.add.text(0, 0, 'hello')
36 | })
37 |
38 | afterEach(() => {
39 | instance.destroy()
40 | })
41 |
42 | test('alpha', async () => {
43 | render(Alpha, {
44 | alpha: 0.1,
45 | })
46 |
47 | expect(instance.alpha).toEqual(0.1)
48 | expect(instance.alphaBottomLeft).toEqual(0.1)
49 | expect(instance.alphaBottomRight).toEqual(0.1)
50 | expect(instance.alphaTopLeft).toEqual(0.1)
51 | expect(instance.alphaTopRight).toEqual(0.1)
52 | })
53 |
54 | test('alpha corners', async () => {
55 | render(Alpha, {
56 | alphaBottomLeft: 0.1,
57 | alphaBottomRight: 0.2,
58 | alphaTopLeft: 0.3,
59 | alphaTopRight: 0.4,
60 | })
61 |
62 | expect(instance.alphaBottomLeft).toEqual(0.1)
63 | expect(instance.alphaBottomRight).toEqual(0.2)
64 | expect(instance.alphaTopLeft).toEqual(0.3)
65 | expect(instance.alphaTopRight).toEqual(0.4)
66 | })
67 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Alpha.svelte:
--------------------------------------------------------------------------------
1 |
80 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/BlendMode.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { getContext } from 'svelte'
3 | import BlendMode from './BlendMode.svelte'
4 | import { createGame } from '../test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | let instance
15 |
16 | beforeAll(async () => {
17 | const setup = await createGame()
18 |
19 | game = setup.game
20 | scene = setup.scene
21 |
22 | getContext.mockImplementation((name) => {
23 | switch (name) {
24 | case 'phaser/scene':
25 | return scene
26 | case 'phaser/game':
27 | return game
28 | case 'phaser/game-object':
29 | return instance
30 | }
31 | })
32 | })
33 |
34 | beforeEach(() => {
35 | instance = scene.add.text(0, 0, 'hello')
36 | })
37 |
38 | afterEach(() => {
39 | instance.destroy()
40 | })
41 |
42 | test('blendMode', async () => {
43 | render(BlendMode, {
44 | blendMode: Phaser.BlendModes.COLOR,
45 | })
46 |
47 | expect(instance.blendMode).toEqual(Phaser.BlendModes.COLOR)
48 | })
49 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/BlendMode.svelte:
--------------------------------------------------------------------------------
1 |
40 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Crop.svelte:
--------------------------------------------------------------------------------
1 |
22 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Depth.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { getContext } from 'svelte'
3 | import Depth from './Depth.svelte'
4 | import { createGame } from '../test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | let instance
15 |
16 | beforeAll(async () => {
17 | const setup = await createGame()
18 |
19 | game = setup.game
20 | scene = setup.scene
21 |
22 | getContext.mockImplementation((name) => {
23 | switch (name) {
24 | case 'phaser/scene':
25 | return scene
26 | case 'phaser/game':
27 | return game
28 | case 'phaser/game-object':
29 | return instance
30 | }
31 | })
32 | })
33 |
34 | beforeEach(() => {
35 | instance = scene.add.text(0, 0, 'hello')
36 | })
37 |
38 | afterEach(() => {
39 | instance.destroy()
40 | })
41 |
42 | test('depth', async () => {
43 | render(Depth, {
44 | depth: 11,
45 | })
46 |
47 | expect(instance.depth).toEqual(11)
48 | })
49 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Depth.svelte:
--------------------------------------------------------------------------------
1 |
27 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Flip.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { getContext } from 'svelte'
3 | import Flip from './Flip.svelte'
4 | import { createGame } from '../test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | let instance
15 |
16 | beforeAll(async () => {
17 | const setup = await createGame()
18 |
19 | game = setup.game
20 | scene = setup.scene
21 |
22 | getContext.mockImplementation((name) => {
23 | switch (name) {
24 | case 'phaser/scene':
25 | return scene
26 | case 'phaser/game':
27 | return game
28 | case 'phaser/game-object':
29 | return instance
30 | }
31 | })
32 | })
33 |
34 | beforeEach(() => {
35 | instance = scene.add.text(0, 0, 'hello')
36 | })
37 |
38 | afterEach(() => {
39 | instance.destroy()
40 | })
41 |
42 | test('flip', async () => {
43 | render(Flip, {
44 | flipX: true,
45 | flipY: true,
46 | })
47 |
48 | expect(instance.flipX).toEqual(true)
49 | expect(instance.flipY).toEqual(true)
50 | })
51 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Flip.svelte:
--------------------------------------------------------------------------------
1 |
38 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Mask.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { getContext } from 'svelte'
3 | import Mask from './Mask.svelte'
4 | import { createGame } from '../test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | let instance
15 |
16 | beforeAll(async () => {
17 | const setup = await createGame()
18 |
19 | game = setup.game
20 | scene = setup.scene
21 |
22 | getContext.mockImplementation((name) => {
23 | switch (name) {
24 | case 'phaser/scene':
25 | return scene
26 | case 'phaser/game':
27 | return game
28 | case 'phaser/game-object':
29 | return instance
30 | }
31 | })
32 | })
33 |
34 | beforeEach(() => {
35 | instance = scene.add.text(0, 0, 'hello')
36 | })
37 |
38 | afterEach(() => {
39 | instance.destroy()
40 | })
41 |
42 | test('mask', async () => {
43 | const mask = new Phaser.Display.Masks.BitmapMask(scene)
44 |
45 | render(Mask, {
46 | mask,
47 | })
48 |
49 | expect(instance.mask).toEqual(mask)
50 | })
51 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Mask.svelte:
--------------------------------------------------------------------------------
1 |
30 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Origin.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { getContext } from 'svelte'
3 | import Origin from './Origin.svelte'
4 | import { createGame } from '../test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | let instance
15 |
16 | beforeAll(async () => {
17 | const setup = await createGame()
18 |
19 | game = setup.game
20 | scene = setup.scene
21 |
22 | getContext.mockImplementation((name) => {
23 | switch (name) {
24 | case 'phaser/scene':
25 | return scene
26 | case 'phaser/game':
27 | return game
28 | case 'phaser/game-object':
29 | return instance
30 | }
31 | })
32 | })
33 |
34 | beforeEach(() => {
35 | instance = scene.add.text(0, 0, 'hello')
36 | })
37 |
38 | afterEach(() => {
39 | instance.destroy()
40 | })
41 |
42 | test('x/y', async () => {
43 | render(Origin, {
44 | originX: 10,
45 | originY: 20,
46 | })
47 |
48 | expect(instance.originX).toEqual(10)
49 | expect(instance.originY).toEqual(20)
50 | })
51 |
52 | test('display x/y', async () => {
53 | render(Origin, {
54 | displayOriginX: 10,
55 | displayOriginY: 20,
56 | })
57 |
58 | expect(instance.displayOriginX).toEqual(10)
59 | expect(instance.displayOriginY).toEqual(20)
60 | })
61 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Origin.svelte:
--------------------------------------------------------------------------------
1 |
62 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/PathFollower.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { getContext } from 'svelte'
3 | import PathFollower from './PathFollower.svelte'
4 | import { createGame } from '../test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | let instance
15 |
16 | beforeAll(async () => {
17 | const setup = await createGame()
18 |
19 | game = setup.game
20 | scene = setup.scene
21 |
22 | getContext.mockImplementation((name) => {
23 | switch (name) {
24 | case 'phaser/scene':
25 | return scene
26 | case 'phaser/game':
27 | return game
28 | case 'phaser/game-object':
29 | return instance
30 | }
31 | })
32 | })
33 |
34 | beforeEach(() => {
35 | instance = scene.add.sprite(0, 0, 'asdf')
36 | })
37 |
38 | afterEach(() => {
39 | instance.destroy()
40 | })
41 |
42 | test('path', async () => {
43 | const path = new Phaser.Curves.Line({ x: 100, y: 100 }, { x: 200, y: 200 })
44 | render(PathFollower, {
45 | path,
46 | })
47 |
48 | expect(instance.path).toEqual(path)
49 | })
50 |
51 | test('rotateToPath', async () => {
52 | render(PathFollower, {
53 | rotateToPath: true,
54 | })
55 |
56 | expect(instance.rotateToPath).toEqual(true)
57 | })
58 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/PathFollower.svelte:
--------------------------------------------------------------------------------
1 |
50 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Pipeline.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { getContext } from 'svelte'
3 | import Pipeline from './Pipeline.svelte'
4 | import { createGame } from '../test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | let instance
15 |
16 | beforeAll(async () => {
17 | const setup = await createGame()
18 |
19 | game = setup.game
20 | scene = setup.scene
21 |
22 | getContext.mockImplementation((name) => {
23 | switch (name) {
24 | case 'phaser/scene':
25 | return scene
26 | case 'phaser/game':
27 | return game
28 | case 'phaser/game-object':
29 | return instance
30 | }
31 | })
32 | })
33 |
34 | beforeEach(() => {
35 | instance = scene.add.text(0, 0, 'hello')
36 | })
37 |
38 | afterEach(() => {
39 | instance.destroy()
40 | })
41 |
42 | test('pipeline', async () => {
43 | jest.spyOn(instance, 'setPipeline')
44 |
45 | // it relies on a webgl render target to actually do anything,
46 | // so we can't test instance.pipeline, but we can spy on the method
47 | render(Pipeline, {
48 | pipeline: 'bleh',
49 | })
50 |
51 | expect(instance.setPipeline).toHaveBeenCalledWith('bleh')
52 | })
53 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Pipeline.svelte:
--------------------------------------------------------------------------------
1 |
24 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/ScrollFactor.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { getContext } from 'svelte'
3 | import ScrollFactor from './ScrollFactor.svelte'
4 | import { createGame } from '../test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | let instance
15 |
16 | beforeAll(async () => {
17 | const setup = await createGame()
18 |
19 | game = setup.game
20 | scene = setup.scene
21 |
22 | getContext.mockImplementation((name) => {
23 | switch (name) {
24 | case 'phaser/scene':
25 | return scene
26 | case 'phaser/game':
27 | return game
28 | case 'phaser/game-object':
29 | return instance
30 | }
31 | })
32 | })
33 |
34 | beforeEach(() => {
35 | instance = scene.add.text(0, 0, 'hello')
36 | })
37 |
38 | afterEach(() => {
39 | instance.destroy()
40 | })
41 |
42 | test('scrollFactor', async () => {
43 | render(ScrollFactor, {
44 | scrollFactorX: 10,
45 | scrollFactorY: 20,
46 | })
47 |
48 | expect(instance.scrollFactorX).toEqual(10)
49 | expect(instance.scrollFactorY).toEqual(20)
50 | })
51 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/ScrollFactor.svelte:
--------------------------------------------------------------------------------
1 |
53 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Size.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { getContext } from 'svelte'
3 | import Size from './Size.svelte'
4 | import { createGame } from '../test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | let instance
15 |
16 | beforeAll(async () => {
17 | const setup = await createGame()
18 |
19 | game = setup.game
20 | scene = setup.scene
21 |
22 | getContext.mockImplementation((name) => {
23 | switch (name) {
24 | case 'phaser/scene':
25 | return scene
26 | case 'phaser/game':
27 | return game
28 | case 'phaser/game-object':
29 | return instance
30 | }
31 | })
32 | })
33 |
34 | beforeEach(() => {
35 | instance = scene.add.text(0, 0, 'hello')
36 | })
37 |
38 | afterEach(() => {
39 | instance.destroy()
40 | })
41 |
42 | test('width/height', async () => {
43 | render(Size, {
44 | width: 10,
45 | height: 20,
46 | })
47 |
48 | expect(instance.width).toEqual(10)
49 | expect(instance.height).toEqual(20)
50 | })
51 |
52 | test('display width/height', async () => {
53 | render(Size, {
54 | displayWidth: 10,
55 | displayHeight: 20,
56 | })
57 |
58 | expect(instance.displayWidth).toEqual(10)
59 | expect(instance.displayHeight).toEqual(20)
60 | })
61 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Size.svelte:
--------------------------------------------------------------------------------
1 |
58 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Texture.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { getContext, tick } from 'svelte'
3 | import Texture from './Texture.svelte'
4 | import { createGame } from '../test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | let instance
15 |
16 | beforeAll(async () => {
17 | const setup = await createGame()
18 |
19 | game = setup.game
20 | scene = setup.scene
21 |
22 | getContext.mockImplementation((name) => {
23 | switch (name) {
24 | case 'phaser/scene':
25 | return scene
26 | case 'phaser/game':
27 | return game
28 | case 'phaser/game-object':
29 | return instance
30 | }
31 | })
32 | })
33 |
34 | beforeEach(() => {
35 | instance = scene.add.sprite(0, 0)
36 | })
37 |
38 | afterEach(() => {
39 | instance.destroy()
40 | })
41 |
42 | test('texture props', async () => {
43 | const {
44 | component: { $set },
45 | } = render(Texture)
46 |
47 | const setTexture = jest.spyOn(instance, 'setTexture')
48 |
49 | $set({ texture: 't', frame: 'f' })
50 | await tick()
51 |
52 | expect(setTexture).toHaveBeenCalledWith('t', 'f')
53 | })
54 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Texture.svelte:
--------------------------------------------------------------------------------
1 |
39 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Tint.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { getContext, tick } from 'svelte'
3 | import Tint from './Tint.svelte'
4 | import { createGame } from '../test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | let instance
15 |
16 | beforeAll(async () => {
17 | const setup = await createGame()
18 |
19 | game = setup.game
20 | scene = setup.scene
21 |
22 | getContext.mockImplementation((name) => {
23 | switch (name) {
24 | case 'phaser/scene':
25 | return scene
26 | case 'phaser/game':
27 | return game
28 | case 'phaser/game-object':
29 | return instance
30 | }
31 | })
32 | })
33 |
34 | beforeEach(() => {
35 | instance = scene.add.text(0, 0, 'hello')
36 | })
37 |
38 | afterEach(() => {
39 | instance.destroy()
40 | })
41 |
42 | test('tint', async () => {
43 | const {
44 | component: { $set },
45 | } = render(Tint)
46 |
47 | const setTint = jest.spyOn(instance, 'setTint')
48 |
49 | $set({
50 | tintTopLeft: 1,
51 | tintTopRight: 2,
52 | tintBottomLeft: 3,
53 | tintBottomRight: 4,
54 | tintFill: 100,
55 | })
56 | await tick()
57 |
58 | expect(setTint).toHaveBeenCalledWith(1, 2, 3, 4, 100)
59 | })
60 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Tint.svelte:
--------------------------------------------------------------------------------
1 |
76 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Transform.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { getContext, tick } from 'svelte'
3 | import Transform from './Transform.svelte'
4 | import { createGame } from '../test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | let instance
15 |
16 | beforeAll(async () => {
17 | const setup = await createGame()
18 |
19 | game = setup.game
20 | scene = setup.scene
21 |
22 | getContext.mockImplementation((name) => {
23 | switch (name) {
24 | case 'phaser/scene':
25 | return scene
26 | case 'phaser/game':
27 | return game
28 | case 'phaser/game-object':
29 | return instance
30 | }
31 | })
32 | })
33 |
34 | beforeEach(() => {
35 | instance = scene.add.text(0, 0, 'hello')
36 | })
37 |
38 | afterEach(() => {
39 | instance.destroy()
40 | })
41 |
42 | test('transform props', async () => {
43 | const {
44 | component: { $set },
45 | } = render(Transform, {
46 | x: 100,
47 | y: 100,
48 | angle: 100,
49 | scale: 3,
50 | z: 2,
51 | w: 2,
52 | })
53 |
54 | expect(instance.x).toEqual(100)
55 | expect(instance.y).toEqual(100)
56 | expect(instance.angle).toEqual(100)
57 | expect(instance.scale).toEqual(3)
58 | expect(instance.z).toEqual(2)
59 | expect(instance.w).toEqual(2)
60 |
61 | // update scale using scaleX/Y
62 | $set({ scaleX: 2, scaleY: 2 })
63 | await tick()
64 | expect(instance.scale).toEqual(2)
65 | })
66 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Visible.spec.js:
--------------------------------------------------------------------------------
1 | import { render } from '@testing-library/svelte'
2 | import { getContext } from 'svelte'
3 | import Visible from './Visible.svelte'
4 | import { createGame } from '../test-utils'
5 |
6 | jest.mock('svelte', () => ({
7 | ...jest.requireActual('svelte'),
8 | getContext: jest.fn(),
9 | }))
10 |
11 | let scene
12 | let game
13 |
14 | let instance
15 |
16 | beforeAll(async () => {
17 | const setup = await createGame()
18 |
19 | game = setup.game
20 | scene = setup.scene
21 |
22 | getContext.mockImplementation((name) => {
23 | switch (name) {
24 | case 'phaser/scene':
25 | return scene
26 | case 'phaser/game':
27 | return game
28 | case 'phaser/game-object':
29 | return instance
30 | }
31 | })
32 | })
33 |
34 | beforeEach(() => {
35 | instance = scene.add.text(0, 0, 'hello')
36 | })
37 |
38 | afterEach(() => {
39 | instance.destroy()
40 | })
41 |
42 | test('visible', async () => {
43 | render(Visible, {
44 | visible: false,
45 | })
46 |
47 | expect(instance.visible).toEqual(false)
48 | })
49 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser-components/Visible.svelte:
--------------------------------------------------------------------------------
1 |
28 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/phaser.js:
--------------------------------------------------------------------------------
1 | import * as Phaser from 'phaser'
2 |
3 | // "module.exports = Phaser" in phaser is very problematic. Rollup
4 | // works when we use `Phaser.default`, but our tests only work if we use `Phaser`,
5 | // so this keeps both happy at the cost of... this nastiness
6 | export default typeof window !== 'undefined' ? Phaser.default : Phaser
7 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/test-utils/createGame.js:
--------------------------------------------------------------------------------
1 | import Phaser from 'phaser'
2 | import { waitFor } from '@testing-library/svelte'
3 |
4 | export async function createGame(config = {}) {
5 | const onSceneCreate = jest.fn()
6 | const game = new Phaser.Game({
7 | type: Phaser.HEADLESS,
8 | banner: false,
9 | scene: {
10 | create: onSceneCreate,
11 | },
12 |
13 | ...config,
14 | })
15 |
16 | await waitFor(() => {
17 | if (!game.isRunning) {
18 | throw 'Game not ready'
19 | }
20 |
21 | // i can't figure out which event is emitted when a scene is ready (without loader), so this works for now
22 | if (onSceneCreate.mock.calls.length === 0) {
23 | throw 'Scene not ready'
24 | }
25 | })
26 |
27 | return { game, scene: game.scene.scenes[0] }
28 | }
29 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/test-utils/index.js:
--------------------------------------------------------------------------------
1 | export * from './createGame'
2 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/test-utils/setup.js:
--------------------------------------------------------------------------------
1 | const datauri = require('datauri')
2 |
3 | //@ts-ignore
4 | global.focus = jest.fn()
5 |
6 | //@ts-ignore
7 | global.URL.createObjectURL = function (blob) {
8 | if (blob) {
9 | return datauri.format(
10 | blob.type,
11 | blob[Object.getOwnPropertySymbols(blob)[0]]._buffer
12 | ).content
13 | }
14 | }
15 | //@ts-ignore
16 | global.URL.revokeObjectURL = function () {
17 | // Do nothing at the moment
18 | }
19 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/util/addInstance.js:
--------------------------------------------------------------------------------
1 | import { getScene } from '../getScene.js'
2 | import { getContainer } from '../getContainer.js'
3 |
4 | /**
5 | * Adds an instance to the parent scene
6 | */
7 | export function addInstance(self) {
8 | const scene = getScene()
9 | const container = getContainer()
10 |
11 | if (scene) {
12 | scene.add.existing(self)
13 | } else {
14 | throw new Error('Unable to find Scene for instance')
15 | }
16 |
17 | if (container && container !== self) {
18 | container.add(self)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/util/createPhaserEventDispatcher.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Hooks into a phaser event with a svelte dispatcher
3 | *
4 | * @param instance - the game object
5 | * @param dispatch - svelte dispatcher
6 | * @param event - phaser event to hook in to
7 | * @param makeArgs - called with the event parameters from phaser. should return an object to send with the svelte dispatcher
8 | * @returns a function to remove the event listener
9 | */
10 | export const createPhaserEventDispatcher = (
11 | instance,
12 | dispatch,
13 | event,
14 | makeArgs
15 | ) => {
16 | const callback = (...args) => dispatch(event, makeArgs(...args))
17 |
18 | instance.on(event, callback)
19 |
20 | return () => instance.off(event, callback)
21 | }
22 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/util/findGameObjectsByName.js:
--------------------------------------------------------------------------------
1 | export function findGameObjectsByName(scene, name) {
2 | return scene.children.list.filter((child) => child.name === name)
3 | }
4 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/util/index.js:
--------------------------------------------------------------------------------
1 | export * from './createPhaserEventDispatcher'
2 | export * from './removeUndefined'
3 | export * from './addInstance'
4 | export * from './shouldApplyProps'
5 | export * from './toArray'
6 | export * from './findGameObjectsByName'
7 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/util/removeUndefined.js:
--------------------------------------------------------------------------------
1 | export function removeUndefined(object) {
2 | return Object.keys(object).reduce((newObject, key) => {
3 | if (typeof object[key] !== 'undefined') {
4 | return {
5 | ...newObject,
6 | [key]: object[key],
7 | }
8 | }
9 |
10 | return newObject
11 | }, {})
12 | }
13 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/util/shouldApplyProps.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Returns true if any of the values are not undefined
3 | */
4 | export function shouldApplyProps(...args) {
5 | for (const arg of args) {
6 | if (typeof arg !== 'undefined') {
7 | return true
8 | }
9 | }
10 |
11 | return false
12 | }
13 |
--------------------------------------------------------------------------------
/packages/svelte-phaser/src/util/toArray.js:
--------------------------------------------------------------------------------
1 | export function toArray(obj) {
2 | return Array.isArray(obj) ? obj : [obj]
3 | }
4 |
--------------------------------------------------------------------------------
/templates/blank/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | public/bundle.*
4 |
--------------------------------------------------------------------------------
/templates/blank/App.svelte:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/templates/blank/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/templates/blank/README.md
--------------------------------------------------------------------------------
/templates/blank/index.js:
--------------------------------------------------------------------------------
1 | import App from './App.svelte'
2 |
3 | const app = new App({
4 | target: document.body,
5 | })
6 |
7 | export default app
8 |
--------------------------------------------------------------------------------
/templates/blank/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "blank-template",
3 | "version": "1.0.0",
4 | "devDependencies": {
5 | "@rollup/plugin-commonjs": "^11.0.0",
6 | "@rollup/plugin-node-resolve": "^7.0.0",
7 | "rollup": "^1.20.0",
8 | "rollup-plugin-livereload": "^1.0.0",
9 | "rollup-plugin-svelte": "~6.1.1",
10 | "rollup-plugin-terser": "^5.1.2",
11 | "svelte": "^3.0.0",
12 | "svelte-phaser": "latest",
13 | "svelte-fragment": "^1.0.1",
14 | "phaser": "^3.23.0"
15 | },
16 | "dependencies": {
17 | "sirv-cli": "^0.4.4"
18 | },
19 | "scripts": {
20 | "build": "rollup -c",
21 | "dev": "rollup -c -w",
22 | "start": "sirv public"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/templates/blank/public/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/templates/blank/public/favicon.png
--------------------------------------------------------------------------------
/templates/blank/public/global.css:
--------------------------------------------------------------------------------
1 | html,
2 | body {
3 | margin: 0;
4 | position: relative;
5 | width: 100%;
6 | height: 100%;
7 | }
8 |
--------------------------------------------------------------------------------
/templates/blank/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Phaser Game
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/templates/blank/rollup.config.js:
--------------------------------------------------------------------------------
1 | import svelte from 'rollup-plugin-svelte'
2 | import resolve from '@rollup/plugin-node-resolve'
3 | import commonjs from '@rollup/plugin-commonjs'
4 | import livereload from 'rollup-plugin-livereload'
5 | import { terser } from 'rollup-plugin-terser'
6 |
7 | const production = !process.env.ROLLUP_WATCH
8 |
9 | export default {
10 | input: './index.js',
11 | output: {
12 | sourcemap: true,
13 | format: 'iife',
14 | name: 'app',
15 | file: 'public/build/bundle.js',
16 | },
17 | plugins: [
18 | svelte({
19 | // enable run-time checks when not in production
20 | dev: !production,
21 | // we'll extract any component CSS out into
22 | // a separate file - better for performance
23 | css: (css) => {
24 | css.write('public/build/bundle.css')
25 | },
26 | }),
27 |
28 | // If you have external dependencies installed from
29 | // npm, you'll most likely need these plugins. In
30 | // some cases you'll need additional configuration -
31 | // consult the documentation for details:
32 | // https://github.com/rollup/plugins/tree/master/packages/commonjs
33 | resolve({
34 | browser: true,
35 | dedupe: ['svelte'],
36 | }),
37 | commonjs(),
38 |
39 | // In dev mode, call `npm run start` once
40 | // the bundle has been generated
41 | !production && serve(),
42 |
43 | // Watch the `public` directory and refresh the
44 | // browser on changes when not in production
45 | !production && livereload('public'),
46 |
47 | // If we're building for production (npm run build
48 | // instead of npm run dev), minify
49 | production && terser(),
50 | ],
51 | watch: {
52 | clearScreen: false,
53 | },
54 | }
55 |
56 | function serve() {
57 | let started = false
58 |
59 | return {
60 | writeBundle() {
61 | if (!started) {
62 | started = true
63 |
64 | require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
65 | stdio: ['ignore', 'inherit', 'inherit'],
66 | shell: true,
67 | })
68 | }
69 | },
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/templates/snowpack/.gitignore:
--------------------------------------------------------------------------------
1 | .build
2 | build
3 | web_modules
4 | node_modules
--------------------------------------------------------------------------------
/templates/snowpack/LICENSE:
--------------------------------------------------------------------------------
1 | """
2 | MIT License
3 |
4 | Copyright (c) 2020 Fred K. Schott
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | """
24 |
25 | This license applies to parts of the repository originating from the
26 | https://github.com/facebook/create-react-app repository:
27 |
28 | """
29 | MIT License
30 |
31 | Copyright (c) 2013-present, Facebook, Inc.
32 |
33 | Permission is hereby granted, free of charge, to any person obtaining a copy
34 | of this software and associated documentation files (the "Software"), to deal
35 | in the Software without restriction, including without limitation the rights
36 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
37 | copies of the Software, and to permit persons to whom the Software is
38 | furnished to do so, subject to the following conditions:
39 |
40 | The above copyright notice and this permission notice shall be included in all
41 | copies or substantial portions of the Software.
42 |
43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
46 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
47 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
48 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
49 | SOFTWARE.
50 | """
51 |
--------------------------------------------------------------------------------
/templates/snowpack/README.md:
--------------------------------------------------------------------------------
1 | # New Project
2 |
3 | > ✨ Bootstrapped with Create Snowpack App (CSA).
4 |
5 | ## Available Scripts
6 |
7 | ### npm start
8 |
9 | Runs the app in the development mode.
10 | Open http://localhost:8080 to view it in the browser.
11 |
12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console.
14 |
15 | ### npm test
16 |
17 | Launches the test runner in the interactive watch mode.
18 | See the section about running tests for more information.
19 |
20 | ### npm run build
21 |
22 | Builds the app for production to the `build/` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance.
24 |
25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed!
27 |
28 | ### Q: What about Eject?
29 |
30 | No eject needed! Snowpack guarantees zero lock-in, and CSA strives for the same.
31 |
--------------------------------------------------------------------------------
/templates/snowpack/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "snowpack-template",
3 | "version": "1.0.0",
4 | "scripts": {
5 | "prepare": "snowpack",
6 | "start": "snowpack dev",
7 | "build": "snowpack build"
8 | },
9 | "webDependencies": {},
10 | "dependencies": {
11 | "svelte": "^3.0.0",
12 | "svelte-phaser": "latest",
13 | "phaser": "^3.23.0"
14 | },
15 | "devDependencies": {
16 | "@snowpack/app-scripts-svelte": "^1.8.4",
17 | "snowpack": "^2.9.0",
18 | "svelte-fragment": "^1.0.1"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/templates/snowpack/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattjennings/svelte-phaser/6b6464532522efccb5d598ae353f15e160792ecc/templates/snowpack/public/favicon.ico
--------------------------------------------------------------------------------
/templates/snowpack/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
11 | Snowpack App
12 |
13 |
14 |
15 |
16 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/templates/snowpack/public/logo.svg:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/templates/snowpack/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/templates/snowpack/snowpack.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: '@snowpack/app-scripts-svelte',
3 | devOptions: {},
4 | install: ['svelte'],
5 | installOptions: {
6 | rollup: {
7 | dedupe: ['svelte', 'phaser'],
8 | },
9 | },
10 | }
11 |
--------------------------------------------------------------------------------
/templates/snowpack/src/App.svelte:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/templates/snowpack/src/index.js:
--------------------------------------------------------------------------------
1 | import App from './App.svelte'
2 |
3 | var app = new App({
4 | target: document.body,
5 | })
6 |
7 | export default app
8 |
--------------------------------------------------------------------------------