Skip to content

Commit

Permalink
Merge pull request #3187 from thecodingmachine/export_config_types_in…
Browse files Browse the repository at this point in the history
…_iframe_api

Export config types in scripting API
  • Loading branch information
moufmouf committed Apr 14, 2023
2 parents 0d202bb + 4ea2b7c commit 9b17720
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion play/package.json
Expand Up @@ -21,7 +21,7 @@
"typecheck": "cross-env tsc --noEmit",
"profile": "tsc && node --prof ./dist/server.js",
"build-iframe-api": "vite --config iframe-api.vite.config.ts build",
"watch-iframe-api": "npm run build-iframe-api --watch",
"watch-iframe-api": "npm run build-iframe-api -- --watch",
"build-typings": "cross-env tsc --project tsconfig-for-iframe-api-typings.json",
"precommit": "lint-staged",
"test": "vitest",
Expand Down
8 changes: 4 additions & 4 deletions play/src/front/Api/Events/IframeEvent.ts
Expand Up @@ -28,7 +28,7 @@ import { isMovePlayerToEventAnswer } from "./MovePlayerToEventAnswer";
import { isAddActionsMenuKeyToRemotePlayerEvent } from "./AddActionsMenuKeyToRemotePlayerEvent";
import { isRemoveActionsMenuKeyFromRemotePlayerEvent } from "./RemoveActionsMenuKeyFromRemotePlayerEvent";
import { isSetAreaPropertyEvent } from "./SetAreaPropertyEvent";
import { isCreateUIWebsiteEvent, isModifyUIWebsiteEvent, isUIWebsite } from "./Ui/UIWebsite";
import { isCreateUIWebsiteEvent, isModifyUIWebsiteEvent, isUIWebsiteEvent } from "./Ui/UIWebsiteEvent";
import { isAreaEvent, isCreateAreaEvent } from "./CreateAreaEvent";
import { isUserInputChatEvent } from "./UserInputChatEvent";
import { isEnterLeaveEvent } from "./EnterLeaveEvent";
Expand Down Expand Up @@ -544,19 +544,19 @@ export const iframeQueryMapTypeGuards = {
},
openUIWebsite: {
query: isCreateUIWebsiteEvent,
answer: isUIWebsite,
answer: isUIWebsiteEvent,
},
closeUIWebsite: {
query: z.string(),
answer: z.undefined(),
},
getUIWebsites: {
query: z.undefined(),
answer: z.array(isUIWebsite),
answer: z.array(isUIWebsiteEvent),
},
getUIWebsiteById: {
query: z.string(),
answer: isUIWebsite,
answer: isUIWebsiteEvent,
},
enablePlayersTracking: {
query: isEnablePlayersTrackingEvent,
Expand Down
Expand Up @@ -61,7 +61,7 @@ export const isModifyUIWebsiteEvent = z.object({

export type ModifyUIWebsiteEvent = z.infer<typeof isModifyUIWebsiteEvent>;

export const isUIWebsite = z.object({
export const isUIWebsiteEvent = z.object({
id: z.string(),
url: z.string(),
visible: z.boolean(),
Expand All @@ -72,4 +72,4 @@ export const isUIWebsite = z.object({
margin: isUIWebsiteMargin.partial().optional(),
});

export type UIWebsite = z.infer<typeof isUIWebsite>;
export type UIWebsiteEvent = z.infer<typeof isUIWebsiteEvent>;
6 changes: 3 additions & 3 deletions play/src/front/Api/Iframe/Ui/UIWebsite.ts
Expand Up @@ -6,8 +6,8 @@ import type {
UIWebsiteSize,
ViewportPositionHorizontal,
ViewportPositionVertical,
UIWebsite as UIWebsiteCore,
} from "../../Events/Ui/UIWebsite";
UIWebsiteEvent,
} from "../../Events/Ui/UIWebsiteEvent";
import { IframeApiContribution, queryWorkadventure, sendToWorkadventure } from "../IframeApiContribution";

class UIWebsitePositionInternal {
Expand Down Expand Up @@ -200,7 +200,7 @@ export class UIWebsite {
private _size: UIWebsiteSizeInternal;
private _margin: UIWebsiteMarginInternal;

constructor(config: UIWebsiteCore) {
constructor(config: UIWebsiteEvent) {
this.id = config.id;
this._url = config.url;
this._visible = config.visible ?? true;
Expand Down
2 changes: 1 addition & 1 deletion play/src/front/Api/IframeListener.ts
Expand Up @@ -28,7 +28,7 @@ import type { AddActionsMenuKeyToRemotePlayerEvent } from "./Events/AddActionsMe
import type { ActionsMenuActionClickedEvent } from "./Events/ActionsMenuActionClickedEvent";
import type { RemoveActionsMenuKeyFromRemotePlayerEvent } from "./Events/RemoveActionsMenuKeyFromRemotePlayerEvent";
import type { SetAreaPropertyEvent } from "./Events/SetAreaPropertyEvent";
import type { ModifyUIWebsiteEvent } from "./Events/Ui/UIWebsite";
import type { ModifyUIWebsiteEvent } from "./Events/Ui/UIWebsiteEvent";
import type { ModifyAreaEvent } from "./Events/CreateAreaEvent";
import type { AskPositionEvent } from "./Events/AskPositionEvent";
import type { PlayerInterface } from "../Phaser/Game/PlayerInterface";
Expand Down
4 changes: 2 additions & 2 deletions play/src/front/Components/UI/Website/UIWebsiteLayer.svelte
@@ -1,9 +1,9 @@
<script lang="ts">
import { onDestroy, onMount } from "svelte";
import type { UIWebsite } from "../../../Api/Events/Ui/UIWebsite";
import type { UIWebsiteEvent } from "../../../Api/Events/Ui/UIWebsiteEvent";
import { iframeListener } from "../../../Api/IframeListener";
export let uiWebsite: UIWebsite;
export let uiWebsite: UIWebsiteEvent;
let main: HTMLDivElement;
const iframe = document.createElement("iframe");
iframe.id = `ui-website-${uiWebsite.id}`;
Expand Down
12 changes: 6 additions & 6 deletions play/src/front/Phaser/Game/UI/UIWebsiteManager.ts
@@ -1,5 +1,5 @@
import { get } from "svelte/store";
import type { CreateUIWebsiteEvent, ModifyUIWebsiteEvent, UIWebsite } from "../../../Api/Events/Ui/UIWebsite";
import type { CreateUIWebsiteEvent, ModifyUIWebsiteEvent, UIWebsiteEvent } from "../../../Api/Events/Ui/UIWebsiteEvent";
import { iframeListener } from "../../../Api/IframeListener";
import { v4 as uuidv4 } from "uuid";
import { uiWebsitesStore } from "../../../Stores/UIWebsiteStore";
Expand Down Expand Up @@ -64,8 +64,8 @@ class UIWebsiteManager {
});
}

public open(websiteConfig: CreateUIWebsiteEvent): UIWebsite {
const newWebsite: UIWebsite = {
public open(websiteConfig: CreateUIWebsiteEvent): UIWebsiteEvent {
const newWebsite: UIWebsiteEvent = {
...websiteConfig,
id: uuidv4(),
visible: websiteConfig.visible ?? true,
Expand All @@ -76,11 +76,11 @@ class UIWebsiteManager {
return newWebsite;
}

public getAll(): UIWebsite[] {
public getAll(): UIWebsiteEvent[] {
return get(uiWebsitesStore);
}

public getById(websiteId: string): UIWebsite | undefined {
public getById(websiteId: string): UIWebsiteEvent | undefined {
return get(uiWebsitesStore).find((currentWebsite) => currentWebsite.id === websiteId);
}

Expand All @@ -95,7 +95,7 @@ class UIWebsiteManager {
}

public closeAll() {
get(uiWebsitesStore).forEach((uiWebsite: UIWebsite) => {
get(uiWebsitesStore).forEach((uiWebsite: UIWebsiteEvent) => {
uiWebsitesStore.remove(uiWebsite);
});
}
Expand Down
12 changes: 6 additions & 6 deletions play/src/front/Stores/UIWebsiteStore.ts
@@ -1,22 +1,22 @@
import { writable } from "svelte/store";
import type { UIWebsite } from "../Api/Events/Ui/UIWebsite";
import type { UIWebsiteEvent } from "../Api/Events/Ui/UIWebsiteEvent";

function createUIWebsiteStore() {
const { subscribe, update, set } = writable(Array<UIWebsite>());
const { subscribe, update, set } = writable(Array<UIWebsiteEvent>());

set(Array<UIWebsite>());
set(Array<UIWebsiteEvent>());

return {
subscribe,
add: (uiWebsite: UIWebsite) => {
add: (uiWebsite: UIWebsiteEvent) => {
update((currentArray) => [...currentArray, uiWebsite]);
},
update: (uiWebsite: UIWebsite) => {
update: (uiWebsite: UIWebsiteEvent) => {
update((currentArray) =>
currentArray.map((currentWebsite) => (currentWebsite.id === uiWebsite.id ? uiWebsite : currentWebsite))
);
},
remove: (uiWebsite: UIWebsite) => {
remove: (uiWebsite: UIWebsiteEvent) => {
update((currentArray) => currentArray.filter((currentWebsite) => currentWebsite.id !== uiWebsite.id));
},
};
Expand Down
16 changes: 16 additions & 0 deletions play/src/iframe_api.ts
Expand Up @@ -28,6 +28,22 @@ import type { Popup } from "./front/Api/Iframe/Ui/Popup";
import type { Sound } from "./front/Api/Iframe/Sound/Sound";
import { answerPromises, queryWorkadventure } from "./front/Api/Iframe/IframeApiContribution";
import camera from "./front/Api/Iframe/camera";
export type {
CreateUIWebsiteEvent,
ModifyUIWebsiteEvent,
UIWebsiteEvent,
UIWebsiteCSSValue,
UIWebsiteMargin,
UIWebsitePosition,
UIWebsiteSize,
ViewportPositionHorizontal,
ViewportPositionVertical,
} from "./front/Api/Events/Ui/UIWebsiteEvent";
export type {
CreateEmbeddedWebsiteEvent,
ModifyEmbeddedWebsiteEvent,
Rectangle,
} from "./front/Api/Events/EmbeddedWebsiteEvent";
export type { UIWebsite } from "./front/Api/Iframe/Ui/UIWebsite";
export type { Menu } from "./front/Api/Iframe/Ui/Menu";
export type { ActionMessage } from "./front/Api/Iframe/Ui/ActionMessage";
Expand Down

0 comments on commit 9b17720

Please sign in to comment.