-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathMain.vue
139 lines (133 loc) · 3.44 KB
/
Main.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
<template>
<div class="main">
<div class="gauntlet">
<div class="gauntlet-wrapper">
<div id="gauntlet-snap"
v-show="status === PEDDING || status === SNAPING"
:class="status === SNAPING? 'snaping':''"
class="gauntlet-item"
@click="snapHandle"></div>
<div id="gauntlet-reverse"
v-show="status === DONE || status === REVERSING"
:class="status === REVERSING? 'reversing':''"
class="gauntlet-item"
@click="reverseHandle"></div>
</div>
</div>
<Content :heroes="heroes"
:status="status" />
<audio preload
ref="allAuduio"></audio>
</div>
</template>
<script>
import Content from "./Content";
import { statusMixin } from "@/global/mixins";
import { heroes } from "@/config";
import Bus from "@/global/Bus.js";
export default {
name: "GauntletMain",
data() {
return {
status: "PEDDING",
heroes,
stay: 4
};
},
mixins: [statusMixin],
methods: {
changeStatus(status) {
this.status = status;
},
sleep(delay) {
return new Promise(resovle => {
setTimeout(() => {
resovle();
}, delay || 2000);
});
},
snapHandle() {
// can not click until harf heroes becomes dust
if (this.status === this.SNAPING || this.status === this.REVERSING)
return;
this.status = this.SNAPING;
this.playAudio("snap");
// select half heroes randomly
setTimeout(async () => {
// get half heroes randomly
const heroesDisappered = this.heroes
.slice(0)
.sort(() => 0.5 - Math.random())
.slice(0, Math.ceil(this.heroes.length / 2));
// hero becomes dust in turn.
for (let i = 0; i < heroesDisappered.length; i++) {
/* eslint-disable */
if (!!i) await this.sleep();
this.$nextTick(() => {
this.playAudio();
Bus.$emit("hide-hero", heroesDisappered[i].id);
});
}
this.$nextTick(() => {
this.status = this.DONE;
});
}, 2500);
},
reverseHandle() {
if (this.status === this.SNAPING || this.status === this.REVERSING)
return;
this.status = this.REVERSING;
Bus.$emit("reverse-time");
this.playAudio("reverse");
},
playAudio(target) {
const audio = this.$refs.allAuduio;
if (!audio) return;
if (!audio.paused) {
audio.pause();
}
if (["snap", "reverse"].indexOf(target) > -1) {
audio.src = require(`../assets/audios/thanos_${target}_sound.mp3`);
} else {
// 消失音频每段大概 4s
let index = target || Math.floor(Math.random() * 6 + 1);
audio.src = require(`../assets/audios/thanos_dust_${index}.mp3`);
}
audio.play();
}
},
components: {
Content
}
};
</script>
<style lang="scss">
.main {
width: 100%;
max-width: 1000px;
margin: 0 auto;
padding: 20px;
.gauntlet {
height: 100px;
}
.gauntlet-item {
width: 80px;
height: 80px;
cursor: pointer;
}
#gauntlet-snap {
background: transparent url("../assets/thanos/thanos_snap.png") center left
no-repeat;
background-position: 0 0;
}
#gauntlet-reverse {
background: transparent url("../assets/thanos/thanos_reverse.png") center
left no-repeat;
background-position: 0 0;
}
.snaping,
.reversing {
animation: gauntlet 2.8s steps(47) both;
}
}
</style>