Skip to content

Commit

Permalink
fix bubble ids
Browse files Browse the repository at this point in the history
  • Loading branch information
nearnshaw committed Jan 2, 2024
1 parent 1caecc2 commit 0bd11e5
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 32 deletions.
51 changes: 36 additions & 15 deletions bin/game.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export enum SyncEntityIDs {
PBAR5_B = 49,
PBAR6_A = 50,
PBAR6_B = 51,
CUSTOMER1 = 52,
CUSTOMER2 = 53,
CUSTOMER3 = 54,
CUSTOMER4 = 55,
// TABLES = 19
}

Expand Down
20 changes: 12 additions & 8 deletions src/modules/customers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GltfContainer, Animator, Transform, engine, Entity, TextShape } from "@
import { Vector3, Scalar, Quaternion, Color4 } from '@dcl/sdk/math'
import { ProgressBar, CustomerData, IngredientType, SpeechBubbleType, BeerGlass, BeerType, GameData } from "../definitions";
import { CreateProgressBar, RemoveProgressBar } from "./progressBars";
import { RemoveSpeechBubble, createSpeechBubble } from "./speechBubble";
import { RemoveSpeechBubble, createSpeechBubble, updateSpeechBubble } from "./speechBubble";
import { syncEntity, parentEntity } from '@dcl/sdk/network'
import * as utils from '@dcl-sdk/utils'
import { getPlayerPosition, playSound } from "./helpers";
Expand Down Expand Up @@ -334,9 +334,9 @@ export function deliverOrder(dishType: number, customer: Entity, dish?: Entity)
}


if (customerData.speechBubble) {
RemoveSpeechBubble(customerData.speechBubble)
}
// if (customerData.speechBubble) {
// RemoveSpeechBubble(customerData.speechBubble)
// }


const [gameEntities] = engine.getEntitiesWith(GameData)
Expand All @@ -352,8 +352,10 @@ export function deliverOrder(dishType: number, customer: Entity, dish?: Entity)
const message = customerCorrectDishMessages[Math.floor(Scalar.randomRange(0, customerCorrectDishMessages.length))]
customerData.message = message

const speechBubble = createSpeechBubble(customer, message, 2.3, SpeechBubbleType.Good)
customerData.speechBubble = speechBubble
updateSpeechBubble(customerData.speechBubble, message, SpeechBubbleType.Good)

// const speechBubble = createSpeechBubble(customer, message, 2.3, SpeechBubbleType.Good)
// customerData.speechBubble = speechBubble

} else {
// Wrong dish
Expand All @@ -362,8 +364,10 @@ export function deliverOrder(dishType: number, customer: Entity, dish?: Entity)
const message = customerWrongDishMessages[Math.floor(Scalar.randomRange(0, customerWrongDishMessages.length))]
customerData.message = message

const speechBubble = createSpeechBubble(customer, message, 2.3, SpeechBubbleType.Bad)
customerData.speechBubble = speechBubble
updateSpeechBubble(customerData.speechBubble, message, SpeechBubbleType.Bad)

// const speechBubble = createSpeechBubble(customer, message, 2.3, SpeechBubbleType.Bad)
// customerData.speechBubble = speechBubble
}


Expand Down
58 changes: 49 additions & 9 deletions src/modules/speechBubble.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { Entity, Material, engine, Transform, TextShape, MeshRenderer, TextAlignMode } from "@dcl/sdk/ecs";
import { SpeechBubbleType } from "../definitions";
import { Color4, Vector3, Quaternion } from "@dcl/ecs-math";
import { syncEntity, parentEntity } from '@dcl/sdk/network'
import { syncEntity, parentEntity, getChildren } from '@dcl/sdk/network'
import { getSyncId } from "./helpers";

const bubble1Texture = Material.Texture.Common({
src: 'assets/textures/bubble.png',
})
// const bubble2Texture = Material.Texture.Common({
// src: 'assets/textures/bubble2.jpg',
// })

const bubble3Texture = Material.Texture.Common({
src: 'assets/textures/bubble3.png',
})
Expand Down Expand Up @@ -53,13 +51,9 @@ export function createSpeechBubble(parent: Entity, text: string, height?: number
break
}

const goodBubbleMaterial = Material.setBasicMaterial(background, {
Material.setBasicMaterial(background, {
diffuseColor: color,
texture: texture,
//alphaTexture: texture,
//specularIntensity: 0,
//metallic: 0,
//roughness: 1,

})

Expand Down Expand Up @@ -99,6 +93,52 @@ export function createSpeechBubble(parent: Entity, text: string, height?: number
}


export function updateSpeechBubble(bubble: Entity, text: string, bubbleType?: SpeechBubbleType) {

const children = Array.from(getChildren(bubble))
let backgroundEntity: Entity | undefined = undefined
let textEntity: Entity | undefined = undefined

for (const ent of children) {
if (TextShape.has(ent)) {
textEntity = ent
}
if (MeshRenderer.has(ent)) {
backgroundEntity = ent
}
}

if (!backgroundEntity || !textEntity) { return }


let texture = bubble1Texture
let color = Color4.Gray()

switch (bubbleType) {
case SpeechBubbleType.Good:
texture = bubble3Texture
color = Color4.Green()
break
case SpeechBubbleType.Bad:
texture = bubble3Texture
color = Color4.Red()
break
}

Material.setBasicMaterial(backgroundEntity, {
diffuseColor: color,
texture: texture,

})

TextShape.getMutable(textEntity).text = text


}




export function RemoveSpeechBubble(bubble: Entity) {

// TODO
Expand Down

0 comments on commit 0bd11e5

Please sign in to comment.