Building action.cmd[] and editing of command, arg. Order of commands can't be edited yet

This commit is contained in:
Tamius Han 2019-03-10 16:31:50 +01:00
parent 76ff4da77f
commit 22c44a3972
5 changed files with 136 additions and 61 deletions

View File

@ -8,23 +8,27 @@
</div> </div>
<CommandChain class="w100" <CommandChain class="w100"
:command="action.command" :command="action.cmd"
@new-command="addNewCommand()" @new-command="addNewCommand()"
@edit="editCommand"
@delete="deleteCommand"
> >
</CommandChain> </CommandChain>
<pre>
Action:
{{action}}
----
</pre>
<CommandAddEdit class="w100" <CommandAddEdit class="w100"
v-if="addEditCommand" v-if="addEditCommand"
:command="currentCmd" :action="currentCmd"
@set-command="updateCommand" @set-command="updateCommand"
@close-popup="addEditCommand=false" @close-popup="addEditCommand=false"
> >
</CommandAddEdit> </CommandAddEdit>
<pre>
----- [ raw action data ] -----
Action:
{{action}}
--- [ end raw action data ] ---
</pre>
<div class="flex flex-column"> <div class="flex flex-column">
<div class="flex flex-row"> <div class="flex flex-row">
<div class="flex label-secondary form-label"> <div class="flex label-secondary form-label">
@ -138,6 +142,11 @@ export default {
} }
} }
}, },
watch: {
action: {
deep: true,
}
},
methods: { methods: {
parseActionShortcut(action) { parseActionShortcut(action) {
return KeyboardShortcutParser.parseShortcut(action.shortcut[0]); return KeyboardShortcutParser.parseShortcut(action.shortcut[0]);
@ -166,9 +175,19 @@ export default {
}, },
addNewCommand() { addNewCommand() {
this.currentCmdIndex = -1; this.currentCmdIndex = -1;
this.currentCmd = undefined;
this.addEditCommand = true; this.addEditCommand = true;
console.log("adding command") console.log("adding command")
}, },
editCommand(index) {
this.currentCmdIndex = index;
this.currentCmd = this.action.cmd[index];
this.addEditCommand = true;
console.log("EDITING COMMAND")
},
deleteCommand(index) {
this.action.cmd.splice(index,1);
},
updateCommand(action, arg) { updateCommand(action, arg) {
this.addEditCommand = false; this.addEditCommand = false;
if (this.currentCmdIndex < 0) { if (this.currentCmdIndex < 0) {
@ -182,6 +201,9 @@ export default {
arg: arg, arg: arg,
}; };
} }
this.action = JSON.parse(JSON.stringify(this.action));
// this.$nextTick(function() {this.$forceUpdate()});
} }
} }
} }

View File

@ -1,11 +1,6 @@
<template> <template>
<div class=""> <div class="">
Values:
<div class="window-content"> <div class="window-content">
<pre>{{action}}</pre>
<pre>{{selectedAction}}</pre>
<pre>{{selectedArgument}}</pre>
<!-- ACTION SELECT --> <!-- ACTION SELECT -->
<div class="flex flex-row"> <div class="flex flex-row">
<div class="flex label-secondary form-label"> <div class="flex label-secondary form-label">
@ -15,8 +10,10 @@
</div> </div>
<div class="flex flex-grow flex-input"> <div class="flex flex-grow flex-input">
<select class="" <select class=""
:value="selectedAction"
@change="setAction($event.target.value)" @change="setAction($event.target.value)"
> >
<option :value="undefined" selected disabled>Select ...</option>
<option v-for="(action, key) in ActionList" <option v-for="(action, key) in ActionList"
:value="key" :value="key"
:key="key" :key="key"
@ -37,8 +34,10 @@
</div> </div>
<div class="flex flex-grow flex-input"> <div class="flex flex-grow flex-input">
<select class="" <select class=""
:value="selectedArgument ? selectedArgument.arg : undefined"
@change="setArgument($event.target.value)" @change="setArgument($event.target.value)"
> >
<option :value="undefined" selected disabled>Select ...</option>
<option v-for="(arg, key) of ActionList[selectedAction].args" <option v-for="(arg, key) of ActionList[selectedAction].args"
:key="key" :key="key"
:value="key" :value="key"
@ -79,6 +78,20 @@
Save Save
</div> </div>
</div> </div>
<pre>
----- [ COMMAND DATA ] -----
:: Action:
{{action}}
:: Selected Action:
{{selectedAction}}
:: Selected Argumennt:
{{selectedArgument}}
--- [ END COMMAND DATA ] ---
</pre>
</div> </div>
</template> </template>
@ -91,19 +104,28 @@ export default {
return { return {
Stretch: Stretch, Stretch: Stretch,
ActionList: ActionList, ActionList: ActionList,
selectedAction: this.action ? action.action : undefined, selectedAction: undefined,
selectedArgument: this.action ? { selectedArgument: undefined,
name: ActionList[action.action].args.find(x => x.arg === action.arg) || ActionList[action.action].args.find(x => x.customArg), customArgumentValue: undefined
arg: action.arg
} : undefined,
customArgumentValue: this.action ? action.arg : undefined
} }
}, },
created () { created () {
console.log("this.actionList", ActionList, this.ActionList) if (this.action) {
for(const a in ActionList) { this.selectedAction = this.action.cmd;
console.log(a); this.selectedArgument = {
name: ActionList[this.action.cmd].args.find(x => x.arg === this.action.arg) || ActionList[this.action.cmd].args.find(x => x.customArg),
arg: this.action.arg
} }
this.customArgumentValue = this.action.arg;
}
// console.log("this.actionList", ActionList, this.ActionList)
// for(const a in ActionList) {
// console.log(a);
// }
},
mounted() {
}, },
props: { props: {
action: Object, action: Object,

View File

@ -1,39 +1,37 @@
<template> <template>
<div class="block-main"> <div class="block-main">
<div class="button-main">
<div v-if="!first" <div class="button-action-display">
class="prev" {{ActionList[action.cmd].name}}:&nbsp;{{
@click="emit('move-left')" /*ActionList[action.cmd].args.find(x => x.arg === action.arg).arg ||*/ action.arg
}}
</div>
<div class="actions flex flex-row flex-center flex-cross-center">
<div v-if="!first || true"
class="flex order-button"
@click="$emit('move-left')"
> >
&lt; &lt;
</div> </div>
<div class="flex flex-grow command-action"
<div class="button-main">
<div class="button-action-display">
{{ActionList[action.action].name}}: {{
ActionList[action.action].args.find(x => x.arg === action.arg) || action.arg
}}
</div>
<div class="actions flex flex-row">
<div class="flex flex-grow"
@click="$emit('delete')" @click="$emit('delete')"
> >
🗙 🗙
</div> </div>
<div class="flex flex-grow" <div class="flex flex-grow command-action"
@click="$emit('edit')" @click="$emit('edit')"
> >
🖉 🖉
</div> </div>
</div> <div v-if="!last || true"
</div> class="flex order-button"
<div v-if="!last"
class="next"
@click="$emit('move-right')" @click="$emit('move-right')"
> >
&gt; &gt;
</div> </div>
</div>
</div>
</div> </div>
</template> </template>
@ -57,7 +55,9 @@ export default {
}, },
methods: { methods: {
parseActionShortcut(action) { parseActionShortcut(action) {
if (action.shortcut) {
return KeyboardShortcutParser.parseShortcut(action.shortcut[0]); return KeyboardShortcutParser.parseShortcut(action.shortcut[0]);
}
}, },
setAction(cmd) { setAction(cmd) {
console.log("SETTING ACTION", cmd); console.log("SETTING ACTION", cmd);
@ -70,13 +70,36 @@ export default {
this.selectedArgument = arg; this.selectedArgument = arg;
this.customArgumentValue = undefined; this.customArgumentValue = undefined;
}, },
emitCommand() { // emitCommand() {
this.$emit( // this.$emit(
'set-command', // 'set-command',
this.selectedAction, // this.selectedAction,
this.customArgumentValue ? this.customArgumentValue : this.selectedArgument.arg // this.customArgumentValue ? this.customArgumentValue : this.selectedArgument.arg
); // );
} // }
} }
} }
</script> </script>
<style lang="scss" scoped>
@import './../../../res/css/colors';
.block-main {
border: 1px solid $primary-color;
min-width: 10rem;
padding-top: 0.1rem;
margin-left: 0.5rem;
margin-right: 0.5rem;
}
.button-action-display, .command-action, .order-button {
display: block;
padding-left: 1rem;
padding-right: 1rem;
text-align: center;
}
.button-action-display {
padding-top: 0.1rem;
}
</style>

View File

@ -1,22 +1,20 @@
<template> <template>
<div class=""> <div class="command-chain flex flex-row flex-center flex-cross-center">
{{command}} <!-- {{command}} -->
<div class="flex flex-row"> <div class="flex flex-row flex-center flex-cross-center">
<CommandBlock v-for="(cmd, index) of command" <CommandBlock v-for="(cmd, index) of command"
:key="index" :key="index"
:command="cmd" :action="cmd"
first
last
@edit="$emit('edit', index)" @edit="$emit('edit', index)"
@delete="$emit('delete', index)" @delete="$emit('delete', index)"
@move-left="$emit('move-left', index)" @move-left="$emit('move-left', index)"
@move-right="$emit('move-left', (index + 1))" @move-right="$emit('move-left', (index + 1))"
> >
</CommandBlock> </CommandBlock>
<div class="new-command" <div class="new-command h100 flex flex-column flex-center flex-cross-center"
@click="$emit('new-command')" @click="$emit('new-command')"
> >
+ <div><b>+</b></div>
</div> </div>
</div> </div>
</div> </div>
@ -37,7 +35,17 @@ export default {
'command' 'command'
], ],
methods: { methods: {
} }
} }
</script> </script>
<style lang="scss" scoped>
@import '../../../res/css/colors';
.new-command {
color: $primary-color;
height: 100%;
padding-left: 2rem;
padding-right: 2rem;
font-size: 2rem;
}
</style>

View File

@ -25,7 +25,7 @@ export default {
} }
}, },
created(){ created(){
if (shortcut) { if (this.shortcut) {
this.shortcutText = KeyboardShortcutParser.parseShortcut(shortcut); this.shortcutText = KeyboardShortcutParser.parseShortcut(shortcut);
} }
}, },