2020-05-09 15:47:20 +09:00
|
|
|
<template>
|
|
|
|
<div class="hveuntkp">
|
2020-10-17 20:12:00 +09:00
|
|
|
<div class="controller _section" v-if="objectSelected">
|
2020-05-09 15:47:20 +09:00
|
|
|
<div class="_content">
|
|
|
|
<p class="name">{{ selectedFurnitureName }}</p>
|
2020-10-17 20:12:00 +09:00
|
|
|
<XPreview ref="preview"/>
|
2020-05-09 15:47:20 +09: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-10-17 20:12:00 +09:00
|
|
|
<MkButton @click="chooseImage(k, $event)">{{ $t('_rooms.chooseImage') }}</MkButton>
|
2020-05-09 15:47:20 +09: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">
|
2020-10-17 20:12:00 +09:00
|
|
|
<MkButton inline @click="translate()" :primary="isTranslateMode"><Fa :icon="faArrowsAlt"/> {{ $t('_rooms.translate') }}</MkButton>
|
|
|
|
<MkButton inline @click="rotate()" :primary="isRotateMode"><Fa :icon="faUndo"/> {{ $t('_rooms.rotate') }}</MkButton>
|
|
|
|
<MkButton inline v-if="isTranslateMode || isRotateMode" @click="exit()"><Fa :icon="faBan"/> {{ $t('_rooms.exit') }}</MkButton>
|
2020-05-09 15:47:20 +09:00
|
|
|
</div>
|
|
|
|
<div class="_content">
|
2020-10-17 20:12:00 +09:00
|
|
|
<MkButton @click="remove()"><Fa :icon="faTrashAlt"/> {{ $t('_rooms.remove') }}</MkButton>
|
2020-05-09 15:47:20 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
<div class="menu _section" v-if="isMyRoom">
|
2020-05-09 15:47:20 +09:00
|
|
|
<div class="_content">
|
2020-10-17 20:12:00 +09:00
|
|
|
<MkButton @click="add()"><Fa :icon="faBoxOpen"/> {{ $t('_rooms.addFurniture') }}</MkButton>
|
2020-05-09 15:47:20 +09:00
|
|
|
</div>
|
|
|
|
<div class="_content">
|
2020-10-17 20:12:00 +09:00
|
|
|
<MkSelect :value="roomType" @update:value="updateRoomType($event)">
|
2020-05-09 15:47:20 +09:00
|
|
|
<template #label>{{ $t('_rooms.roomType') }}</template>
|
2020-07-25 01:56:52 +09:00
|
|
|
<option value="default">{{ $t('_rooms._roomType.default') }}</option>
|
|
|
|
<option value="washitsu">{{ $t('_rooms._roomType.washitsu') }}</option>
|
2020-10-17 20:12:00 +09:00
|
|
|
</MkSelect>
|
2020-05-09 15:47:20 +09:00
|
|
|
<label v-if="roomType === 'default'">
|
2020-07-25 01:56:52 +09:00
|
|
|
<span>{{ $t('_rooms.carpetColor') }}</span>
|
2020-05-09 15:47:20 +09:00
|
|
|
<input type="color" :value="carpetColor" @change="updateCarpetColor($event)"/>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div class="_content">
|
2020-10-17 20:12:00 +09:00
|
|
|
<MkButton inline :disabled="!changed" primary @click="save()"><Fa :icon="faSave"/> {{ $t('save') }}</MkButton>
|
|
|
|
<MkButton inline @click="clear()"><Fa :icon="faBroom"/> {{ $t('_rooms.clear') }}</MkButton>
|
2020-05-09 15:47:20 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 20:12:00 +09:00
|
|
|
import { computed, defineComponent } from 'vue';
|
|
|
|
import { Room } from '@/scripts/room/room';
|
2020-05-09 15:47:20 +09:00
|
|
|
import parseAcct from '../../../misc/acct/parse';
|
|
|
|
import XPreview from './preview.vue';
|
2020-10-17 20:12:00 +09:00
|
|
|
const storeItems = require('@/scripts/room/furnitures.json5');
|
2020-05-09 15:47:20 +09:00
|
|
|
import { faBoxOpen, faUndo, faArrowsAlt, faBan, faBroom } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { faSave, faTrashAlt } from '@fortawesome/free-regular-svg-icons';
|
|
|
|
import { query as urlQuery } from '../../../prelude/url';
|
2020-10-17 20:12:00 +09:00
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import MkSelect from '@/components/ui/select.vue';
|
|
|
|
import { selectFile } from '@/scripts/select-file';
|
|
|
|
import * as os from '@/os';
|
2020-05-09 15:47:20 +09:00
|
|
|
|
|
|
|
let room: Room;
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
export default defineComponent({
|
2020-05-09 15:47:20 +09:00
|
|
|
components: {
|
|
|
|
XPreview,
|
|
|
|
MkButton,
|
|
|
|
MkSelect,
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
acct: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2020-10-17 20:12:00 +09:00
|
|
|
INFO: computed(() => this.user ? {
|
2020-11-03 20:36:12 +09:00
|
|
|
title: this.$t('room'),
|
|
|
|
avatar: this.user,
|
2020-10-17 20:12:00 +09:00
|
|
|
} : null),
|
2020-05-09 15:47:20 +09:00
|
|
|
user: null,
|
|
|
|
objectSelected: false,
|
|
|
|
selectedFurnitureName: null,
|
|
|
|
selectedFurnitureInfo: null,
|
|
|
|
selectedFurnitureProps: null,
|
|
|
|
roomType: null,
|
|
|
|
carpetColor: null,
|
|
|
|
isTranslateMode: false,
|
|
|
|
isRotateMode: false,
|
|
|
|
isMyRoom: false,
|
|
|
|
changed: false,
|
|
|
|
faBoxOpen, faSave, faTrashAlt, faUndo, faArrowsAlt, faBan, faBroom,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
async mounted() {
|
|
|
|
window.addEventListener('beforeunload', this.beforeunload);
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
this.user = await os.api('users/show', {
|
2020-05-09 15:47:20 +09:00
|
|
|
...parseAcct(this.acct)
|
|
|
|
});
|
|
|
|
|
|
|
|
this.isMyRoom = this.$store.getters.isSignedIn && (this.$store.state.i.id === this.user.id);
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
const roomInfo = await os.api('room/show', {
|
2020-05-09 15:47:20 +09:00
|
|
|
userId: this.user.id
|
|
|
|
});
|
|
|
|
|
|
|
|
this.roomType = roomInfo.roomType;
|
|
|
|
this.carpetColor = roomInfo.carpetColor;
|
|
|
|
|
|
|
|
room = new Room(this.user, this.isMyRoom, roomInfo, this.$el, {
|
|
|
|
graphicsQuality: this.$store.state.device.roomGraphicsQuality,
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
useOrthographicCamera: this.$store.state.device.roomUseOrthographicCamera
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
beforeRouteLeave(to, from, next) {
|
|
|
|
if (this.changed) {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.dialog({
|
2020-05-09 15:47:20 +09:00
|
|
|
type: 'warning',
|
2020-07-11 12:12:35 +09:00
|
|
|
text: this.$t('leaveConfirm'),
|
2020-05-09 15:47:20 +09:00
|
|
|
showCancelButton: true
|
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) {
|
|
|
|
next(false);
|
|
|
|
} else {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
beforeUnmount() {
|
2020-05-09 15:47:20 +09:00
|
|
|
room.destroy();
|
|
|
|
window.removeEventListener('beforeunload', this.beforeunload);
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
beforeunload(e: BeforeUnloadEvent) {
|
|
|
|
if (this.changed) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.returnValue = '';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
async add() {
|
2020-10-17 20:12:00 +09:00
|
|
|
const { canceled, result: id } = await os.dialog({
|
2020-05-09 15:47:20 +09:00
|
|
|
type: null,
|
|
|
|
title: this.$t('_rooms.addFurniture'),
|
|
|
|
select: {
|
|
|
|
items: storeItems.map(item => ({
|
|
|
|
value: item.id, text: this.$t('_rooms._furnitures.' + item.id)
|
|
|
|
}))
|
|
|
|
},
|
|
|
|
showCancelButton: true
|
|
|
|
});
|
|
|
|
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 20:12:00 +09:00
|
|
|
os.api('room/update', {
|
2020-05-09 15:47:20 +09:00
|
|
|
room: room.getRoomInfo()
|
|
|
|
}).then(() => {
|
|
|
|
this.changed = false;
|
2020-10-17 20:12:00 +09:00
|
|
|
os.success();
|
2020-05-09 15:47:20 +09:00
|
|
|
}).catch((e: any) => {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.dialog({
|
2020-05-09 15:47:20 +09:00
|
|
|
type: 'error',
|
|
|
|
text: e.message
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
clear() {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.dialog({
|
2020-05-09 15:47:20 +09:00
|
|
|
type: 'warning',
|
|
|
|
text: this.$t('_rooms.clearConfirm'),
|
|
|
|
showCancelButton: true
|
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
|
|
|
room.removeAllFurnitures();
|
|
|
|
this.changed = true;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-05-09 15:55:00 +09:00
|
|
|
chooseImage(key, e) {
|
2020-10-17 20:12:00 +09:00
|
|
|
selectFile(e.currentTarget || e.target, null, false).then(file => {
|
2020-05-09 15:47:20 +09: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 20:12:00 +09:00
|
|
|
> ::v-deep(canvas) {
|
2020-05-09 15:47:20 +09:00
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|