Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature checklist from #73 #94

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions configschema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ export interface Configschema {
key: string;
}[];
} | null;
checklist: {
enabled: boolean;
items?: string[] | null;
forceCheckBeforeStartTimer: boolean;
};
}
35 changes: 34 additions & 1 deletion configschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,45 @@
"type": "null"
}
]
},
"checklist": {
"type": "object",
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean",
"default": false
},
"items": {
"oneOf": [
{
"type": "array",
"uniqueItems": true,
"items": {
"type": "string"
}
},
{
"type": "null"
}
]
},
"forceCheckBeforeStartTimer": {
"type": "boolean",
"default": false
}
},
"required": [
"enabled",
"forceCheckBeforeStartTimer"
]
}
},
"required": [
"language",
"twitch",
"schedule",
"oengus"
"oengus",
"checklist"
]
}
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@
"width": 3,
"file": "alert-dialog.html",
"dialog": true
},
{
"name": "checklist",
"title": "Checklist",
"file": "checklist.html",
"width": 3
}
]
}
Expand Down
11 changes: 11 additions & 0 deletions schemas/checklist.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* tslint:disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/

export type Checklist = {
name: string;
complete: boolean;
}[];
14 changes: 14 additions & 0 deletions schemas/checklist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "http://json-schema.org/draft-04/schema",

"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"name": {"type": "string"},
"complete": {"type": "boolean"}
},
"required": ["name", "complete"]
}
}
1 change: 1 addition & 0 deletions schemas/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './checklist';
export * from './defaultSetupTime';
export * from './horaroImportSavedOpts';
export * from './horaroImportStatus';
Expand Down
2 changes: 2 additions & 0 deletions src/dashboard/_misc/components/RunList/RunPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ export default class extends Vue {
dialog.openDialog({ name: 'NoTwitchGame' });
}
}

await nodecg.sendMessage('resetChecklist');
} catch (err) {
// catch
}
Expand Down
17 changes: 17 additions & 0 deletions src/dashboard/checklist/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint no-new: off, @typescript-eslint/explicit-function-return-type: off */

import Vue from 'vue';
import i18n from '../_misc/i18n';
import vuetify from '../_misc/vuetify';
import App from './main.vue';
import waitForReplicants from './store';

waitForReplicants().then((store) => {
new Vue({
vuetify,
i18n,
store,
el: '#App',
render: (h) => h(App),
});
});
75 changes: 75 additions & 0 deletions src/dashboard/checklist/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<i18n>
{
"en": {
"panelTitle": "Checklist",
"notEnabled": "Checklist is not enabled.",
"emptyItems": "Checklist is empty."
},
"ja": {
"panelTitle": "チェックリスト",
"notEnabled": "チェックリストが有効になっていません。",
"emptyItems": "チェックリストが空です。"
}
}
</i18n>

<template>
<v-app>
<div v-if="!config.enabled">
{{ $t('notEnabled') }}
</div>
<div v-else>
<div v-if="checklist.length === 0">
{{ $t('emptyItems') }}
</div>
<v-switch
v-for="checkbox in checklist"
:key="checkbox.name"
:label="checkbox.name"
:value="true"
:input-value="checkbox.complete"
@change="toggleCheckbox(checkbox.name, $event !== null)"
/>
</div>
</v-app>
</template>

<script lang="ts">
import { Vue, Component } from 'vue-property-decorator';
import { State } from 'vuex-class';
import { CheckList } from 'types';
import { Configschema } from 'configschema';

@Component({
components: {
},
})
export default class extends Vue {
@State checklist!: CheckList;

get config(): Configschema['checklist'] {
return (nodecg.bundleConfig as Configschema).checklist;
}

async toggleCheckbox(name: string, complete: boolean): Promise<void> {
try {
await nodecg.sendMessage('toggleCheckbox', { name, complete });
// checklist change successful
} catch (err) {
// catch
}
}

mounted(): void {
if (window.frameElement?.parentElement) {
window.frameElement.parentElement.setAttribute(
'display-title',
this.$t('panelTitle') as string,
);
}
}
}
</script>

<style scoped>
</style>
37 changes: 37 additions & 0 deletions src/dashboard/checklist/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import clone from 'clone';
import type { ReplicantBrowser } from 'nodecg/types/browser';
import type { Checklist } from 'schemas';
import Vue from 'vue';
import Vuex, { Store } from 'vuex';

Vue.use(Vuex);

// Replicants and their types
const reps: {
checklist: ReplicantBrowser<Checklist>;
[k: string]: ReplicantBrowser<unknown>;
} = {
checklist: nodecg.Replicant('checklist'),
};

const store = new Vuex.Store({
state: {
checklist: [] as Checklist,
},
mutations: {
setState(state, { name, val }): void {
Vue.set(state, name, val);
},
},
});

Object.keys(reps).forEach((key) => {
reps[key].on('change', (val) => {
store.commit('setState', { name: key, val: clone(val) });
});
});

export default async (): Promise<Store<Record<string, unknown>>> => {
await NodeCG.waitForReplicants(...Object.keys(reps).map((key) => reps[key]));
return store;
};
2 changes: 2 additions & 0 deletions src/dashboard/run-player/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export default class extends Vue {
if (confirm) {
try {
await nodecg.sendMessage('returnToStart');
await nodecg.sendMessage('resetChecklist');
} catch (err) {
// run removal unsuccessful
}
Expand All @@ -141,6 +142,7 @@ export default class extends Vue {
dialog.openDialog({ name: 'NoTwitchGame' });
}
}
await nodecg.sendMessage('resetChecklist');
} catch (err) {
// run change unsuccessful
}
Expand Down
29 changes: 26 additions & 3 deletions src/dashboard/timer/components/StartButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<template v-slot:activator="{ on }">
<span v-on="on">
<v-btn
:disabled="state === 'finished'"
:disabled="state === 'finished' || (isEnabledForceCheck && !checklistComplete)"
@click="button"
>
<v-icon v-if="state === 'running'">
Expand All @@ -42,18 +42,41 @@
</template>

<script lang="ts">
import { Vue, Component } from 'vue-property-decorator';
import { Vue, Component, Watch } from 'vue-property-decorator';
import { State } from 'vuex-class';
import { Timer } from 'schemas';
import { Timer, Checklist } from 'schemas';
import { Configschema } from 'configschema';

@Component
export default class extends Vue {
@State timer!: Timer;
@State checklist!: Checklist;

checklistComplete = false;

get state(): string {
return this.timer.state;
}

get config(): Configschema['checklist'] {
return (nodecg.bundleConfig as Configschema).checklist;
}

get isEnabledForceCheck(): boolean {
return this.config.enabled
&& this.checklist.length !== 0
&& this.config.forceCheckBeforeStartTimer;
}

@Watch('checklist', { immediate: true })
onChecklistChange(val: Checklist): void {
this.updateChecklistComplete(val);
}

updateChecklistComplete(checklist: Checklist): void {
this.checklistComplete = checklist.every((checkbox) => checkbox.complete);
}

async button(): Promise<void> {
try {
if (this.state === 'stopped' || this.state === 'paused') {
Expand Down
4 changes: 3 additions & 1 deletion src/dashboard/timer/store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import clone from 'clone';
import type { ReplicantBrowser } from 'nodecg/types/browser';
import type { RunDataActiveRun, Timer, TimerChangesDisabled } from 'schemas';
import type { RunDataActiveRun, Timer, TimerChangesDisabled, Checklist } from 'schemas';
import Vue from 'vue';
import Vuex, { Store } from 'vuex';

Expand All @@ -11,11 +11,13 @@ const reps: {
runDataActiveRun: ReplicantBrowser<RunDataActiveRun>;
timer: ReplicantBrowser<Timer>;
timerChangesDisabled: ReplicantBrowser<TimerChangesDisabled>;
checklist: ReplicantBrowser<Checklist>;
[k: string]: ReplicantBrowser<unknown>;
} = {
runDataActiveRun: nodecg.Replicant('runDataActiveRun'),
timer: nodecg.Replicant('timer'),
timerChangesDisabled: nodecg.Replicant('timerChangesDisabled'),
checklist: nodecg.Replicant('checklist'),
};

// Types for mutations below
Expand Down
Loading