Skip to content

Commit

Permalink
feat: random action (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
skarab42 authored Jul 25, 2021
1 parent 71143fd commit eaf4847
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
13 changes: 12 additions & 1 deletion app/server/libs/twitch/pushActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ function getValidEvents(widget, eventName) {
module.exports = function pushActions(eventName, eventProps) {
logger.debug("pushActions", { eventName, eventProps });

const randomActions = [];

stores.panels.get("panels").forEach(({ widgets }) => {
widgets.forEach((widget) => {
if (!widget.component) return;
Expand All @@ -63,8 +65,17 @@ module.exports = function pushActions(eventName, eventProps) {
if (isInvalidShortcut(event, eventProps)) return;
if (isInvalidRules(event, eventProps)) return;

push({ type, widget, event, eventProps });
if (widget.random) {
randomActions.push({ type, widget, event, eventProps });
} else {
push({ type, widget, event, eventProps });
}
});
});
});

if (randomActions.length) {
const random = Math.floor(Math.random() * randomActions.length);
push(randomActions[random]);
}
};
3 changes: 2 additions & 1 deletion app/static/locales/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@
"source": "source",
"test": "test",
"port": "port",
"password": "password"
"password": "password",
"random": "random"
},
"obs": {
"scene-list": "OBS | Scene list",
Expand Down
3 changes: 2 additions & 1 deletion app/static/locales/es/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@
"source": "fuente",
"test": "test",
"port": "puerto",
"password": "contraseña"
"password": "contraseña",
"random": "al azar"
},
"obs": {
"scene-list": "OBS | Lista de escenas",
Expand Down
3 changes: 2 additions & 1 deletion app/static/locales/fr/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@
"source": "source",
"test": "test",
"port": "port",
"password": "mot de passe"
"password": "mot de passe",
"random": "aléatoire"
},
"obs": {
"scene-list": "OBS | Liste des scènes",
Expand Down
10 changes: 10 additions & 0 deletions front-src/client/components/Panels/Panel/Widget/Edit/Action.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import Button from "@/components/UI/Button.svelte";
import Select from "@/components/UI/Select.svelte";
import { findSpaceForWidget } from "@/stores/panels";
import Checkbox from "@/components/UI/Checkbox.svelte";
import MdDelete from "svelte-icons/md/MdDeleteForever.svelte";
import ConfirmModal from "@/components/UI/ConfirmModal.svelte";
Expand Down Expand Up @@ -97,6 +98,10 @@
function onRemoveAction() {
removeActionModal = true;
}
function onCheckboxChange({ target }) {
change("random", target.checked);
}
</script>

{#if component}
Expand All @@ -113,6 +118,11 @@
label="{_('words.trigger')}"
on:change="{onTriggerChange}"
/>
<Checkbox
on:change="{onCheckboxChange}"
checked="{widget.random}"
label="{_('words.random')}"
/>
{/if}
{#if config.hasEvent}
<ActionEvents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
}
async function onChange({ detail }) {
console.log(detail);
if (detail.key === "shortcutName") {
await onShortcutChange(detail.value);
return;
Expand Down

0 comments on commit eaf4847

Please sign in to comment.