This repository has been archived by the owner on Apr 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
vRoomFlags.vue
182 lines (174 loc) · 5.55 KB
/
vRoomFlags.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
<template>
<vModal>
<h1 slot="header">Game Options</h1>
<template slot="body" class="flags-body">
<h2>
Death Penalty
<vTooltip>
<span>{{ deathTooltip }}</span>
</vTooltip>
</h2>
<select class="slot-selector" :disabled="!isHost" v-model="deathFlag">
<option v-for="option in payload.death" :key="option.id">{{ option.name }}</option>
</select>
<h2>Run Options</h2>
<div class="switches">
<vSwitch
v-for="entry in payload.game"
:key="entry.id"
v-model="payload.game[entry.id].value"
:disabled="!isHost"
>
<span>{{ entry.name }}</span>
<vTooltip>
<span>{{ entry.tooltip }}</span>
</vTooltip>
</vSwitch>
</div>
<h2>
World seed
<vTooltip>
<span>{{ payload.world.sync_world_seed.tooltip }}</span>
</vTooltip>
</h2>
<div class="world-seed">
<vInput v-model="payload.world.sync_world_seed.value" ref="seedInput"></vInput>
<vButton @click="randomizeSeed">Random</vButton>
</div>
</template>
<div slot="footer" class="centered">
<vButton @click="applyFlags">Apply</vButton>
<vButton @click="close">Cancel</vButton>
</div>
</vModal>
</template>
<script>
import vSwitch from "../components/vSwitch.vue";
import vModal from "../components/vModal.vue";
import vButton from "../components/vButton.vue";
import vTooltip from "../components/vTooltip.vue";
import vInput from "../components/vInput.vue";
export default {//braincells where'd ya go
name: "vRoomPassword",
components: {
vButton,
vModal,
vInput,
vSwitch,
vTooltip,
},
beforeMount() {
this.payload = this.flags;
const deathFlag = this.storeFlags.find(v => v.id.startsWith("death_penalty") && v.value)
console.log({ f: this.storeFlags })
this.deathFlag = deathFlag.name
},
data() {
return {
payload: null,
deathFlag: ""
};
},
computed: {
isHost() {
return this.$store.getters.isHost;
},
storeFlags() {
return this.$store.getters.flags
},
flags() {
const flags = this.storeFlags;
const game = {};
const world = {};
const death = {};
for (const flag of flags) {
if (flag.id.startsWith("death_penalty")) {
death[flag.id] = flag;
} else if (flag.id == "sync_world_seed") {
world[flag.id] = flag;
} else {
game[flag.id] = flag;
}
}
return { game, death, world };
},
deathTooltip() {
const flags = this.flags.death;
const flag = this.deathFlag;
let tooltip = "";
for (const key in flags) {
if (flags[key].name == flag) {
tooltip = flags[key].tooltip;
break;
}
}
return tooltip;
},
},
methods: {
//the whole flags things is a massive mess gotta rethink when braincells grow back
applyFlags() {
const flags = this.flags;
const payload = [];
//console.log({a: flags.death})
for (const flag in flags.death) {
if (flags.death[flag].name == this.deathFlag) {
flags.death[flag].value = true
payload.push({ flag: flags.death[flag].id });
}
else {
flags.death[flag].value = false
}
}
for (const flag in flags.game) {
if (
typeof flags.game[flag].value == "boolean" &&
flags.game[flag].value
) {
payload.push({ flag: flags.game[flag].id });
}
}
for (const flag in flags.world) {
let val = Number(flags.world[flag].value)
if (isNaN(val)) { val = 0 }
payload.push({ flag: flags.world[flag].id, value: Math.min(val, 4294967295) })
}
//console.log({ flags: payload })
this.$emit("applyFlags", { flags: payload });
},
randomizeSeed() {
const seed = Math.floor(Math.random() * 4294967295) + 1
// not an amazing way to do it
this.$refs.seedInput.$refs.input.value = seed
this.$refs.seedInput.$refs.input.dispatchEvent(new Event('input'))
},
close() {
this.$emit("close");
},
},
};
</script>
<style>
.flags-body {
display: flex;
flex-flow: row wrap;
width: 100%;
}
.switches {
display: flex;
flex-flow: row wrap;
}
.switches > div {
padding: 0.2em;
min-width: 180px;
}
.world-seed {
display: flex;
width: 100%;
}
.world-seed .labeled-input {
margin-top: auto;
padding-bottom: 0;
margin-right: 0;
}
</style>