forked from akanyan/STARTLINER
81 lines
2.4 KiB
Vue
81 lines
2.4 KiB
Vue
<script setup lang="ts">
|
|
import { computed } from 'vue';
|
|
import InputNumber from 'primevue/inputnumber';
|
|
import InputText from 'primevue/inputtext';
|
|
import ToggleSwitch from 'primevue/toggleswitch';
|
|
import OptionRow from './OptionRow.vue';
|
|
import { usePrfStore } from '../stores';
|
|
import { Patch } from '../types';
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
const { t, te } = useI18n();
|
|
|
|
const prf = usePrfStore();
|
|
|
|
const toggleUnary = (key: string, val: boolean) => {
|
|
if (val) {
|
|
prf.current!.data.patches[key] = 'enabled';
|
|
} else {
|
|
delete prf.current!.data.patches[key];
|
|
}
|
|
};
|
|
|
|
const setNumber = (key: string, val: number) => {
|
|
if (val) {
|
|
prf.current!.data.patches[key] = { number: val };
|
|
} else {
|
|
delete prf.current!.data.patches[key];
|
|
}
|
|
};
|
|
|
|
const props = defineProps({
|
|
patch: Object as () => Patch,
|
|
});
|
|
|
|
// One day, I will repent
|
|
const hexModel = computed({
|
|
get() {
|
|
const hex = (prf.current!.data.patches[props.patch!.id!] as any)?.hex;
|
|
if (hex !== undefined) {
|
|
return new TextDecoder().decode(new Int8Array(hex).buffer);
|
|
} else {
|
|
return 'FREE PLAY';
|
|
}
|
|
},
|
|
set(value: string) {
|
|
(prf.current!.data.patches[props.patch!.id!] as any) = {
|
|
hex: new TextEncoder().encode(value),
|
|
};
|
|
},
|
|
});
|
|
|
|
// Doesn't need to be reactive
|
|
const nameKey = `patch.${props.patch?.id}`;
|
|
const name = te(nameKey) ? t(nameKey) : props.patch?.name;
|
|
|
|
const tooltipKey = `patch.${props.patch?.id}-tooltip`;
|
|
const tooltip = te(tooltipKey) ? t(tooltipKey) : props.patch?.tooltip;
|
|
</script>
|
|
|
|
<template>
|
|
<OptionRow :title="name" :tooltip="tooltip" :greytext="patch?.id">
|
|
<ToggleSwitch
|
|
v-if="patch?.type === undefined"
|
|
:model-value="prf.current!.data.patches?.[patch!.id!] !== undefined"
|
|
@update:model-value="(v: boolean) => toggleUnary(patch!.id!, v)"
|
|
/>
|
|
<InputNumber
|
|
v-else-if="patch?.type === 'number'"
|
|
class="number-input"
|
|
:model-value="
|
|
(prf.current!.data.patches[patch!.id!] as any)?.number
|
|
"
|
|
@update:model-value="(v: number) => setNumber(patch!.id!, v)"
|
|
:min="patch?.min"
|
|
:max="patch?.max"
|
|
:placeholder="(patch?.default ?? 0).toString()"
|
|
/>
|
|
<InputText v-else-if="patch?.type === 'hex'" v-model="hexModel" />
|
|
</OptionRow>
|
|
</template>
|