-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDiceArea.vue
195 lines (171 loc) · 3.6 KB
/
DiceArea.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<template>
<div class="dice-area">
<div>
<div
v-show="draw"
:class="{ success: isSuccess, failure: isFailure, active: isActive }"
@click.stop="draw = false"
class="result"
>
{{ commandResult }}
</div>
</div>
<template v-for="(result, i) in target.drawables">
<Dice
v-if="draw"
:key="i"
:face="result.face"
:value="result.value"
@hide="draw = false"
/>
</template>
<audio preload>
<source :src="soundData" />
</audio>
</div>
</template>
<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import Dice from "./Dice.vue";
import soundData from "./assets/dice_roll.mp3";
@Component({
components: {
Dice
}
})
export default class DiceArea extends Vue {
data() {
return {
draw: false,
soundData: soundData,
target: []
};
}
mounted() {
this.$store.watch(
state => {
return state.readyAnimation;
},
val => {
if (val == false) {
this.playAnimation();
}
}
);
}
playAnimation() {
if (!this.playDiceAnimation) {
return;
}
this.play();
const target = this.$store.state.logBuffer[0];
if (target.drawables.length > 0) {
this.$data.draw = true;
this.$data.target = target;
this.$store.commit("activateAnimation");
setTimeout(this.deactivateAnimation, 900);
} else {
this.$store.commit("appendLog", target);
}
setTimeout(this.nextAnimation, 1200);
}
get playSound() {
return this.$store.state.settings.playSound;
}
get playDiceAnimation() {
return this.$store.state.settings.playDiceAnimation;
}
getAudio() {
if (this.$el !== undefined) {
return this.$el.querySelectorAll("audio")[0];
}
return null;
}
play() {
if (!this.playSound) {
return;
}
const audio = this.getAudio();
if (audio != null) {
audio.pause();
audio.currentTime = 0.15;
audio.volume = this.$store.state.settings.soundVolume;
audio.play();
}
}
showDice() {
this.$data.draw = true;
}
hideDice() {
this.$data.draw = false;
}
deactivateAnimation() {
this.$store.commit("deactivateAnimation");
this.$store.commit("appendLog", this.$data.target);
}
nextAnimation() {
this.$store.commit("nextAnimation");
if (!this.$store.state.readyAnimation) {
this.playAnimation();
}
}
get commandResult(): string {
const result = this.$data.target.body;
if (!result) {
return "";
}
const strs = result.split(">");
return strs[strs.length - 1];
}
get isSuccess(): boolean {
return this.$data.target.success;
}
get isFailure(): boolean {
return this.$data.target.failure;
}
get isActive(): boolean {
return this.$store.state.activeAnimation;
}
get soundVolume(): number {
return this.$store.state.settings.soundVolume;
}
}
</script>
<style lang="scss" scoped>
.dice-area {
position: absolute;
top: 0;
z-index: 200;
}
.result {
display: inline-block;
font-size: 1.5rem;
min-width: 100px;
border-radius: 5px;
padding: 10px 5px;
margin-left: 10px;
text-align: center;
border: solid 1px #e0e0e0;
background-color: #fff;
&.active {
animation: showing 0.8s step-end;
}
&.success {
border: solid 1px #81c784;
background-color: #c8e6c9 !important;
}
&.failure {
border: solid 1px #e57373;
background-color: #ffcdd2 !important;
}
}
@keyframes showing {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
</style>