Skip to content

Commit

Permalink
Fixes/trigger random with queue (#505)
Browse files Browse the repository at this point in the history
* fix waitUntilDone checks for the targetScreen

* QoL: Recipe: Action List Config - now has a button to open up the Action Settings

* Fix up the Action State Debug View
  • Loading branch information
negue committed Sep 27, 2022
1 parent abdd461 commit 5fb96be
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 37 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
## 2022.1 to be released
## 2022.1-rc1 to be released

### Feature
### Quality of Life

* [x] Recipe: Action List Config - now has a button to open up the Action Settings

### Fixes

* [ ] Ability to re-authenticate even when you are not in the normal ports
* [x] Trigger random using a queue on recipe and each item - could end up in not triggering a second time

## 2022.1-beta-4

Expand Down
1 change: 1 addition & 0 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This list might be changed in future, depending on the amount of work that needs
* [ ] Dependency: Twitch Scope System - for Scripts and Command Block Checks
* [ ] Recipe: Obs Command Block: Set Volume
* [ ] Dependency: Command Block Settings for Numbers with a Range Config
* [ ] Ability to re-authenticate even when you are not in the normal ports

### Misc

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ export class ActionActivityService {
// Load State once
this.memeboxApi.get<ActionStateEntries>(`${ENDPOINTS.ACTION_ACTIVITY.PREFIX}${ENDPOINTS.ACTION_ACTIVITY.CURRENT}`)
.then( actionStateInitialValue => {
this.activityStore.update(() => actionStateInitialValue);
this.activityStore.update((currentState) =>
{
return {
actionState: {
...currentState.actionState,
...actionStateInitialValue,
},
screenState: currentState.screenState
}
});
});

const actionStateWSHandler = new WebsocketHandler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,21 @@
<mat-card-header class="card__header">
<mat-card-title>{{ actionDictionary[actionEntry.actionId]?.name }}</mat-card-title>

<button mat-icon-button class="remove-icon"
matTooltip="Remove" *ngIf="actionListTypeSelect.value !== 'byTag'"
(click)="removeActionEntry(actionList, actionEntry)">
<mat-icon svgIcon="delete"></mat-icon>
</button>

<div class="icon-list">
<button mat-icon-button
matTooltip="edit Action"
color="accent"
(click)="openActionEditDialog(actionDictionary[actionEntry.actionId])">
<mat-icon svgIcon="settings"></mat-icon>
</button>
<button mat-icon-button
matTooltip="Remove" *ngIf="actionListTypeSelect.value !== 'byTag'"
color="warn"
(click)="removeActionEntry(actionList, actionEntry)">
<mat-icon svgIcon="delete"></mat-icon>
</button>
</div>
</mat-card-header>

<app-action-preview [action]="actionDictionary[actionEntry.actionId]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
width: 0;
}

.mat-icon-button.remove-icon {
.icon-list {
position: absolute;
top: 0.25rem;
right: 1rem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export class ActionListSettingsComponent {
actionList.splice(indexOf, 1);
}

openActionEditDialog (action: Action) {
this.dialogService.showMediaEditDialog({
actionToEdit: action
});
}

onTagSelected($event: string) {
this.updateConfigPayload({
actionsByTag: $event
Expand Down
4 changes: 2 additions & 2 deletions server/providers/actions/action-active-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class ActionActiveState {
return this._state$
.pipe(
filter(( state) => {
return isActionCurrently(state, ActionStateEnum.Active, actionId, screenId ?? actionId);
return isActionCurrently(state, ActionStateEnum.Active, actionId, screenId);
}),
map(_ => {}),
take(1)
Expand All @@ -98,7 +98,7 @@ export class ActionActiveState {
return this._state$
.pipe(
filter(( state) => {
const done = isActionCurrently(state, ActionStateEnum.Done, actionId, screenId ?? actionId);
const done = isActionCurrently(state, ActionStateEnum.Done, actionId, screenId);

return done;
}),
Expand Down
44 changes: 23 additions & 21 deletions server/providers/actions/action-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,36 @@ export class ActionQueue {

const actionConfig = fullState.clips[triggerAction.id];

if (actionConfig.queueName) {
if (isVisibleMedia(actionConfig.type)) {
const currentState = this.actionState.getActiveStateEntry(triggerAction.id, triggerAction.targetScreen);
const mediaInScreenConfig = fullState.screen[triggerAction.targetScreen]?.clips[triggerAction.id];
if (!actionConfig.queueName) {
// no queue needed, "just do it"
await this.executeTriggerWithoutQueueAndWait(triggerAction);
return;
}

const visibilityOfOverrides =currentState?.currentOverrides?.screenMedia?.visibility;
const visibilityOfMedia = mediaInScreenConfig?.visibility;
// Special: handle already visible / toggled media
if (isVisibleMedia(actionConfig.type)) {
const currentState = this.actionState.getActiveStateEntry(triggerAction.id, triggerAction.targetScreen);
const mediaInScreenConfig = fullState.screen[triggerAction.targetScreen]?.clips[triggerAction.id];

const currentVisibilityConfig = visibilityOfOverrides ?? visibilityOfMedia;
const visibilityOfOverrides = currentState?.currentOverrides?.screenMedia?.visibility;
const visibilityOfMedia = mediaInScreenConfig?.visibility;

if (currentState?.state === ActionStateEnum.Active && currentVisibilityConfig === VisibilityEnum.Toggle) {
await this.executeTriggerWithoutQueueAndWait(triggerAction);
return;
}
const currentVisibilityConfig = visibilityOfOverrides ?? visibilityOfMedia;

if (currentState?.state === ActionStateEnum.Active && currentVisibilityConfig === VisibilityEnum.Toggle) {
await this.executeTriggerWithoutQueueAndWait(triggerAction);
return;
}
}

const subject = this.createOrGetQueueSubject(actionConfig.queueName);
subject.next(triggerAction);
const subject = this.createOrGetQueueSubject(actionConfig.queueName);

await this._queueDone$.pipe(
filter(uniqueDone => uniqueDone === triggerAction.uniqueId),
take(1),
).toPromise();
} else {
// no queue needed, "just do it"
subject.next(triggerAction);

await this.executeTriggerWithoutQueueAndWait(triggerAction);
}
await this._queueDone$.pipe(
filter(uniqueDone => uniqueDone === triggerAction.uniqueId),
take(1)
).toPromise();
}

private createOrGetQueueSubject (queueName: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {ActivityQueries, AppQueries, AppService} from "@memebox/app-state";
import {filter, map} from "rxjs/operators";
import {ACTION_TYPE_INFORMATION, ActionStateEnum, ActionType} from "@memebox/contracts";
import {combineLatest} from "rxjs";
import {ActionStateEntry} from "@memebox/shared-state";

function actionStateEnumToString (activity: ActionStateEnum) {
switch (activity) {
Expand Down Expand Up @@ -31,23 +32,23 @@ export class ActivityStateComponent {
)
]).pipe(
map(([activityState, actionMap]) => {
const actionKeys = Object.keys(activityState);
const actionKeys = Object.keys(activityState.actionState ?? {});

return actionKeys.map(actionId => {
const statesOfAction = activityState[actionId];
const statesOfAction: Record<string, ActionStateEntry> = activityState.actionState[actionId];
const keysOfStates = Object.keys(statesOfAction);

let activityOfAction = '';

if (keysOfStates.includes(actionId)) {
activityOfAction = actionStateEnumToString(statesOfAction[actionId])
activityOfAction = actionStateEnumToString(statesOfAction[actionId].state)
}

const stateInScreen = keysOfStates.filter(key => key !== actionId)
.map(key => {
return {
screenId: key,
state: actionStateEnumToString(statesOfAction[key])
state: actionStateEnumToString(statesOfAction[key].state)
}
});

Expand Down

0 comments on commit 5fb96be

Please sign in to comment.