2020-05-09 06:47:20 +00:00
|
|
|
<template>
|
|
|
|
<div class="hveuntkp">
|
2020-10-17 11:12:00 +00:00
|
|
|
<div class="controller _section" v-if="objectSelected">
|
2020-05-09 06:47:20 +00:00
|
|
|
<div class="_content">
|
|
|
|
<p class="name">{{ selectedFurnitureName }}</p>
|
2020-10-17 11:12:00 +00:00
|
|
|
<XPreview ref="preview"/>
|
2020-05-09 06:47:20 +00: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 01:47:36 +00:00
|
|
|
<MkButton @click="chooseImage(k, $event)">{{ $ts._rooms.chooseImage }}</MkButton>
|
2020-05-09 06:47:20 +00: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 14:22:59 +00: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 06:47:20 +00:00
|
|
|
</div>
|
|
|
|
<div class="_content">
|
2021-04-20 14:22:59 +00:00
|
|
|
<MkButton @click="remove()"><i class="fas fa-trash-alt"></i> {{ $ts._rooms.remove }}</MkButton>
|
2020-05-09 06:47:20 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
<div class="menu _section" v-if="isMyRoom">
|
2020-05-09 06:47:20 +00:00
|
|
|
<div class="_content">
|
2021-04-20 14:22:59 +00:00
|
|
|
<MkButton @click="add()"><i class="fas fa-box-open"></i> {{ $ts._rooms.addFurniture }}</MkButton>
|
2020-05-09 06:47:20 +00:00
|
|
|
</div>
|
|
|
|
<div class="_content">
|
2020-10-17 11:12:00 +00:00
|
|
|
<MkSelect :value="roomType" @update:value="updateRoomType($event)">
|
2020-12-26 01:47:36 +00: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 11:12:00 +00:00
|
|
|
</MkSelect>
|
2020-05-09 06:47:20 +00:00
|
|
|
<label v-if="roomType === 'default'">
|
2020-12-26 01:47:36 +00:00
|
|
|
<span>{{ $ts._rooms.carpetColor }}</span>
|
2020-05-09 06:47:20 +00:00
|
|
|
<input type="color" :value="carpetColor" @change="updateCarpetColor($event)"/>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div class="_content">
|
2021-04-20 14:22:59 +00: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 06:47:20 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 11:12:00 +00:00
|
|
|
import { computed, defineComponent } from 'vue';
|
2021-03-23 08:30:14 +00:00
|
|
|
import { Room } from '@client/scripts/room/room';
|
2021-07-15 11:45:32 +00:00
|
|
|
import { parseAcct } from '@/misc/acct';
|
2020-05-09 06:47:20 +00:00
|
|
|
import XPreview from './preview.vue';
|
2021-03-23 08:30:14 +00:00
|
|
|
const storeItems = require('@client/scripts/room/furnitures.json5');
|
2020-05-09 06:47:20 +00:00
|
|
|
import { query as urlQuery } from '../../../prelude/url';
|
2021-03-23 08:30:14 +00:00
|
|
|
import MkButton from '@client/components/ui/button.vue';
|
|
|
|
import MkSelect from '@client/components/ui/select.vue';
|
|
|
|
import { selectFile } from '@client/scripts/select-file';
|
|
|
|
import * as os from '@client/os';
|
|
|
|
import { ColdDeviceStorage } from '@client/store';
|
2021-04-10 03:54:12 +00:00
|
|
|
import * as symbols from '@client/symbols';
|
2020-05-09 06:47:20 +00:00
|
|
|
|
|
|
|
let room: Room;
|
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
export default defineComponent({
|
2020-05-09 06:47:20 +00:00
|
|
|
components: {
|
|
|
|
XPreview,
|
|
|
|
MkButton,
|
|
|
|
MkSelect,
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
acct: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-04-10 03:54:12 +00:00
|
|
|
[symbols.PAGE_INFO]: computed(() => this.user ? {
|
2020-12-26 01:47:36 +00:00
|
|
|
title: this.$ts.room,
|
2020-11-03 11:36:12 +00:00
|
|
|
avatar: this.user,
|
2020-10-17 11:12:00 +00:00
|
|
|
} : null),
|
2020-05-09 06:47:20 +00: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 11:12:00 +00:00
|
|
|
this.user = await os.api('users/show', {
|
2020-05-09 06:47:20 +00:00
|
|
|
...parseAcct(this.acct)
|
|
|
|
});
|
|
|
|
|
2020-12-19 01:55:52 +00:00
|
|
|
this.isMyRoom = this.$i && (this.$i.id === this.user.id);
|
2020-05-09 06:47:20 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
const roomInfo = await os.api('room/show', {
|
2020-05-09 06:47:20 +00: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 01:55:52 +00:00
|
|
|
graphicsQuality: ColdDeviceStorage.get('roomGraphicsQuality'),
|
2020-05-09 06:47:20 +00: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 01:55:52 +00:00
|
|
|
useOrthographicCamera: ColdDeviceStorage.get('roomUseOrthographicCamera'),
|
2020-05-09 06:47:20 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
beforeRouteLeave(to, from, next) {
|
|
|
|
if (this.changed) {
|
2020-10-17 11:12:00 +00:00
|
|
|
os.dialog({
|
2020-05-09 06:47:20 +00:00
|
|
|
type: 'warning',
|
2020-12-26 01:47:36 +00:00
|
|
|
text: this.$ts.leaveConfirm,
|
2020-05-09 06:47:20 +00:00
|
|
|
showCancelButton: true
|
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) {
|
|
|
|
next(false);
|
|
|
|
} else {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
beforeUnmount() {
|
2020-05-09 06:47:20 +00:00
|
|
|
room.destroy();
|
|
|
|
window.removeEventListener('beforeunload', this.beforeunload);
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
beforeunload(e: BeforeUnloadEvent) {
|
|
|
|
if (this.changed) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.returnValue = '';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
async add() {
|
2020-10-17 11:12:00 +00:00
|
|
|
const { canceled, result: id } = await os.dialog({
|
2020-05-09 06:47:20 +00:00
|
|
|
type: null,
|
2020-12-26 01:47:36 +00:00
|
|
|
title: this.$ts._rooms.addFurniture,
|
2020-05-09 06:47:20 +00:00
|
|
|
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 11:12:00 +00:00
|
|
|
os.api('room/update', {
|
2020-05-09 06:47:20 +00:00
|
|
|
room: room.getRoomInfo()
|
|
|
|
}).then(() => {
|
|
|
|
this.changed = false;
|
2020-10-17 11:12:00 +00:00
|
|
|
os.success();
|
2020-05-09 06:47:20 +00:00
|
|
|
}).catch((e: any) => {
|
2020-10-17 11:12:00 +00:00
|
|
|
os.dialog({
|
2020-05-09 06:47:20 +00:00
|
|
|
type: 'error',
|
|
|
|
text: e.message
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
clear() {
|
2020-10-17 11:12:00 +00:00
|
|
|
os.dialog({
|
2020-05-09 06:47:20 +00:00
|
|
|
type: 'warning',
|
2020-12-26 01:47:36 +00:00
|
|
|
text: this.$ts._rooms.clearConfirm,
|
2020-05-09 06:47:20 +00:00
|
|
|
showCancelButton: true
|
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
|
|
|
room.removeAllFurnitures();
|
|
|
|
this.changed = true;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-05-09 06:55:00 +00:00
|
|
|
chooseImage(key, e) {
|
2020-10-17 11:12:00 +00:00
|
|
|
selectFile(e.currentTarget || e.target, null, false).then(file => {
|
2020-05-09 06:47:20 +00: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 11:12:00 +00:00
|
|
|
> ::v-deep(canvas) {
|
2020-05-09 06:47:20 +00:00
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|