2020-05-09 08:47:20 +02:00
|
|
|
<template>
|
|
|
|
<div class="hveuntkp">
|
2020-10-17 13:12:00 +02:00
|
|
|
<div class="controller _section" v-if="objectSelected">
|
2020-05-09 08:47:20 +02:00
|
|
|
<div class="_content">
|
|
|
|
<p class="name">{{ selectedFurnitureName }}</p>
|
2020-10-17 13:12:00 +02:00
|
|
|
<XPreview ref="preview"/>
|
2020-05-09 08:47:20 +02:00
|
|
|
<template v-if="selectedFurnitureInfo.props">
|
|
|
|
<div v-for="k in Object.keys(selectedFurnitureInfo.props)" :key="k">
|
|
|
|
<p>{{ k }}</p>
|
|
|
|
<template v-if="selectedFurnitureInfo.props[k] === 'image'">
|
2020-12-26 02:47:36 +01:00
|
|
|
<MkButton @click="chooseImage(k, $event)">{{ $ts._rooms.chooseImage }}</MkButton>
|
2020-05-09 08:47:20 +02:00
|
|
|
</template>
|
|
|
|
<template v-else-if="selectedFurnitureInfo.props[k] === 'color'">
|
|
|
|
<input type="color" :value="selectedFurnitureProps ? selectedFurnitureProps[k] : null" @change="updateColor(k, $event)"/>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
<div class="_content">
|
2021-04-20 16:22:59 +02:00
|
|
|
<MkButton inline @click="translate()" :primary="isTranslateMode"><i class="fas fa-arrows-alt"></i> {{ $ts._rooms.translate }}</MkButton>
|
|
|
|
<MkButton inline @click="rotate()" :primary="isRotateMode"><i class="fas fa-undo"></i> {{ $ts._rooms.rotate }}</MkButton>
|
|
|
|
<MkButton inline v-if="isTranslateMode || isRotateMode" @click="exit()"><i class="fas fa-ban"></i> {{ $ts._rooms.exit }}</MkButton>
|
2020-05-09 08:47:20 +02:00
|
|
|
</div>
|
|
|
|
<div class="_content">
|
2021-04-20 16:22:59 +02:00
|
|
|
<MkButton @click="remove()"><i class="fas fa-trash-alt"></i> {{ $ts._rooms.remove }}</MkButton>
|
2020-05-09 08:47:20 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
<div class="menu _section" v-if="isMyRoom">
|
2020-05-09 08:47:20 +02:00
|
|
|
<div class="_content">
|
2021-04-20 16:22:59 +02:00
|
|
|
<MkButton @click="add()"><i class="fas fa-box-open"></i> {{ $ts._rooms.addFurniture }}</MkButton>
|
2020-05-09 08:47:20 +02:00
|
|
|
</div>
|
|
|
|
<div class="_content">
|
2021-08-06 15:29:19 +02:00
|
|
|
<MkSelect :model-value="roomType" @update:modelValue="updateRoomType($event)">
|
2020-12-26 02:47:36 +01:00
|
|
|
<template #label>{{ $ts._rooms.roomType }}</template>
|
|
|
|
<option value="default">{{ $ts._rooms._roomType.default }}</option>
|
|
|
|
<option value="washitsu">{{ $ts._rooms._roomType.washitsu }}</option>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkSelect>
|
2020-05-09 08:47:20 +02:00
|
|
|
<label v-if="roomType === 'default'">
|
2020-12-26 02:47:36 +01:00
|
|
|
<span>{{ $ts._rooms.carpetColor }}</span>
|
2020-05-09 08:47:20 +02:00
|
|
|
<input type="color" :value="carpetColor" @change="updateCarpetColor($event)"/>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div class="_content">
|
2021-04-20 16:22:59 +02:00
|
|
|
<MkButton inline :disabled="!changed" primary @click="save()"><i class="fas fa-save"></i> {{ $ts.save }}</MkButton>
|
|
|
|
<MkButton inline @click="clear()"><i class="fas fa-broom"></i> {{ $ts._rooms.clear }}</MkButton>
|
2020-05-09 08:47:20 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 13:12:00 +02:00
|
|
|
import { computed, defineComponent } from 'vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import { Room } from '@/scripts/room/room';
|
|
|
|
import * as Acct from 'misskey-js/built/acct';
|
2020-05-09 08:47:20 +02:00
|
|
|
import XPreview from './preview.vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
const storeItems = require('@/scripts/room/furnitures.json5');
|
|
|
|
import { query as urlQuery } from '@/scripts/url';
|
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import MkSelect from '@/components/form/select.vue';
|
|
|
|
import { selectFile } from '@/scripts/select-file';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import { ColdDeviceStorage } from '@/store';
|
|
|
|
import * as symbols from '@/symbols';
|
2020-05-09 08:47:20 +02:00
|
|
|
|
|
|
|
let room: Room;
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
export default defineComponent({
|
2020-05-09 08:47:20 +02:00
|
|
|
components: {
|
|
|
|
XPreview,
|
|
|
|
MkButton,
|
|
|
|
MkSelect,
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
acct: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-04-10 05:54:12 +02:00
|
|
|
[symbols.PAGE_INFO]: computed(() => this.user ? {
|
2020-12-26 02:47:36 +01:00
|
|
|
title: this.$ts.room,
|
2020-11-03 12:36:12 +01:00
|
|
|
avatar: this.user,
|
2020-10-17 13:12:00 +02:00
|
|
|
} : null),
|
2020-05-09 08:47:20 +02:00
|
|
|
user: null,
|
|
|
|
objectSelected: false,
|
|
|
|
selectedFurnitureName: null,
|
|
|
|
selectedFurnitureInfo: null,
|
|
|
|
selectedFurnitureProps: null,
|
|
|
|
roomType: null,
|
|
|
|
carpetColor: null,
|
|
|
|
isTranslateMode: false,
|
|
|
|
isRotateMode: false,
|
|
|
|
isMyRoom: false,
|
|
|
|
changed: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
async mounted() {
|
|
|
|
window.addEventListener('beforeunload', this.beforeunload);
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
this.user = await os.api('users/show', {
|
2021-11-11 18:02:25 +01:00
|
|
|
...Acct.parse(this.acct)
|
2020-05-09 08:47:20 +02:00
|
|
|
});
|
|
|
|
|
2020-12-19 02:55:52 +01:00
|
|
|
this.isMyRoom = this.$i && (this.$i.id === this.user.id);
|
2020-05-09 08:47:20 +02:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
const roomInfo = await os.api('room/show', {
|
2020-05-09 08:47:20 +02:00
|
|
|
userId: this.user.id
|
|
|
|
});
|
|
|
|
|
|
|
|
this.roomType = roomInfo.roomType;
|
|
|
|
this.carpetColor = roomInfo.carpetColor;
|
|
|
|
|
|
|
|
room = new Room(this.user, this.isMyRoom, roomInfo, this.$el, {
|
2020-12-19 02:55:52 +01:00
|
|
|
graphicsQuality: ColdDeviceStorage.get('roomGraphicsQuality'),
|
2020-05-09 08:47:20 +02:00
|
|
|
onChangeSelect: obj => {
|
|
|
|
this.objectSelected = obj != null;
|
|
|
|
if (obj) {
|
|
|
|
const f = room.findFurnitureById(obj.name);
|
|
|
|
this.selectedFurnitureName = this.$t('_rooms._furnitures.' + f.type);
|
|
|
|
this.selectedFurnitureInfo = storeItems.find(x => x.id === f.type);
|
|
|
|
this.selectedFurnitureProps = f.props
|
|
|
|
? JSON.parse(JSON.stringify(f.props)) // Disable reactivity
|
|
|
|
: null;
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$refs.preview.selected(obj);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2020-12-19 02:55:52 +01:00
|
|
|
useOrthographicCamera: ColdDeviceStorage.get('roomUseOrthographicCamera'),
|
2020-05-09 08:47:20 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
beforeRouteLeave(to, from, next) {
|
|
|
|
if (this.changed) {
|
2021-11-18 10:45:58 +01:00
|
|
|
os.confirm({
|
2020-05-09 08:47:20 +02:00
|
|
|
type: 'warning',
|
2020-12-26 02:47:36 +01:00
|
|
|
text: this.$ts.leaveConfirm,
|
2020-05-09 08:47:20 +02:00
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) {
|
|
|
|
next(false);
|
|
|
|
} else {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
beforeUnmount() {
|
2020-05-09 08:47:20 +02:00
|
|
|
room.destroy();
|
|
|
|
window.removeEventListener('beforeunload', this.beforeunload);
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
beforeunload(e: BeforeUnloadEvent) {
|
|
|
|
if (this.changed) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.returnValue = '';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
async add() {
|
2021-11-18 10:45:58 +01:00
|
|
|
const { canceled, result: id } = await os.select({
|
2020-12-26 02:47:36 +01:00
|
|
|
title: this.$ts._rooms.addFurniture,
|
2021-11-18 10:45:58 +01:00
|
|
|
items: storeItems.map(item => ({
|
|
|
|
value: item.id, text: this.$t('_rooms._furnitures.' + item.id)
|
|
|
|
}))
|
2020-05-09 08:47:20 +02:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
room.addFurniture(id);
|
|
|
|
this.changed = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
remove() {
|
|
|
|
this.isTranslateMode = false;
|
|
|
|
this.isRotateMode = false;
|
|
|
|
room.removeFurniture();
|
|
|
|
this.changed = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
save() {
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('room/update', {
|
2020-05-09 08:47:20 +02:00
|
|
|
room: room.getRoomInfo()
|
|
|
|
}).then(() => {
|
|
|
|
this.changed = false;
|
2020-10-17 13:12:00 +02:00
|
|
|
os.success();
|
2020-05-09 08:47:20 +02:00
|
|
|
}).catch((e: any) => {
|
2021-11-18 10:45:58 +01:00
|
|
|
os.alert({
|
2020-05-09 08:47:20 +02:00
|
|
|
type: 'error',
|
|
|
|
text: e.message
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
clear() {
|
2021-11-18 10:45:58 +01:00
|
|
|
os.confirm({
|
2020-05-09 08:47:20 +02:00
|
|
|
type: 'warning',
|
2020-12-26 02:47:36 +01:00
|
|
|
text: this.$ts._rooms.clearConfirm,
|
2020-05-09 08:47:20 +02:00
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
|
|
|
room.removeAllFurnitures();
|
|
|
|
this.changed = true;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-05-09 08:55:00 +02:00
|
|
|
chooseImage(key, e) {
|
2020-10-17 13:12:00 +02:00
|
|
|
selectFile(e.currentTarget || e.target, null, false).then(file => {
|
2020-05-09 08:47:20 +02:00
|
|
|
room.updateProp(key, `/proxy/?${urlQuery({ url: file.thumbnailUrl })}`);
|
|
|
|
this.$refs.preview.selected(room.getSelectedObject());
|
|
|
|
this.changed = true;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
updateColor(key, ev) {
|
|
|
|
room.updateProp(key, ev.target.value);
|
|
|
|
this.$refs.preview.selected(room.getSelectedObject());
|
|
|
|
this.changed = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
updateCarpetColor(ev) {
|
|
|
|
room.updateCarpetColor(ev.target.value);
|
|
|
|
this.carpetColor = ev.target.value;
|
|
|
|
this.changed = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
updateRoomType(type) {
|
|
|
|
room.changeRoomType(type);
|
|
|
|
this.roomType = type;
|
|
|
|
this.changed = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
translate() {
|
|
|
|
if (this.isTranslateMode) {
|
|
|
|
this.exit();
|
|
|
|
} else {
|
|
|
|
this.isRotateMode = false;
|
|
|
|
this.isTranslateMode = true;
|
|
|
|
room.enterTransformMode('translate');
|
|
|
|
}
|
|
|
|
this.changed = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
rotate() {
|
|
|
|
if (this.isRotateMode) {
|
|
|
|
this.exit();
|
|
|
|
} else {
|
|
|
|
this.isTranslateMode = false;
|
|
|
|
this.isRotateMode = true;
|
|
|
|
room.enterTransformMode('rotate');
|
|
|
|
}
|
|
|
|
this.changed = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
exit() {
|
|
|
|
this.isTranslateMode = false;
|
|
|
|
this.isRotateMode = false;
|
|
|
|
room.exitTransformMode();
|
|
|
|
this.changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.hveuntkp {
|
|
|
|
position: relative;
|
|
|
|
min-height: 500px;
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
> ::v-deep(canvas) {
|
2020-05-09 08:47:20 +02:00
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|