Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.0.10: refactor API, internals, testing #23

Merged
merged 37 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
82ed517
feat: start refactor with 2d
Gugustinette Sep 30, 2024
089cd1c
feat: setRotationDegree to RigidBody + sample not working test
Gugustinette Sep 30, 2024
b4c3052
chore: configure browser tests
Gugustinette Sep 30, 2024
3080aa0
Merge branch 'main' into physic-refactor
Gugustinette Sep 30, 2024
9ce2a08
chore: fix test config (but expect error for testing purpose here)
Gugustinette Sep 30, 2024
3eae9a9
chore: fix test
Gugustinette Sep 30, 2024
9eea0ee
test: add tests for FCollider in 2d
Gugustinette Oct 1, 2024
8ad107a
fix: 3d internals in 2d
Gugustinette Oct 1, 2024
46805d9
test(2d): add collider test which do not pass idk why
Gugustinette Oct 1, 2024
1df5366
fix(2d): improve collider testing and fix setScale
Gugustinette Oct 2, 2024
545a7e2
feat(2d): refactor FRigidBody and add tests
Gugustinette Oct 2, 2024
6bcc4fb
docs: add a section about internals
Gugustinette Oct 3, 2024
2ddec82
test(2d): add tests for update transforms methods
Gugustinette Oct 4, 2024
c8bca4c
feat(3d): refactor collider & rigidBody + add tests
Gugustinette Oct 4, 2024
c3fef07
chore: update docs + lint
Gugustinette Oct 4, 2024
b89f858
fix(3d): fix playground model position
Gugustinette Oct 4, 2024
246ad56
docs: add fibbo IPA pronouncation
Gugustinette Oct 11, 2024
ec6007f
docs: fix rigid-body to rigidBody
Gugustinette Oct 11, 2024
9b8a33f
feat: improve test config, improve FScene, FComponent, FCamera...
Gugustinette Oct 12, 2024
c0ad9b0
fix: tests config + devtools typing
Gugustinette Oct 12, 2024
e66585f
chore: fix ci and test config
Gugustinette Oct 12, 2024
b3ce640
feat: hide pixi and three objects behind __INTERNALS__
Gugustinette Oct 13, 2024
08aee70
feat: frame / onFrame refactor
Gugustinette Oct 14, 2024
a245113
fix: game camera + add light getters/setters
Gugustinette Oct 17, 2024
0632acf
feat(3d): start refactoring transform reactivity system
Gugustinette Oct 20, 2024
be6da53
feat(3d): refactor transform system
Gugustinette Oct 22, 2024
d34f1f6
fix: devtools
Gugustinette Oct 22, 2024
5b93a7b
fix(3d): custom meshes are back
Gugustinette Oct 22, 2024
09a6190
fix: default capsule and sphere collider shapes
Gugustinette Oct 22, 2024
845301c
fix(3d): collision management
Gugustinette Oct 22, 2024
744044a
fix(3d): make FCharacterControllerKV rotatable
Gugustinette Oct 22, 2024
075380e
feat(3d): add setLinvel and setAngvel for convenience
Gugustinette Oct 22, 2024
6e84547
feat(2d): start refactoring 2d transform system
Gugustinette Oct 22, 2024
0a5a8c4
test(2d): fix physic + tests
Gugustinette Oct 22, 2024
31a9adc
feat(2d): refactor transform system
Gugustinette Oct 22, 2024
4400eec
chore: update API reference + lint
Gugustinette Oct 22, 2024
df5f16d
docs: update documentation
Gugustinette Oct 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
with:
node-version: 22
registry-url: https://registry.npmjs.org/
- run: npm ci
- name: Install Dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Test all packages
run: npx nx run-many --target=test --all
run: npx nx run-many --target=test:run --all
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ html


.nx/cache
.nx/workspace-data
.nx/workspace-data

__screenshots__
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
"**/node_modules": true,
"**/tsconfig.json": true,
"**/*.d.ts": true,
"**/.gitignore": true
"**/.gitignore": true,
"**/vitest.workspace.ts": true,
"**/vitest.config.ts": true,
"**/coverage": true
}
}
1 change: 1 addition & 0 deletions apps/playground-2d/src/classes/Character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default class Character extends FSprite {
super(scene, {
texture: 'character_0000.png',
position: { x: 0, y: 10 },
// rotationDegree: 45,
scale: { x: 0.5, y: 0.5 },
})

Expand Down
6 changes: 1 addition & 5 deletions apps/playground-2d/src/classes/MySquare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { FRectangle } from '@fibbojs/2d'
export default class MySquare extends FRectangle {
constructor(scene: FScene) {
super(scene)
this.setRotationDegree(30)
this.transform.rotationDegree = 30
this.initRigidBody()
}

onFrame(delta: number) {
super.onFrame(delta)
}
}
11 changes: 3 additions & 8 deletions apps/playground-2d/src/level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function addBelowGround(scene: FScene, position: { x: number, y: number }) {
position,
})
ground.initCollider()
scene.addComponent(ground)
}

function addGround(scene: FScene, position: { x: number, y: number }) {
Expand All @@ -16,7 +15,6 @@ function addGround(scene: FScene, position: { x: number, y: number }) {
position,
})
ground.initCollider()
scene.addComponent(ground)
}

function addBackground(scene: FScene, position: { x: number, y: number }) {
Expand All @@ -25,9 +23,8 @@ function addBackground(scene: FScene, position: { x: number, y: number }) {
position,
})
background.onLoaded(() => {
background.container.zIndex = -1
background.__CONTAINER__.zIndex = -1
})
scene.addComponent(background)
}

function addBackgroundDark(scene: FScene, position: { x: number, y: number }) {
Expand All @@ -36,9 +33,8 @@ function addBackgroundDark(scene: FScene, position: { x: number, y: number }) {
position,
})
background.onLoaded(() => {
background.container.zIndex = -1
background.__CONTAINER__.zIndex = -1
})
scene.addComponent(background)
}

function addBackgroundVariation(scene: FScene, position: { x: number, y: number }, variation = 0) {
Expand All @@ -53,9 +49,8 @@ function addBackgroundVariation(scene: FScene, position: { x: number, y: number
position,
})
background.onLoaded(() => {
background.container.zIndex = -1
background.__CONTAINER__.zIndex = -1
})
scene.addComponent(background)
}

export function loadLevel(scene: FScene) {
Expand Down
27 changes: 9 additions & 18 deletions apps/playground-2d/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-new */
import './style.css'
import { FAttachedCamera, FCircle, FComponentEmpty, FRectangle, FScene, FShapes } from '@fibbojs/2d'
import { fDebug } from '@fibbojs/devtools'
Expand All @@ -20,13 +21,10 @@ import Character from './classes/Character'
scale: { x: 20, y: 0.1 },
})
deathZone.initCollider()
scene.addComponent(deathZone)

// Load level
loadLevel(scene)

const square = new MySquare(scene)
scene.addComponent(square)
new MySquare(scene)

const square2 = new FRectangle(scene, {
position: { x: 0, y: 3 },
Expand All @@ -36,15 +34,13 @@ import Character from './classes/Character'
square2.initCollider({
rotationDegree: 45,
})
scene.addComponent(square2)

const square3 = new FRectangle(scene, {
position: { x: 4, y: 1 },
})
square3.initCollider({
shape: FShapes.CIRCLE,
})
scene.addComponent(square3)

const square4 = new FRectangle(scene, {
position: { x: -2.2, y: 1 },
Expand All @@ -56,34 +52,30 @@ import Character from './classes/Character'
square4.initSensor({
scale: { x: 2.5, y: 2.5 },
})
scene.addComponent(square4)

const square5 = new FRectangle(scene, {
position: { x: 1, y: 2 },
scale: { x: 0.5, y: 0.5 },
})
square5.initSensor()
scene.addComponent(square5)

const circle = new FCircle(scene, {
position: { x: 0, y: 3 },
scale: { x: 1, y: 1 },
})
circle.initRigidBody()
scene.addComponent(circle)

// Create a rotating square
const rotatingSquare = new FRectangle(scene, {
position: { x: 0, y: 5 },
})
rotatingSquare.initSensor()
let totalDelta = 0
scene.addComponent(rotatingSquare)
scene.onFrame((delta) => {
// Each frame, move the cube on a circle of radius 3
const x = Math.cos(totalDelta) * 3
const y = Math.sin(totalDelta) * 3
rotatingSquare.setPosition({ x, y })
rotatingSquare.transform.setPosition({ x, y })
totalDelta += delta
})

Expand All @@ -96,28 +88,27 @@ import Character from './classes/Character'
// Cast the component to FRectangle
const square = component as FRectangle
// Change the color of the square to a random color
square.container.tint = Math.random() * 0xFFFFFF
square.__CONTAINER__.tint = Math.random() * 0xFFFFFF
})
character.onCollisionWith(circle, () => {
console.log('Sprite collided with the circle!')
})
character.onCollisionWith(deathZone, () => {
character.setPosition({ x: 0, y: 5 })
character.transform.setPosition({ x: 0, y: 5 })
console.log('Sprite collided with the death zone!')
})
scene.addComponent(character)

// Create keyboard
const keyboard = new FKeyboard(scene)
keyboard.onKeyDown('p', () => {
character.setPosition({ x: 0, y: 5 })

// Remove a square
scene.removeComponent(square4)
character.transform.setPosition({ x: 0, y: 5 })

// Remove the collision callback with FRectangle
removeCollisionCallbackWithFRectangle()

// Make character 2 times bigger on Y axis
character.transform.setScale({ x: 0.5, y: 1 })

// Zoom in the camera
scene.camera.setZoom(1)
})
Expand Down
38 changes: 19 additions & 19 deletions apps/playground-3d/pages/rainbowls/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ import * as THREE from 'three'
for (let j = 0; j < GRID_COLS; j++) {
// Create the sphere to display
const sphere = new FSphere(scene)
sphere.setPosition({ x: i * GRID_GAP - GRID_ROWS * GRID_GAP / 2, y: 1, z: j * GRID_GAP - GRID_COLS * GRID_GAP / 2 })
sphere.transform.setPosition({ x: i * GRID_GAP - GRID_ROWS * GRID_GAP / 2, y: 1, z: j * GRID_GAP - GRID_COLS * GRID_GAP / 2 })
// @ts-expect-error Disable typing for the mesh property
sphere.mesh.material.color.set(new THREE.Color(0x2C2C2C))
sphere.__MESH__.material.color.set(new THREE.Color(0x2C2C2C))

// Create a cube for the hitbox
const cube = new FCuboid(scene)
cube.setPosition({ x: i * GRID_GAP - GRID_ROWS * GRID_GAP / 2, y: 1, z: j * GRID_GAP - GRID_COLS * GRID_GAP / 2 })
cube.setScale({ x: GRID_GAP, y: 1, z: GRID_GAP })
cube.transform.setPosition({ x: i * GRID_GAP - GRID_ROWS * GRID_GAP / 2, y: 1, z: j * GRID_GAP - GRID_COLS * GRID_GAP / 2 })
cube.transform.setScale({ x: GRID_GAP, y: 1, z: GRID_GAP })
// Make the cube invisible
// @ts-expect-error Disable typing for the mesh property
cube.mesh.material.transparent = true
cube.__MESH__.material.transparent = true
// @ts-expect-error Disable typing for the mesh property
cube.mesh.material.opacity = 0
cube.__MESH__.material.opacity = 0
// Attach coordinates to the cube
cube.mesh.userData = { x: i, y: j }
cube.__MESH__.userData = { x: i, y: j }

// Add the sphere to the scene
scene.addComponent(sphere)
Expand All @@ -49,13 +49,13 @@ import * as THREE from 'three'

// Create a camera target
const cameraTarget = new FCuboid(scene)
cameraTarget.setPosition({ x: 0, y: 1, z: 0 })
cameraTarget.transform.setPosition({ x: 0, y: 1, z: 0 })
// Create a camera
const camera = new FOrbitCamera({
const camera = new FOrbitCamera(scene, {
target: cameraTarget,
})
camera.setPosition(14, 12, 14)
camera.lookAt(0, 0, 0)
camera.transform.setPosition({ x: 14, y: 12, z: 14 })
camera.lookAt({ x: 0, y: 0, z: 0 })
scene.camera = camera

// Create raycaster and pointer
Expand All @@ -79,11 +79,11 @@ import * as THREE from 'three'
// Move the spheres back to their original position
for (let i = 0; i < GRID_ROWS; i++) {
for (let j = 0; j < GRID_COLS; j++) {
grid[i][j].mesh.position.lerp(
grid[i][j].__MESH__.position.lerp(
new THREE.Vector3(
grid[i][j].mesh.position.x,
grid[i][j].__MESH__.position.x,
1,
grid[i][j].mesh.position.z,
grid[i][j].__MESH__.position.z,
)
, 0.1,
)
Expand All @@ -102,19 +102,19 @@ import * as THREE from 'three'
if (distance < RADIUS) {
// Change the color of the sphere based on the distance
// @ts-expect-error Disable typing for the mesh property
sphere.mesh.material.color.set(new THREE.Color(`hsl(${(distance / RADIUS) * 360}, 90%, 70%)`))
sphere.__MESH__.material.color.set(new THREE.Color(`hsl(${(distance / RADIUS) * 360}, 90%, 70%)`))
// Elevate the sphere based on the distance
sphere.mesh.position.lerp(
sphere.__MESH__.position.lerp(
new THREE.Vector3(
sphere.mesh.position.x,
sphere.__MESH__.position.x,
1 + ELEVATION * (1 - distance / RADIUS),
sphere.mesh.position.z,
sphere.__MESH__.position.z,
)
, 0.1,
)
}
// @ts-expect-error Disable typing for the mesh property
else { sphere.mesh.material.color.set(new THREE.Color(0x2C2C2C)) }
else { sphere.__MESH__.material.color.set(new THREE.Color(0x2C2C2C)) }
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions apps/playground-3d/src/classes/Character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ export default class Character extends FFBX {

initRigidBody(options?: FRigidBodyOptions) {
super.initRigidBody({
position: { x: 0, y: 0.25, z: 0 },
scale: { x: 0.25, y: 0.25, z: 0.25 },
positionOffset: { x: 0, y: 0.25, z: 0 },
scaleOffset: { x: -1.5, y: -1.5, z: -1.5 },
...options,
})
}

initSensor(options?: FRigidBodyOptions) {
super.initSensor({
...options,
position: { x: 0, y: 0.25, z: 0 },
scale: { x: 0.6, y: 0.4, z: 0.6 },
positionOffset: { x: 0, y: 0.25, z: 0 },
scaleOffset: { x: -1.3, y: -1.8, z: -1.3 },
})
}
}
4 changes: 0 additions & 4 deletions apps/playground-3d/src/classes/Duck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@ export default class Duck extends FGLB {
name: 'Duck',
})
}

onFrame(delta: number) {
super.onFrame(delta)
}
}
10 changes: 3 additions & 7 deletions apps/playground-3d/src/classes/GltfCube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ export default class GltfCube extends FGLTF {
super(scene, {
name: 'Cube',
})
this.setPosition({ x: -4, y: 5, z: 2 })
this.setScale({ x: 2, y: 0.25, z: 2 })
this.setRotationDegree({ x: 20, y: 0, z: 0 })
this.transform.position = { x: -4, y: 5, z: 2 }
this.transform.rotationDegree = { x: 20, y: 0, z: 0 }
this.transform.scale = { x: 2, y: 0.25, z: 2 }
this.initRigidBody()
}

onFrame(delta: number) {
super.onFrame(delta)
}
}
4 changes: 0 additions & 4 deletions apps/playground-3d/src/classes/MyCustomCube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,4 @@ export default class MyCustomCube extends FCuboid {
constructor(scene: FScene, options?: FComponentOptions) {
super(scene, options)
}

onFrame(delta: number) {
super.onFrame(delta)
}
}
Loading