Skip to content

Commit

Permalink
several fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nearnshaw committed Dec 28, 2023
1 parent aaa1c54 commit 60f1041
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 32 deletions.
17 changes: 16 additions & 1 deletion assets/scene/main.composite
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,21 @@
"protocolBuffer": "PBPointerEvents"
},
"data": {
"513": {
"json": {
"pointerEvents": [
{
"eventType": 1,
"eventInfo": {
"button": 3,
"hoverText": "Interact",
"maxDistance": 10,
"showFeedback": false
}
}
]
}
},
"522": {
"json": {
"pointerEvents": [
Expand Down Expand Up @@ -1280,7 +1295,7 @@
"serializationType": "map"
},
"data": {
"530": {
"513": {
"json": {
"gizmo": 0
}
Expand Down
63 changes: 46 additions & 17 deletions bin/game.js

Large diffs are not rendered by default.

Binary file modified main.crdt
Binary file not shown.
32 changes: 29 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
ColliderLayer, engine, Animator,
AudioSource, VisibilityComponent, Material,
VideoPlayer, pointerEventsSystem,
AvatarAttach, GltfContainer, PointerEvents, PointerEventType, TextShape, Transform
AvatarAttach, GltfContainer, PointerEvents, Tween, PointerEventType, TextShape, Transform
} from '@dcl/sdk/ecs'
import { Vector3, Quaternion } from '@dcl/sdk/math'
import { BeerType, IngredientType, SyncEntityIDs } from './definitions'
Expand Down Expand Up @@ -58,13 +58,39 @@ export function main() {
fontSize: 3,
})


//Ingredient expenders
const noodles_expender = engine.getEntityOrNullByName("ExpenderNoodles")
const roll_expender = engine.getEntityOrNullByName("ExpenderRolls")

const noodles_button = engine.getEntityOrNullByName("Noodle Button")
const roll_button = engine.getEntityOrNullByName("Roll Button")

// TODO: HANDLE IDS FOR MULTIPLAYER MODE

if (noodles_expender && roll_expender && noodles_button && roll_button) {
const noodles_button_events = getTriggerEvents(noodles_button)
noodles_button_events.on(TriggerType.ON_CLICK, () => {
console.log("BUTTON WAS PRESSED!!")
const startPosition = Vector3.add(Transform.get(noodles_expender).position, Vector3.create(0, 0.7, 0))
createIngredient(IngredientType.Noodles, startPosition, true)

})

const roll_button_events = getTriggerEvents(roll_button)
roll_button_events.on(TriggerType.ON_CLICK, () => {
console.log("BUTTON WAS PRESSED!!")
const startPosition = Vector3.add(Transform.get(roll_expender).position, Vector3.create(0, 0.7, 0))
createIngredient(IngredientType.SushiRoll, startPosition, true)

})

}






// Pots
const pot1 = engine.getEntityOrNullByName("Pot1")
const pot2 = engine.getEntityOrNullByName("Pot2")
Expand Down Expand Up @@ -143,7 +169,7 @@ export function main() {
}



// FOR TESTING
createIngredient(IngredientType.Noodles, Vector3.create(4.4, 0.8, 1.5))
createIngredient(IngredientType.SushiRoll, Vector3.create(6.4, 0.8, 1.5))
createIngredient(IngredientType.SlicedSushi, Vector3.create(8.4, 0.8, 1.5))
Expand Down
33 changes: 25 additions & 8 deletions src/modules/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {
MeshRenderer,
AudioSource,
ColliderLayer,
pointerEventsSystem
pointerEventsSystem,
Tween,
EasingFunction
} from '@dcl/sdk/ecs'
import { Vector3, Quaternion } from '@dcl/sdk/math'
import { BeerGlass, BeerType, CuttingBoard, getTapData, GrabableObjectComponent, IngredientType, SyncEntityIDs, TapBase, TapComponent } from '../definitions'
Expand Down Expand Up @@ -55,7 +57,7 @@ export function instanceBeer(entity: Entity, id: SyncEntityIDs) {
// INGREDIENT


export function createIngredient(ingredient: IngredientType, position: Vector3) {
export function createIngredient(ingredient: IngredientType, position: Vector3, fall?: boolean) {
const entity = engine.addEntity()

let model = ""
Expand Down Expand Up @@ -101,11 +103,25 @@ export function createIngredient(ingredient: IngredientType, position: Vector3)
]
})

// syncEntity(
// entity,
// [AudioSource.componentId, Transform.componentId, GrabableObjectComponent.componentId],
// id
// )
if (fall) {
Tween.create(entity, {
mode: Tween.Mode.Move({
start: position,
end: Vector3.add(position, Vector3.create(0, -0.7, 0)),
}),
duration: 1000,
easingFunction: EasingFunction.EF_LINEAR
})
}

syncEntity(
entity,
[AudioSource.componentId, Transform.componentId, GrabableObjectComponent.componentId, Tween.componentId],
// id
)
// TODO: HANDLE IDS FOR MULTIPLAYER

return ingredient

}

Expand Down Expand Up @@ -204,7 +220,8 @@ export function createCuttingBoard(position: Vector3, id: SyncEntityIDs) {

const CutterParent = engine.addEntity()
Transform.create(CutterParent, {
position: position
position: position,
rotation: Quaternion.fromEulerDegrees(0, 0, 0)
})

syncEntity(CutterParent, [], id + 100)
Expand Down
6 changes: 3 additions & 3 deletions src/modules/pickAndDrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ export function pickingGlassSystem() {
// parent: hitParentEntity
// })
console.log("DROPPED ON TAP")
removeParent(pickedUpChild)
//removeParent(pickedUpChild)
parentEntity(pickedUpChild, hitParentEntity)
drop = true
} else if (hitParentEntity && CuttingBoard.has(hitParentEntity)) {
//If cutting board
console.log("DROPPED ON CUTTING BOARD")
const board = CuttingBoard.getMutable(hitParentEntity)
if (!board || !board.hasRoll || !board.modelEntity) {
removeParent(pickedUpChild)
//removeParent(pickedUpChild)
parentEntity(pickedUpChild, hitParentEntity)
drop = true

Expand All @@ -63,7 +63,7 @@ export function pickingGlassSystem() {
console.log("DROPPED ON POT")
const pot = PotData.getMutable(hitEntity)
if (pot && !pot.hasIngredient) {
removeParent(pickedUpChild)
//removeParent(pickedUpChild)
parentEntity(pickedUpChild, hitEntity)
pot.hasIngredient = true
pot.attachedEntity = pickedUpChild
Expand Down
1 change: 1 addition & 0 deletions src/modules/pot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function pickFood(pot: Entity) {
const potData = PotData.getMutable(pot)
if (potData && potData.hasIngredient && potData.attachedEntity !== undefined) {

console.log("PICKING UP FROM POT")
pickUpItem(potData.attachedEntity)
potData.hasIngredient = false
//potData.attachedEntity = undefined
Expand Down

0 comments on commit 60f1041

Please sign in to comment.