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

With the new version of WorkAdventure, we use new toast #1

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 12 additions & 9 deletions src/bomb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ActionMessage, Sound, UIWebsite} from "@workadventure/iframe-api-typings";
// @ts-ignore
import {PlayerMessage, Sound, UIWebsite} from "@workadventure/iframe-api-typings";
import {rootLink} from "./config";
import {initiateJob, getPlayerJob, setPlayerJob, Job} from "./modules/job";
import { actionForAllPlayers, discussionv2 as discussion, notifications, secretPassages, sounds } from './modules'
Expand Down Expand Up @@ -185,7 +186,7 @@ onInit(STEP_GAME).then(async () => {
}

// On enter free spy layer
let displayFreeSpyActionMessage: ActionMessage | null = null
let displayFreeSpyPlayerMessage: PlayerMessage | null = null
WA.room.onEnterLayer('saveSpyZone').subscribe(() => {
// If bomb has not been defused, cannot free spy
if (!actionForAllPlayers.hasBeenTriggered('boom') && !actionForAllPlayers.hasBeenTriggered('defuseBomb')) {
Expand All @@ -196,7 +197,8 @@ onInit(STEP_GAME).then(async () => {
"discussion",
)
} else if(!actionForAllPlayers.hasBeenTriggered('freeSpy')) {
displayFreeSpyActionMessage = WA.ui.displayActionMessage({
// @ts-ignore
displayFreeSpyPlayerMessage = WA.ui.displayPlayerMessage({
message: utils.translations.translate('utils.executeAction', {
action: utils.translations.translate('bomb.freeSpy.free')
}),
Expand All @@ -206,17 +208,18 @@ onInit(STEP_GAME).then(async () => {
})

WA.room.onLeaveLayer('saveSpyZone').subscribe(() => {
displayFreeSpyActionMessage?.remove()
displayFreeSpyActionMessage = null
displayFreeSpyPlayerMessage?.remove()
displayFreeSpyPlayerMessage = null
})
}
})

// On enter bomb layer
let displayDefuseBombActionMessage: ActionMessage | null = null
let displayDefuseBombPlayerMessage: PlayerMessage | null = null
WA.room.onEnterLayer('bombZone').subscribe( () => {
if (!actionForAllPlayers.hasBeenTriggered('boom') && !actionForAllPlayers.hasBeenTriggered('defuseBomb')) {
displayDefuseBombActionMessage = WA.ui.displayActionMessage({
// @ts-ignore
displayDefuseBombPlayerMessage = WA.ui.displayPlayerMessage({
message: utils.translations.translate('utils.executeAction', {
action: utils.translations.translate('bomb.bomb.defuse')
}),
Expand Down Expand Up @@ -244,8 +247,8 @@ onInit(STEP_GAME).then(async () => {
}

WA.room.onLeaveLayer('bombZone').subscribe(() => {
displayDefuseBombActionMessage?.remove()
displayDefuseBombActionMessage = null
displayDefuseBombPlayerMessage?.remove()
displayDefuseBombPlayerMessage = null
})
})

Expand Down
8 changes: 5 additions & 3 deletions src/choice.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// <reference types="@workadventure/iframe-api-typings" />

import { ActionMessage, Sound } from '@workadventure/iframe-api-typings';
// @ts-ignore
import { PlayerMessage, Sound } from '@workadventure/iframe-api-typings';
import { discussionv2 as discussion, inventory } from './modules'
import { JobPlayerVaraible, checkAllPlayersGotJob, initiateJob } from "./modules/job";
import * as utils from "./utils";
Expand Down Expand Up @@ -132,9 +133,10 @@ onInit(STEP_GAME).then(async () => {
});

// Take a croissant (useless, but funny)
let takeCroissant: ActionMessage
let takeCroissant: PlayerMessage
WA.room.onEnterLayer('croissants').subscribe(() => {
takeCroissant = WA.ui.displayActionMessage({
// @ts-ignore
takeCroissant = WA.ui.displayPlayerMessage({
message: utils.translations.translate('utils.executeAction', {action : utils.translations.translate('choice.takeCroissantMessage')}),
callback: () => {
const inventorySize = inventory.getInventory().length
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const rootLink = 'https://workadventure.github.io/TheGameProject'
//const rootLink = 'http://localhost:5173'
//const rootLink = 'https://workadventure.github.io/TheGameProject'
const rootLink = 'http://localhost:5173'
const env: 'dev' | 'prod' = "prod"

export {
Expand Down
23 changes: 14 additions & 9 deletions src/escape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ bootstrapExtra();

import {hiddenZone, actionForAllPlayers, secretPassages, readRunes, arrayFilling, sounds} from './modules'
import { Job, initiateJob, setPlayerJob} from "./modules/job";
import {ActionMessage, Sound } from "@workadventure/iframe-api-typings";
// @ts-ignore
import {PlayerMessage, Sound } from "@workadventure/iframe-api-typings";
import * as utils from "./utils";
import {
activateActionForAllPlayer,
Expand Down Expand Up @@ -161,10 +162,11 @@ onInit(STEP_GAME).then(async () => {

}, false)

let blueOn: ActionMessage|null = null
let blueOn: PlayerMessage|null = null
WA.room.onEnterLayer('runes/left').subscribe(() => {
if (!WA.state.runesVictory && !hasBeenTriggered('blue')) {
blueOn = WA.ui.displayActionMessage({
// @ts-ignore
blueOn = WA.ui.displayPlayerMessage({
message: utils.translations.translate('escape.active'),
callback: () => {
activateActionForAllPlayer('blue', true)
Expand All @@ -188,10 +190,11 @@ onInit(STEP_GAME).then(async () => {

}, false)

let redOn: ActionMessage|null = null
let redOn: PlayerMessage|null = null
WA.room.onEnterLayer('runes/center').subscribe(() => {
if (!WA.state.runesVictory && !WA.state.demon) {
redOn = WA.ui.displayActionMessage({
// @ts-ignore
redOn = WA.ui.displayPlayerMessage({
message: utils.translations.translate('escape.active'),
callback: () => {
activateActionForAllPlayer('red', true)
Expand All @@ -215,10 +218,11 @@ onInit(STEP_GAME).then(async () => {

}, false)

let yellowOn: ActionMessage|null = null
let yellowOn: PlayerMessage|null = null
WA.room.onEnterLayer('runes/right').subscribe(() => {
if (!WA.state.runesVictory && !WA.state.knight) {
yellowOn = WA.ui.displayActionMessage({
// @ts-ignore
yellowOn = WA.ui.displayPlayerMessage({
message: utils.translations.translate('escape.active'),
callback: () => {
activateActionForAllPlayer('yellow', true)
Expand Down Expand Up @@ -340,10 +344,11 @@ onInit(STEP_GAME).then(async () => {
WA.room.hideLayer('blackFogs/blackFog9');
WA.room.hideLayer('blackFogs/blackFog10');
})
let artifact: ActionMessage|null = null
let artifact: PlayerMessage|null = null
WA.room.onEnterLayer('artifactZone').subscribe(() => {
if(!hasBeenTriggered('artifactBrok')) {
artifact = WA.ui.displayActionMessage({
// @ts-ignore
artifact = WA.ui.displayPlayerMessage({
message: utils.translations.translate('escape.artifact'),
callback: () => {
actionForAllPlayers.activateActionForAllPlayer('artifactBrok');
Expand Down
44 changes: 28 additions & 16 deletions src/maze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import {hiddenZone, excavations, inventory, switchingTiles, hooking, sounds} from './modules'
import {initiateJob} from "./modules/job";
import * as utils from './utils'
import {ActionMessage, Sound} from "@workadventure/iframe-api-typings";
// @ts-ignore
import {PlayerMessage, Sound} from "@workadventure/iframe-api-typings";
import {env, rootLink} from "./config"
import { onInit } from './utils/init';
import { getChoiceInFirebase, getGem, saveGameStep, saveGem } from './utils/firebase';
Expand All @@ -17,11 +18,12 @@ onInit(STEP_GAME).then( async () => {
disableScreenSharing();

// Trigger fire
let triggerBlue: ActionMessage|null = null;
let triggerBlue: PlayerMessage|null = null;
WA.room.onEnterLayer(`triggerBlue`).subscribe(() => {
if(!WA.state.blueFire){
if(WA.player.state.hasFoundBlueSeed) {
triggerBlue = WA.ui.displayActionMessage({
// @ts-ignore
triggerBlue = WA.ui.displayPlayerMessage({
message: utils.translations.translate('maze.triggerBlue'),
callback: () => {
inventory.removeFromInventory('powder')
Expand All @@ -30,14 +32,16 @@ onInit(STEP_GAME).then( async () => {
})
}
else {
triggerBlue = WA.ui.displayActionMessage({
// @ts-ignore
triggerBlue = WA.ui.displayPlayerMessage({
message: utils.translations.translate('maze.empty'),
callback: () => {
}
})
}
} else {
triggerBlue = WA.ui.displayActionMessage({
// @ts-ignore
triggerBlue = WA.ui.displayPlayerMessage({
message: utils.translations.translate('maze.fireOn'),
callback: () => {
}
Expand All @@ -48,11 +52,12 @@ onInit(STEP_GAME).then( async () => {
WA.room.onLeaveLayer(`triggerBlue`).subscribe(() => {
triggerBlue?.remove()
});
let triggerRed: ActionMessage|null = null;
let triggerRed: PlayerMessage|null = null;
WA.room.onEnterLayer(`triggerRed`).subscribe(() => {
if(!WA.state.redFire){
if(WA.player.state.hasFoundRedSeed) {
triggerRed = WA.ui.displayActionMessage({
// @ts-ignore
triggerRed = WA.ui.displayPlayerMessage({
message: utils.translations.translate('maze.triggerRed'),
callback: () => {
inventory.removeFromInventory('gem')
Expand All @@ -61,14 +66,16 @@ onInit(STEP_GAME).then( async () => {
})
}
else {
triggerRed = WA.ui.displayActionMessage({
// @ts-ignore
triggerRed = WA.ui.displayPlayerMessage({
message: utils.translations.translate('maze.empty'),
callback: () => {
}
})
}
} else {
triggerRed = WA.ui.displayActionMessage({
// @ts-ignore
triggerRed = WA.ui.displayPlayerMessage({
message: utils.translations.translate('maze.fireOn'),
callback: () => {
}
Expand All @@ -79,11 +86,12 @@ onInit(STEP_GAME).then( async () => {
WA.room.onLeaveLayer(`triggerRed`).subscribe(() => {
triggerRed?.remove()
});
let triggerGreen: ActionMessage|null = null;
let triggerGreen: PlayerMessage|null = null;
WA.room.onEnterLayer(`triggerGreen`).subscribe(() => {
if(!WA.state.greenFire){
if(WA.player.state.hasFoundGreenSeed) {
triggerGreen = WA.ui.displayActionMessage({
// @ts-ignore
triggerGreen = WA.ui.displayPlayerMessage({
message: utils.translations.translate('maze.triggerGreen'),
callback: () => {
inventory.removeFromInventory('seed')
Expand All @@ -92,14 +100,16 @@ onInit(STEP_GAME).then( async () => {
})
}
else {
triggerGreen = WA.ui.displayActionMessage({
// @ts-ignore
triggerGreen = WA.ui.displayPlayerMessage({
message: utils.translations.translate('maze.empty'),
callback: () => {
}
})
}
} else {
triggerGreen = WA.ui.displayActionMessage({
// @ts-ignore
triggerGreen = WA.ui.displayPlayerMessage({
message: utils.translations.translate('maze.fireOn'),
callback: () => {
inventory.removeFromInventory('seed');
Expand Down Expand Up @@ -198,14 +208,15 @@ onInit(STEP_GAME).then( async () => {
console.info('Excavation has been made !')} // List of callbacks for your excavationGroups
])

let findSeed: ActionMessage|null = null
let findSeed: PlayerMessage|null = null

excavations.initiateExcavations(
['excavations/exca6'], // List of your excavationGroups names
[() => {
WA.room.onEnterLayer(`excavations/exca6/found`).subscribe(() => {
if(!WA.player.state.hasFoundGreenSeed){
findSeed = WA.ui.displayActionMessage({
// @ts-ignore
findSeed = WA.ui.displayPlayerMessage({
message: utils.translations.translate('maze.takeSeedMsg'),
callback: async () => {
await hasFoundGreenSeed();
Expand All @@ -229,7 +240,8 @@ onInit(STEP_GAME).then( async () => {
WA.room.showLayer('switchTileVictory')
WA.room.onEnterLayer(`blueSeed`).subscribe(() => {
if(!WA.player.state.hasFoundBlueSeed) {
findSeed = WA.ui.displayActionMessage({
// @ts-ignore
findSeed = WA.ui.displayPlayerMessage({
message: utils.translations.translate('maze.takePowderMsg'),
callback: async () => {
await hasFoundBlueSeed();
Expand Down
6 changes: 3 additions & 3 deletions src/modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ You must at first initialize the runes with **initiateRunesReading** function.
Then, you can call the **setRunesReadingZone** as many time as you want for each runes zone. It takes 4 parameters :
- **layer :** the name of the layer on wich the player must enter to see read message
- **params :** a record containing all the query params you want to pass to your view
- **customActionMessage :** The translation key of the custom message that must be displayed when user steps on layer
- **customPlayerMessage :** The translation key of the custom message that must be displayed when user steps on layer
- **view :** the name of the view to call (by default **base** wich take "content" (translation key of text to display) and "title" (translation key of text to display / optional) as parameter)

In your map's script :
Expand Down Expand Up @@ -338,9 +338,9 @@ In your map's script, you have to add openDiscussionWebsite() with parameters :

```typescript
WA.onInit().then(() => {
let talk: ActionMessage;
let talk: PlayerMessage;
WA.room.onEnterLayer("YOUR MAP LAYER").subscribe(() => {
talk = WA.ui.displayActionMessage({
talk = WA.ui.displayPlayerMessage({
message: utils.translations.translate('utils.executeAction', {action : utils.translations.translate('choice.talk')}),
callback: () => {
discussion.openDiscussionWebsite('YOUR TITLE, EX : views.choice.title', 'YOUR TEXT, EX : views.choice.text')
Expand Down
8 changes: 5 additions & 3 deletions src/modules/excavations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import * as utils from '../utils'
import { canUser } from "./job";
import {ActionMessage} from "@workadventure/iframe-api-typings";
// @ts-ignore
import {PlayerMessage} from "@workadventure/iframe-api-typings";
import { sounds } from '../modules'

let makeExcavationAction: ActionMessage|null = null
let makeExcavationAction: PlayerMessage|null = null

// initiateExcavationZones
const initiateExcavations = (excavationZones: Array<string> = ['excavationZone'], callbacks : Array<Function>|null = null) => {
Expand All @@ -19,7 +20,8 @@ const initiateExcavations = (excavationZones: Array<string> = ['excavationZone']

WA.room.onEnterLayer(`${excavationZones[i]}/trace`).subscribe(() => {
if (!WA.state[`${excavationZones[i]}Discovered`]) {
makeExcavationAction = WA.ui.displayActionMessage({
// @ts-ignore
makeExcavationAction = WA.ui.displayPlayerMessage({
message: utils.translations.translate('utils.executeAction', {
action: utils.translations.translate('modules.excavation.makeExcavations')
}),
Expand Down
8 changes: 5 additions & 3 deletions src/modules/hooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import * as utils from '../utils'
import { canUser } from "./job";
import {ActionMessage} from "@workadventure/iframe-api-typings";
// @ts-ignore
import {PlayerMessage} from "@workadventure/iframe-api-typings";
import { sounds } from '../modules'

let makeHookingAction: ActionMessage|null = null
let makeHookingAction: PlayerMessage|null = null

// initiateExcavationZones
const setHooking = (hookingZone: string, callback: Function|null = null) => {
Expand All @@ -20,7 +21,8 @@ const setHooking = (hookingZone: string, callback: Function|null = null) => {
if (!WA.state[`${hookingZone}Discovered`]) {

// Shoow hooking message
makeHookingAction = WA.ui.displayActionMessage({
// @ts-ignore
makeHookingAction = WA.ui.displayPlayerMessage({
message: utils.translations.translate('utils.executeAction', {
action: utils.translations.translate('modules.hooking.hook') // TODO : translation in files
}),
Expand Down
14 changes: 8 additions & 6 deletions src/modules/readRunes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import * as utils from '../utils'
import { canUser } from "./job";
import {rootLink} from "../config";
import {ActionMessage, UIWebsite} from "@workadventure/iframe-api-typings";
// @ts-ignore
import {PlayerMessage, UIWebsite} from "@workadventure/iframe-api-typings";

let runeWebsite: UIWebsite|null = null
let readRunesAction: ActionMessage|null = null
let readRunesAction: PlayerMessage|null = null

const initiateRunesReading = () => {
WA.onInit().then(() => {
Expand All @@ -22,13 +23,14 @@ const initiateRunesReading = () => {
// Initiate a rune reading zone
// Layer : the layer on wich the player must enter to see read message
// params : a record containing all the params you want to pass to your view
// customActionMessage : custom message displayed for read action (translation key)
// customPlayerMessage : custom message displayed for read action (translation key)
// view : the name of the view to call (by default base wich take "content" and "title" (optional) as parameter. You must put translation key in both)
const setRunesReadingZone = (layer: string, params: Record<string, string> = {}, customActionMessage: string ='modules.runes.see', view: string = 'base') => {
const setRunesReadingZone = (layer: string, params: Record<string, string> = {}, customPlayerMessage: string ='modules.runes.see', view: string = 'base') => {
WA.room.onEnterLayer(layer).subscribe(() => {
readRunesAction = WA.ui.displayActionMessage({
// @ts-ignore
readRunesAction = WA.ui.displayPlayerMessage({
message: utils.translations.translate('utils.executeAction', {
action: utils.translations.translate(customActionMessage)
action: utils.translations.translate(customPlayerMessage)
}),
callback: () => {
openRunesWebsite(params, view)
Expand Down
Loading
Loading