Skip to content

Commit

Permalink
Refactor vehicle text display and remove unused script
Browse files Browse the repository at this point in the history
  • Loading branch information
iErcann committed Jan 26, 2025
1 parent 385687e commit 64bef8b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 249 deletions.
17 changes: 13 additions & 4 deletions back/src/ecs/system/VehicleSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class VehicleSystem {
*/
this.vehicleCreationSystem.update(entities, world)
/**
* Vehicle movement
* Vehicle movement based on player input
*/
this.vehicleMovementSystem.update(entities, dt)
/**
Expand All @@ -37,6 +37,8 @@ export class VehicleSystem {
this.handlePlayerExitVehicle(entities)
/**
* Update vehicle controller raycast
* To optimize this : Only update the raycast if a player is inside the vehicle
* But since wheels can be non physical, idle vehicles will have their chassis on the ground
*/
for (const entity of entities) {
const vehicleRayCastComponent = entity.getComponent(VehicleRayCastComponent)
Expand Down Expand Up @@ -213,9 +215,16 @@ export class VehicleSystem {
}
}
private updateText(textComponent: TextComponent, vehicleComponent: VehicleComponent) {
textComponent.text = `🚗 Driver: ${
vehicleComponent.driverEntityId ? 'Yes' : 'No'
} | 🧑‍🤝‍🧑 Passengers: ${vehicleComponent.passengerEntityIds.length}`
const hasDriver = !!vehicleComponent.driverEntityId
const passengerCount = vehicleComponent.passengerEntityIds.length

textComponent.text = [
hasDriver ? '' : '🚗 Car',
passengerCount > 0 ? `👥 ${passengerCount} passenger${passengerCount > 1 ? 's' : ''}` : '',
]
.filter(Boolean)
.join(' ')

textComponent.updated = true
}
}
235 changes: 0 additions & 235 deletions back/src/scripts/carScript.js

This file was deleted.

9 changes: 1 addition & 8 deletions back/src/scripts/defaultScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ new MapWorld('https://notbloxo.fra1.cdn.digitaloceanspaces.com/Notblox-Assets/wo

// Create a basic cube
const basicCubeParams = {
position: { x: 0, y: 5, z: -20 },
position: { x: 0, y: 5, z: -50 },
size: { width: 3, height: 3, depth: 3 },
}
new Cube(basicCubeParams)
Expand All @@ -24,13 +24,6 @@ const basicSphereParams = {
}
new Sphere(basicSphereParams)

const basicSphereParams2 = {
position: { x: 5, y: 10, z: -10 },
radius: 6,
color: '#ffffff',
}
new Sphere(basicSphereParams2)

// === Interactive Trigger Zone Example ===
// Creates an invisible trigger zone that detects when players enter/exit
const triggerCube = new TriggerCube(
Expand Down
6 changes: 4 additions & 2 deletions front/game/ecs/system/TextComponentSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ export class TextComponentSystem {
this.updateVisibility(entity, currentPlayerEntity, textComponent)
}

// Update the visibility of the text based on the distance from the player
// Updates text visibility based on two conditions:
// 1. The text must be within displayDistance units of the player
// 2. The text content must not be empty
private updateVisibility(
entityWithText: Entity,
currentPlayerEntity: Entity,
Expand All @@ -284,7 +286,7 @@ export class TextComponentSystem {

const distance = this.calculateDistance(position, playerPosition)

textObject.visible = distance <= textComponent.displayDistance
textObject.visible = distance <= textComponent.displayDistance && textComponent.text !== ''
}

private calculateDistance(pos1: PositionComponent, pos2: PositionComponent): number {
Expand Down

0 comments on commit 64bef8b

Please sign in to comment.