Merge branch 'develop' of github.com:thecodingmachine/workadventure into main
This commit is contained in:
commit
72a07467c5
5
.github/workflows/push-to-npm.yml
vendored
5
.github/workflows/push-to-npm.yml
vendored
@ -2,6 +2,7 @@ name: Push @workadventure/iframe-api-typings to NPM
|
|||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
types: [created]
|
types: [created]
|
||||||
|
push:
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@ -52,6 +53,9 @@ jobs:
|
|||||||
- name: Copy typings to package dir
|
- name: Copy typings to package dir
|
||||||
run: cp front/dist/src/iframe_api.d.ts front/packages/iframe-api-typings/iframe_api.d.ts
|
run: cp front/dist/src/iframe_api.d.ts front/packages/iframe-api-typings/iframe_api.d.ts
|
||||||
|
|
||||||
|
- name: Copy typings to package dir (2)
|
||||||
|
run: cp -R front/dist/src/Api front/packages/iframe-api-typings/Api
|
||||||
|
|
||||||
- name: Install dependencies in package
|
- name: Install dependencies in package
|
||||||
run: yarn install
|
run: yarn install
|
||||||
working-directory: "front/packages/iframe-api-typings"
|
working-directory: "front/packages/iframe-api-typings"
|
||||||
@ -61,3 +65,4 @@ jobs:
|
|||||||
working-directory: "front/packages/iframe-api-typings"
|
working-directory: "front/packages/iframe-api-typings"
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
if: ${{ github.event_name == 'release' }}
|
||||||
|
@ -63,7 +63,7 @@
|
|||||||
"templater": "cross-env ./templater.sh",
|
"templater": "cross-env ./templater.sh",
|
||||||
"serve": "cross-env TS_NODE_PROJECT=\"tsconfig-for-webpack.json\" webpack serve --open",
|
"serve": "cross-env TS_NODE_PROJECT=\"tsconfig-for-webpack.json\" webpack serve --open",
|
||||||
"build": "cross-env TS_NODE_PROJECT=\"tsconfig-for-webpack.json\" NODE_ENV=production webpack",
|
"build": "cross-env TS_NODE_PROJECT=\"tsconfig-for-webpack.json\" NODE_ENV=production webpack",
|
||||||
"build-typings": "cross-env TS_NODE_PROJECT=\"tsconfig-for-webpack.json\" NODE_ENV=production NODE_ENV=production BUILD_TYPINGS=1 webpack",
|
"build-typings": "cross-env TS_NODE_PROJECT=\"tsconfig-for-webpack.json\" NODE_ENV=production BUILD_TYPINGS=1 webpack",
|
||||||
"test": "TS_NODE_PROJECT=\"tsconfig-for-jasmine.json\" ts-node node_modules/jasmine/bin/jasmine --config=jasmine.json",
|
"test": "TS_NODE_PROJECT=\"tsconfig-for-jasmine.json\" ts-node node_modules/jasmine/bin/jasmine --config=jasmine.json",
|
||||||
"lint": "node_modules/.bin/eslint src/ . --ext .ts",
|
"lint": "node_modules/.bin/eslint src/ . --ext .ts",
|
||||||
"fix": "node_modules/.bin/eslint --fix src/ . --ext .ts",
|
"fix": "node_modules/.bin/eslint --fix src/ . --ext .ts",
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
import type { ChatEvent } from '../Events/ChatEvent'
|
import type { ChatEvent } from "../Events/ChatEvent";
|
||||||
import { isUserInputChatEvent, UserInputChatEvent } from '../Events/UserInputChatEvent'
|
import { isUserInputChatEvent, UserInputChatEvent } from "../Events/UserInputChatEvent";
|
||||||
import { IframeApiContribution, sendToWorkadventure } from './IframeApiContribution'
|
import { IframeApiContribution, sendToWorkadventure } from "./IframeApiContribution";
|
||||||
import { apiCallback } from "./registeredCallbacks";
|
import { apiCallback } from "./registeredCallbacks";
|
||||||
import {Subject} from "rxjs";
|
import { Subject } from "rxjs";
|
||||||
|
|
||||||
const chatStream = new Subject<string>();
|
const chatStream = new Subject<string>();
|
||||||
|
|
||||||
class WorkadventureChatCommands extends IframeApiContribution<WorkadventureChatCommands> {
|
export class WorkadventureChatCommands extends IframeApiContribution<WorkadventureChatCommands> {
|
||||||
|
callbacks = [
|
||||||
callbacks = [apiCallback({
|
apiCallback({
|
||||||
callback: (event: UserInputChatEvent) => {
|
callback: (event: UserInputChatEvent) => {
|
||||||
chatStream.next(event.message);
|
chatStream.next(event.message);
|
||||||
},
|
},
|
||||||
type: "userInputChat",
|
type: "userInputChat",
|
||||||
typeChecker: isUserInputChatEvent
|
typeChecker: isUserInputChatEvent,
|
||||||
})]
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
sendChatMessage(message: string, author: string) {
|
sendChatMessage(message: string, author: string) {
|
||||||
sendToWorkadventure({
|
sendToWorkadventure({
|
||||||
type: 'chat',
|
type: "chat",
|
||||||
data: {
|
data: {
|
||||||
'message': message,
|
message: message,
|
||||||
'author': author
|
author: author,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,4 +35,4 @@ class WorkadventureChatCommands extends IframeApiContribution<WorkadventureChatC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new WorkadventureChatCommands()
|
export default new WorkadventureChatCommands();
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
import { IframeApiContribution, sendToWorkadventure } from './IframeApiContribution';
|
import { IframeApiContribution, sendToWorkadventure } from "./IframeApiContribution";
|
||||||
|
|
||||||
class WorkadventureControlsCommands extends IframeApiContribution<WorkadventureControlsCommands> {
|
export class WorkadventureControlsCommands extends IframeApiContribution<WorkadventureControlsCommands> {
|
||||||
callbacks = []
|
callbacks = [];
|
||||||
|
|
||||||
disablePlayerControls(): void {
|
disablePlayerControls(): void {
|
||||||
sendToWorkadventure({ 'type': 'disablePlayerControls', data: null });
|
sendToWorkadventure({ type: "disablePlayerControls", data: null });
|
||||||
}
|
}
|
||||||
|
|
||||||
restorePlayerControls(): void {
|
restorePlayerControls(): void {
|
||||||
sendToWorkadventure({ 'type': 'restorePlayerControls', data: null });
|
sendToWorkadventure({ type: "restorePlayerControls", data: null });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default new WorkadventureControlsCommands();
|
export default new WorkadventureControlsCommands();
|
||||||
|
@ -1,59 +1,56 @@
|
|||||||
import type { GoToPageEvent } from '../Events/GoToPageEvent';
|
import type { GoToPageEvent } from "../Events/GoToPageEvent";
|
||||||
import type { OpenTabEvent } from '../Events/OpenTabEvent';
|
import type { OpenTabEvent } from "../Events/OpenTabEvent";
|
||||||
import { IframeApiContribution, sendToWorkadventure } from './IframeApiContribution';
|
import { IframeApiContribution, sendToWorkadventure } from "./IframeApiContribution";
|
||||||
import type {OpenCoWebSiteEvent} from "../Events/OpenCoWebSiteEvent";
|
import type { OpenCoWebSiteEvent } from "../Events/OpenCoWebSiteEvent";
|
||||||
import type {LoadPageEvent} from "../Events/LoadPageEvent";
|
import type { LoadPageEvent } from "../Events/LoadPageEvent";
|
||||||
|
|
||||||
|
|
||||||
class WorkadventureNavigationCommands extends IframeApiContribution<WorkadventureNavigationCommands> {
|
|
||||||
callbacks = []
|
|
||||||
|
|
||||||
|
export class WorkadventureNavigationCommands extends IframeApiContribution<WorkadventureNavigationCommands> {
|
||||||
|
callbacks = [];
|
||||||
|
|
||||||
openTab(url: string): void {
|
openTab(url: string): void {
|
||||||
sendToWorkadventure({
|
sendToWorkadventure({
|
||||||
"type": 'openTab',
|
type: "openTab",
|
||||||
"data": {
|
data: {
|
||||||
url
|
url,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
goToPage(url: string): void {
|
goToPage(url: string): void {
|
||||||
sendToWorkadventure({
|
sendToWorkadventure({
|
||||||
"type": 'goToPage',
|
type: "goToPage",
|
||||||
"data": {
|
data: {
|
||||||
url
|
url,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
goToRoom(url: string): void {
|
goToRoom(url: string): void {
|
||||||
sendToWorkadventure({
|
sendToWorkadventure({
|
||||||
"type": 'loadPage',
|
type: "loadPage",
|
||||||
"data": {
|
data: {
|
||||||
url
|
url,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
openCoWebSite(url: string, allowApi: boolean = false, allowPolicy: string = ""): void {
|
openCoWebSite(url: string, allowApi: boolean = false, allowPolicy: string = ""): void {
|
||||||
sendToWorkadventure({
|
sendToWorkadventure({
|
||||||
"type": 'openCoWebSite',
|
type: "openCoWebSite",
|
||||||
"data": {
|
data: {
|
||||||
url,
|
url,
|
||||||
allowApi,
|
allowApi,
|
||||||
allowPolicy,
|
allowPolicy,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
closeCoWebSite(): void {
|
closeCoWebSite(): void {
|
||||||
sendToWorkadventure({
|
sendToWorkadventure({
|
||||||
"type": 'closeCoWebSite',
|
type: "closeCoWebSite",
|
||||||
data: null
|
data: null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default new WorkadventureNavigationCommands();
|
export default new WorkadventureNavigationCommands();
|
||||||
|
@ -1,28 +1,28 @@
|
|||||||
import {IframeApiContribution, sendToWorkadventure} from "./IframeApiContribution";
|
import { IframeApiContribution, sendToWorkadventure } from "./IframeApiContribution";
|
||||||
import type {HasPlayerMovedEvent, HasPlayerMovedEventCallback} from "../Events/HasPlayerMovedEvent";
|
import type { HasPlayerMovedEvent, HasPlayerMovedEventCallback } from "../Events/HasPlayerMovedEvent";
|
||||||
import {Subject} from "rxjs";
|
import { Subject } from "rxjs";
|
||||||
import {apiCallback} from "./registeredCallbacks";
|
import { apiCallback } from "./registeredCallbacks";
|
||||||
import {isHasPlayerMovedEvent} from "../Events/HasPlayerMovedEvent";
|
import { isHasPlayerMovedEvent } from "../Events/HasPlayerMovedEvent";
|
||||||
|
|
||||||
const moveStream = new Subject<HasPlayerMovedEvent>();
|
const moveStream = new Subject<HasPlayerMovedEvent>();
|
||||||
|
|
||||||
class WorkadventurePlayerCommands extends IframeApiContribution<WorkadventurePlayerCommands> {
|
export class WorkadventurePlayerCommands extends IframeApiContribution<WorkadventurePlayerCommands> {
|
||||||
callbacks = [
|
callbacks = [
|
||||||
apiCallback({
|
apiCallback({
|
||||||
type: 'hasPlayerMoved',
|
type: "hasPlayerMoved",
|
||||||
typeChecker: isHasPlayerMovedEvent,
|
typeChecker: isHasPlayerMovedEvent,
|
||||||
callback: (payloadData) => {
|
callback: (payloadData) => {
|
||||||
moveStream.next(payloadData);
|
moveStream.next(payloadData);
|
||||||
}
|
},
|
||||||
}),
|
}),
|
||||||
]
|
];
|
||||||
|
|
||||||
onPlayerMove(callback: HasPlayerMovedEventCallback): void {
|
onPlayerMove(callback: HasPlayerMovedEventCallback): void {
|
||||||
moveStream.subscribe(callback);
|
moveStream.subscribe(callback);
|
||||||
sendToWorkadventure({
|
sendToWorkadventure({
|
||||||
type: 'onPlayerMove',
|
type: "onPlayerMove",
|
||||||
data: null
|
data: null,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ function getDataLayer(): Promise<DataLayerEvent> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class WorkadventureRoomCommands extends IframeApiContribution<WorkadventureRoomCommands> {
|
export class WorkadventureRoomCommands extends IframeApiContribution<WorkadventureRoomCommands> {
|
||||||
callbacks = [
|
callbacks = [
|
||||||
apiCallback({
|
apiCallback({
|
||||||
callback: (payloadData: EnterLeaveEvent) => {
|
callback: (payloadData: EnterLeaveEvent) => {
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
import type { LoadSoundEvent } from '../Events/LoadSoundEvent';
|
import type { LoadSoundEvent } from "../Events/LoadSoundEvent";
|
||||||
import type { PlaySoundEvent } from '../Events/PlaySoundEvent';
|
import type { PlaySoundEvent } from "../Events/PlaySoundEvent";
|
||||||
import type { StopSoundEvent } from '../Events/StopSoundEvent';
|
import type { StopSoundEvent } from "../Events/StopSoundEvent";
|
||||||
import { IframeApiContribution, sendToWorkadventure } from './IframeApiContribution';
|
import { IframeApiContribution, sendToWorkadventure } from "./IframeApiContribution";
|
||||||
import {Sound} from "./Sound/Sound";
|
import { Sound } from "./Sound/Sound";
|
||||||
|
|
||||||
class WorkadventureSoundCommands extends IframeApiContribution<WorkadventureSoundCommands> {
|
export class WorkadventureSoundCommands extends IframeApiContribution<WorkadventureSoundCommands> {
|
||||||
callbacks = []
|
callbacks = [];
|
||||||
|
|
||||||
loadSound(url: string): Sound {
|
loadSound(url: string): Sound {
|
||||||
return new Sound(url);
|
return new Sound(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default new WorkadventureSoundCommands();
|
export default new WorkadventureSoundCommands();
|
||||||
|
@ -1,54 +1,56 @@
|
|||||||
import { isButtonClickedEvent } from '../Events/ButtonClickedEvent';
|
import { isButtonClickedEvent } from "../Events/ButtonClickedEvent";
|
||||||
import { isMenuItemClickedEvent } from '../Events/ui/MenuItemClickedEvent';
|
import { isMenuItemClickedEvent } from "../Events/ui/MenuItemClickedEvent";
|
||||||
import type { MenuItemRegisterEvent } from '../Events/ui/MenuItemRegisterEvent';
|
import type { MenuItemRegisterEvent } from "../Events/ui/MenuItemRegisterEvent";
|
||||||
import { IframeApiContribution, sendToWorkadventure } from './IframeApiContribution';
|
import { IframeApiContribution, sendToWorkadventure } from "./IframeApiContribution";
|
||||||
import { apiCallback } from "./registeredCallbacks";
|
import { apiCallback } from "./registeredCallbacks";
|
||||||
import type { ButtonClickedCallback, ButtonDescriptor } from "./Ui/ButtonDescriptor";
|
import type { ButtonClickedCallback, ButtonDescriptor } from "./Ui/ButtonDescriptor";
|
||||||
import { Popup } from "./Ui/Popup";
|
import { Popup } from "./Ui/Popup";
|
||||||
|
|
||||||
let popupId = 0;
|
let popupId = 0;
|
||||||
const popups: Map<number, Popup> = new Map<number, Popup>();
|
const popups: Map<number, Popup> = new Map<number, Popup>();
|
||||||
const popupCallbacks: Map<number, Map<number, ButtonClickedCallback>> = new Map<number, Map<number, ButtonClickedCallback>>();
|
const popupCallbacks: Map<number, Map<number, ButtonClickedCallback>> = new Map<
|
||||||
|
number,
|
||||||
|
Map<number, ButtonClickedCallback>
|
||||||
|
>();
|
||||||
|
|
||||||
const menuCallbacks: Map<string, (command: string) => void> = new Map()
|
const menuCallbacks: Map<string, (command: string) => void> = new Map();
|
||||||
|
|
||||||
interface ZonedPopupOptions {
|
interface ZonedPopupOptions {
|
||||||
zone: string
|
zone: string;
|
||||||
objectLayerName?: string,
|
objectLayerName?: string;
|
||||||
popupText: string,
|
popupText: string;
|
||||||
delay?: number
|
delay?: number;
|
||||||
popupOptions: Array<ButtonDescriptor>
|
popupOptions: Array<ButtonDescriptor>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class WorkAdventureUiCommands extends IframeApiContribution<WorkAdventureUiCommands> {
|
||||||
class WorkAdventureUiCommands extends IframeApiContribution<WorkAdventureUiCommands> {
|
callbacks = [
|
||||||
|
apiCallback({
|
||||||
callbacks = [apiCallback({
|
type: "buttonClickedEvent",
|
||||||
type: "buttonClickedEvent",
|
typeChecker: isButtonClickedEvent,
|
||||||
typeChecker: isButtonClickedEvent,
|
callback: (payloadData) => {
|
||||||
callback: (payloadData) => {
|
const callback = popupCallbacks.get(payloadData.popupId)?.get(payloadData.buttonId);
|
||||||
const callback = popupCallbacks.get(payloadData.popupId)?.get(payloadData.buttonId);
|
const popup = popups.get(payloadData.popupId);
|
||||||
const popup = popups.get(payloadData.popupId);
|
if (popup === undefined) {
|
||||||
if (popup === undefined) {
|
throw new Error('Could not find popup with ID "' + payloadData.popupId + '"');
|
||||||
throw new Error('Could not find popup with ID "' + payloadData.popupId + '"');
|
}
|
||||||
}
|
if (callback) {
|
||||||
if (callback) {
|
popup.inputValue = payloadData.inputValue;
|
||||||
popup.inputValue = payloadData.inputValue;
|
callback(popup);
|
||||||
callback(popup);
|
}
|
||||||
}
|
},
|
||||||
}
|
}),
|
||||||
}),
|
apiCallback({
|
||||||
apiCallback({
|
type: "menuItemClicked",
|
||||||
type: "menuItemClicked",
|
typeChecker: isMenuItemClickedEvent,
|
||||||
typeChecker: isMenuItemClickedEvent,
|
callback: (event) => {
|
||||||
callback: event => {
|
const callback = menuCallbacks.get(event.menuItem);
|
||||||
const callback = menuCallbacks.get(event.menuItem);
|
if (callback) {
|
||||||
if (callback) {
|
callback(event.menuItem);
|
||||||
callback(event.menuItem)
|
}
|
||||||
}
|
},
|
||||||
}
|
}),
|
||||||
})];
|
];
|
||||||
|
|
||||||
|
|
||||||
openPopup(targetObject: string, message: string, buttons: ButtonDescriptor[], input: boolean = false): Popup {
|
openPopup(targetObject: string, message: string, buttons: ButtonDescriptor[], input: boolean = false): Popup {
|
||||||
popupId++;
|
popupId++;
|
||||||
@ -67,41 +69,41 @@ class WorkAdventureUiCommands extends IframeApiContribution<WorkAdventureUiComma
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendToWorkadventure({
|
sendToWorkadventure({
|
||||||
'type': 'openPopup',
|
type: "openPopup",
|
||||||
'data': {
|
data: {
|
||||||
popupId,
|
popupId,
|
||||||
targetObject,
|
targetObject,
|
||||||
message,
|
message,
|
||||||
buttons: buttons.map((button) => {
|
buttons: buttons.map((button) => {
|
||||||
return {
|
return {
|
||||||
label: button.label,
|
label: button.label,
|
||||||
className: button.className
|
className: button.className,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
input
|
input
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
popups.set(popupId, popup)
|
popups.set(popupId, popup);
|
||||||
return popup;
|
return popup;
|
||||||
}
|
}
|
||||||
|
|
||||||
registerMenuCommand(commandDescriptor: string, callback: (commandDescriptor: string) => void) {
|
registerMenuCommand(commandDescriptor: string, callback: (commandDescriptor: string) => void) {
|
||||||
menuCallbacks.set(commandDescriptor, callback);
|
menuCallbacks.set(commandDescriptor, callback);
|
||||||
sendToWorkadventure({
|
sendToWorkadventure({
|
||||||
'type': 'registerMenuCommand',
|
type: "registerMenuCommand",
|
||||||
'data': {
|
data: {
|
||||||
menutItem: commandDescriptor
|
menutItem: commandDescriptor,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
displayBubble(): void {
|
displayBubble(): void {
|
||||||
sendToWorkadventure({ 'type': 'displayBubble', data: null });
|
sendToWorkadventure({ type: "displayBubble", data: null });
|
||||||
}
|
}
|
||||||
|
|
||||||
removeBubble(): void {
|
removeBubble(): void {
|
||||||
sendToWorkadventure({ 'type': 'removeBubble', data: null });
|
sendToWorkadventure({ type: "removeBubble", data: null });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user