Skip to content

Commit

Permalink
Init 2d Playground and package with PixiJS
Browse files Browse the repository at this point in the history
Also move onFrame logic to FScene
  • Loading branch information
Gugustinette committed May 11, 2024
1 parent b3efc33 commit 9584d07
Show file tree
Hide file tree
Showing 47 changed files with 1,016 additions and 334 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Core package for the Fibbo web game engine, based on [three.js](https://threejs.
npm install
```

- Run the playground
- To develop on the 3D package, run the 3D playground :

```bash
# In one terminal
Expand All @@ -28,6 +28,15 @@ nx dev @fibbojs/playground-3d
nx watch --projects=@fibbojs/3d -- nx build @fibbojs/3d
```

- To develop on the 2D package, run the 2D playground :

```bash
# In one terminal
nx dev @fibbojs/playground-2d
# In another terminal
nx watch --projects=@fibbojs/2d -- nx build @fibbojs/2d
```

You can now open your browser and navigate to `http://localhost:5173/`.

## Documentation
Expand Down
24 changes: 24 additions & 0 deletions apps/playground-2d/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
12 changes: 12 additions & 0 deletions apps/playground-2d/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + TS</title>
</head>
<body>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions apps/playground-2d/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@fibbojs/playground-2d",
"type": "module",
"version": "0.0.1",
"private": true,
"author": "Augustin Mercier <mercier.augustin@outlook.fr>",
"license": "Apache-2.0",
"homepage": "https://fibbojs.github.io/fibbo",
"repository": {
"type": "git",
"url": "git+https://github.com/fibbojs/fibbo.git"
},
"bugs": "https://github.com/fibbojs/fibbo/issues",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"devDependencies": {
"@fibbojs/2d": "^0.0.1",
"@fibbojs/core": "^0.0.1",
"typescript": "^5.2.2",
"vite": "^5.2.0",
"vite-plugin-top-level-await": "^1.4.1",
"vite-plugin-wasm": "^3.3.0"
}
}
11 changes: 11 additions & 0 deletions apps/playground-2d/src/classes/MySquare.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { FSquare } from '@fibbojs/2d'

export default class MySquare extends FSquare {
constructor() {
super()
}

onFrame(delta: number) {
super.onFrame(delta)
}
}
8 changes: 8 additions & 0 deletions apps/playground-2d/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import './style.css'
import { FScene2d } from '@fibbojs/2d'
import MySquare from './classes/MySquare'

const scene = new FScene2d()

const square = new MySquare()
scene.addComponent(square)
96 changes: 96 additions & 0 deletions apps/playground-2d/src/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}

body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}

h1 {
font-size: 3.2em;
line-height: 1.1;
}

#app {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.vanilla:hover {
filter: drop-shadow(0 0 2em #3178c6aa);
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
1 change: 1 addition & 0 deletions apps/playground-2d/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
27 changes: 27 additions & 0 deletions apps/playground-2d/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"target": "ES2020",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"useDefineForClassFields": true,
"module": "ESNext",

/* Bundler mode */
"moduleResolution": "bundler",
"resolveJsonModule": true,
"allowImportingTsExtensions": true,

/* Linting */
"strict": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noEmit": true,
"isolatedModules": true,
"skipLibCheck": true,

/* Enable decorators */
// eslint-disable-next-line jsonc/sort-keys
"experimentalDecorators": true
},
"include": ["src"]
}
10 changes: 10 additions & 0 deletions apps/playground-2d/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'vite'
import wasm from 'vite-plugin-wasm'
import topLevelAwait from 'vite-plugin-top-level-await'

export default defineConfig({
plugins: [
wasm(),
topLevelAwait(),
],
})
9 changes: 7 additions & 2 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ export default defineConfig({
{ text: 'Index', link: '/api/index.md' },
{ text: 'Modules', items: [
{ text: '2D', link: '/api/modules/2d_src', collapsed: true, items: [
{ text: 'FComponent2d', link: '/api/classes/2d_src.FComponent2d' },
{ text: 'FScene2d', link: '/api/classes/2d_src.FScene2d' },
{ text: 'Core Classes', items: [
{ text: 'FComponent2d', link: '/api/classes/2d_src.FComponent2d' },
{ text: 'FScene2d', link: '/api/classes/2d_src.FScene2d' },
] },
{ text: 'Polygons Classes', items: [
{ text: 'FSquare', link: '/api/classes/2d_src.FSquare' },
] },
] },
{ text: '3D', link: '/api/modules/3d_src', collapsed: true, items: [
{ text: 'Camera Classes', items: [
Expand Down
28 changes: 23 additions & 5 deletions docs/api/classes/2d_src.FComponent2d.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ The base class for all 2D components in FibboJS.

**`FComponent2d`**

↳↳ [`FSquare`](2d_src.FSquare.md)

## Table of contents

### Constructors
Expand All @@ -27,6 +29,10 @@ The base class for all 2D components in FibboJS.
- [setRotation](2d_src.FComponent2d.md#setrotation)
- [setScale](2d_src.FComponent2d.md#setscale)

### Properties

- [container](2d_src.FComponent2d.md#container)

## Constructors

### constructor
Expand All @@ -43,7 +49,7 @@ FComponent.constructor

#### Defined in

[packages/2d/src/FComponent2d.ts:8](https://github.com/fibbojs/fibbo/blob/ccc6e3847dd911058d63a251d216974de127e8af/packages/2d/src/FComponent2d.ts#L8)
[packages/2d/src/FComponent2d.ts:14](https://github.com/fibbojs/fibbo/blob/b3efc33731eef5a3996c7b1f098740f83fa3ec10/packages/2d/src/FComponent2d.ts#L14)

## Methods

Expand All @@ -67,7 +73,7 @@ FComponent.onFrame

#### Defined in

[packages/2d/src/FComponent2d.ts:12](https://github.com/fibbojs/fibbo/blob/ccc6e3847dd911058d63a251d216974de127e8af/packages/2d/src/FComponent2d.ts#L12)
[packages/2d/src/FComponent2d.ts:19](https://github.com/fibbojs/fibbo/blob/b3efc33731eef5a3996c7b1f098740f83fa3ec10/packages/2d/src/FComponent2d.ts#L19)

___

Expand All @@ -92,7 +98,7 @@ Set the position of the component.

#### Defined in

[packages/2d/src/FComponent2d.ts:17](https://github.com/fibbojs/fibbo/blob/ccc6e3847dd911058d63a251d216974de127e8af/packages/2d/src/FComponent2d.ts#L17)
[packages/2d/src/FComponent2d.ts:24](https://github.com/fibbojs/fibbo/blob/b3efc33731eef5a3996c7b1f098740f83fa3ec10/packages/2d/src/FComponent2d.ts#L24)

___

Expand All @@ -117,7 +123,7 @@ Set the rotation of the component.

#### Defined in

[packages/2d/src/FComponent2d.ts:27](https://github.com/fibbojs/fibbo/blob/ccc6e3847dd911058d63a251d216974de127e8af/packages/2d/src/FComponent2d.ts#L27)
[packages/2d/src/FComponent2d.ts:34](https://github.com/fibbojs/fibbo/blob/b3efc33731eef5a3996c7b1f098740f83fa3ec10/packages/2d/src/FComponent2d.ts#L34)

___

Expand All @@ -142,4 +148,16 @@ Set the scale of the component.

#### Defined in

[packages/2d/src/FComponent2d.ts:22](https://github.com/fibbojs/fibbo/blob/ccc6e3847dd911058d63a251d216974de127e8af/packages/2d/src/FComponent2d.ts#L22)
[packages/2d/src/FComponent2d.ts:29](https://github.com/fibbojs/fibbo/blob/b3efc33731eef5a3996c7b1f098740f83fa3ec10/packages/2d/src/FComponent2d.ts#L29)

## Properties

### container

**container**: `Container`\<`ContainerChild`\>

container is the PIXI container that holds the square.

#### Defined in

[packages/2d/src/FComponent2d.ts:12](https://github.com/fibbojs/fibbo/blob/b3efc33731eef5a3996c7b1f098740f83fa3ec10/packages/2d/src/FComponent2d.ts#L12)
Loading

0 comments on commit 9584d07

Please sign in to comment.