Merge branch 'develop' of github.com:thecodingmachine/workadventure into develop

This commit is contained in:
_Bastler
2022-02-02 16:42:18 +01:00
14 changed files with 537 additions and 142 deletions
+43
View File
@@ -0,0 +1,43 @@
import { writable } from "svelte/store";
export interface ActionsMenuData {
playerName: string;
actions: { actionName: string; callback: Function }[];
}
function createActionsMenuStore() {
const { subscribe, update, set } = writable<ActionsMenuData | undefined>(undefined);
return {
subscribe,
initialize: (playerName: string) => {
set({
playerName,
actions: [],
});
},
addAction: (actionName: string, callback: Function) => {
update((data) => {
data?.actions.push({ actionName, callback });
return data;
});
},
removeAction: (actionName: string) => {
update((data) => {
const actionIndex = data?.actions.findIndex((action) => action.actionName === actionName);
if (actionIndex !== undefined && actionIndex != -1) {
data?.actions.splice(actionIndex, 1);
}
return data;
});
},
/**
* Hides menu
*/
clear: () => {
set(undefined);
},
};
}
export const actionsMenuStore = createActionsMenuStore();
+33 -10
View File
@@ -3,14 +3,17 @@ import { writable } from "svelte/store";
export function createColorStore() {
const { subscribe, set } = writable<number | undefined>(undefined);
let color: number | undefined = undefined;
let focused: boolean = false;
let followColor: number | undefined = undefined;
let apiColor: number | undefined = undefined;
let pointedByPointer: boolean = false;
let pointedByCharacter: boolean = false;
const updateColor = () => {
if (focused) {
if (pointedByPointer || pointedByCharacter) {
set(0xffff00);
} else {
set(color);
set(followColor ?? apiColor);
}
};
@@ -18,22 +21,42 @@ export function createColorStore() {
subscribe,
pointerOver() {
focused = true;
pointedByPointer = true;
updateColor();
},
pointerOut() {
focused = false;
pointedByPointer = false;
updateColor();
},
setColor(newColor: number) {
color = newColor;
characterCloseBy() {
pointedByCharacter = true;
updateColor();
},
removeColor() {
color = undefined;
characterFarAway() {
pointedByCharacter = false;
updateColor();
},
setFollowColor(newColor: number) {
followColor = newColor;
updateColor();
},
removeFollowColor() {
followColor = undefined;
updateColor();
},
setApiColor(newColor: number) {
apiColor = newColor;
updateColor();
},
removeApiColor() {
apiColor = undefined;
updateColor();
},
};