partey_workadventure/maps/tests/AlterActionMenuApi/script.php
Piotr Hanusiak d4dcd0d5ce
Actions menu api (#1862)
* wip

* wip

* random action on click

* removing actions

* register single key per command use

* change removeActionsMenu action name

* fixed actions menu not hiding content properly:

* actions menu fix

* added mock Block Player action

* ActionsMenu buttons styling

* added displaying priority for menu actions

* moved utils actionMenu features to the UI

* import as a type:

* more object oriented style for API

* removed registered actions from RemotePlayer instance

* readme update

* Fixing typos / Improving wording

* added instructions on AlterActionsMenu test map

Co-authored-by: Hanusiak Piotr <piotr@ltmp.co>
Co-authored-by: David Négrier <d.negrier@thecodingmachine.com>
2022-03-14 10:15:10 +01:00

44 lines
1.5 KiB
PHP

<!doctype html>
<html lang="en">
<head>
<script src="<?php echo $_SERVER["FRONT_URL"] ?>/iframe_api.js"></script>
<script>
window.addEventListener('load', () => {
//@ts-ignore
WA.onInit().then(() => {
const addActionButton = document.getElementById('addActionButton');
let lastRemotePlayerClicked;
WA.ui.onRemotePlayerClicked.subscribe((remotePlayer) => {
lastRemotePlayerClicked = remotePlayer;
const action = remotePlayer.addAction('This will disappear!', () => {
console.log('You managed to click me, young hero');
});
window.setTimeout(
() => {
action.remove();
},
1000,
);
remotePlayer.addAction('Ask to tell a joke', () => {
console.log('I am NOT telling you a joke!');
});
});
addActionButton.addEventListener('click', () => {
const randomActionName = (Math.floor(Math.random() * 100)).toString();
action = lastRemotePlayerClicked?.addAction(randomActionName, () => {
console.log(`called action ${randomActionName}`);
});
});
});
})
</script>
</head>
<body>
<button id="addActionButton">Add Action</button>
</body>
</html>