@2kog/kacha 0.0.0-stage → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -2
- package/bin/init-project.js +63 -0
- package/bin/kacha.js +51 -0
- package/index.html +5 -0
- package/package.json +45 -4
- package/server/asset-directories.js +65 -0
- package/server/asset-watch.js +35 -0
- package/server/character-assets.js +399 -0
- package/server/image-assets.js +652 -0
- package/server/index.js +15 -0
- package/server/project-brand.js +56 -0
- package/server/project-paths.js +4 -0
- package/server/project-settings.js +55 -0
- package/src/App.vue +34 -0
- package/src/assets/css/workbench.css +272 -0
- package/src/assets/img/rabbit-mark.svg +1 -0
- package/src/components/AssetDeleteButton.vue +53 -0
- package/src/components/AssetHistory.vue +40 -0
- package/src/components/AssetStoryEditor.vue +32 -0
- package/src/components/AssetTagInput.vue +26 -0
- package/src/components/ProjectMarkdown.vue +33 -0
- package/src/i18n/en.json +163 -0
- package/src/i18n/index.js +40 -0
- package/src/layouts/WorkbenchLayout.vue +61 -0
- package/src/main.js +7 -0
- package/src/router/index.js +38 -0
- package/src/service/assets.js +13 -0
- package/src/service/project-markdown.js +26 -0
- package/src/views/assets/AudioAssets.vue +325 -0
- package/src/views/assets/CharacterAssets.vue +412 -0
- package/src/views/assets/ImageAssets.vue +456 -0
- package/src/views/settings/ProjectSettings.vue +80 -0
- package/templates/project/AGENTS.md +14 -0
- package/templates/project/README.md +7 -0
- package/templates/project/assets/audio/README.md +5 -0
- package/templates/project/assets/characters/README.md +5 -0
- package/templates/project/assets/other/README.md +3 -0
- package/templates/project/assets/props/README.md +3 -0
- package/templates/project/assets/scenes/README.md +3 -0
- package/vite.config.js +10 -0
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import AssetDeleteButton from '@/components/AssetDeleteButton.vue'
|
|
3
|
+
import AssetHistory from '@/components/AssetHistory.vue'
|
|
4
|
+
import AssetStoryEditor from '@/components/AssetStoryEditor.vue'
|
|
5
|
+
import AssetTagInput from '@/components/AssetTagInput.vue'
|
|
6
|
+
import ProjectMarkdown from '@/components/ProjectMarkdown.vue'
|
|
7
|
+
import { requestAsset } from '@/service/assets.js'
|
|
8
|
+
import { Image, Pencil, Plus, RefreshCw, Search, Upload, X } from 'lucide-vue-next'
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
components: { AssetDeleteButton, AssetHistory, AssetStoryEditor, AssetTagInput, ProjectMarkdown, Image, Pencil, Plus, RefreshCw, Search, Upload, X },
|
|
12
|
+
props: { kind: { type: String, default: 'scenes' } },
|
|
13
|
+
data() {
|
|
14
|
+
return {
|
|
15
|
+
scenes: [], tagFilters: [], query: '', createTags: [], overviewDraft: {}, scene: null, tab: 'cover', category: '', selectedId: '',
|
|
16
|
+
imageForm: null, storyDraft: null, promptDraft: null, create: false, name: '',
|
|
17
|
+
busy: false, error: '', pageError: '', revision: 0,
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
computed: {
|
|
21
|
+
isScene() {
|
|
22
|
+
return this.kind === 'scenes'
|
|
23
|
+
},
|
|
24
|
+
isProp() {
|
|
25
|
+
return this.kind === 'props'
|
|
26
|
+
},
|
|
27
|
+
isOther() {
|
|
28
|
+
return this.kind === 'other'
|
|
29
|
+
},
|
|
30
|
+
assetLabel() {
|
|
31
|
+
return this.isProp ? '道具' : this.isOther ? '其他' : '场景'
|
|
32
|
+
},
|
|
33
|
+
changeEvent() {
|
|
34
|
+
return 'workbench:' + this.kind + ':changed'
|
|
35
|
+
},
|
|
36
|
+
availableTags() {
|
|
37
|
+
return [...new Set(this.scenes.flatMap(item => item.tags || []))].sort((a, b) => a.localeCompare(b, 'zh-CN'))
|
|
38
|
+
},
|
|
39
|
+
visibleScenes() {
|
|
40
|
+
const query = this.query.trim().toLowerCase()
|
|
41
|
+
return this.scenes.filter(scene => {
|
|
42
|
+
const tags = scene.tags || []
|
|
43
|
+
return this.tagFilters.every(tag => tags.includes(tag))
|
|
44
|
+
&& [scene.name, ...tags, ...scene.groupPath].some(value => value.toLowerCase().includes(query))
|
|
45
|
+
})
|
|
46
|
+
},
|
|
47
|
+
detailTabs() {
|
|
48
|
+
const galleries = this.isOther
|
|
49
|
+
? [{ key: 'images', name: '扩展' }]
|
|
50
|
+
: Object.entries(this.scene.groups).map(([key, name]) => ({ key, name }))
|
|
51
|
+
return [
|
|
52
|
+
{ key: 'overview', name: '概览' },
|
|
53
|
+
{ key: 'cover', name: '主图' },
|
|
54
|
+
...galleries,
|
|
55
|
+
{ key: 'story', name: this.isOther ? '说明' : this.assetLabel + '说明' },
|
|
56
|
+
{ key: 'history', name: '历史版本' },
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
simpleCover() {
|
|
60
|
+
return !this.isScene && this.tab === 'cover'
|
|
61
|
+
},
|
|
62
|
+
inGallery() {
|
|
63
|
+
return this.isOther ? this.tab === 'images' : Object.hasOwn(this.scene?.groups ?? {}, this.tab)
|
|
64
|
+
},
|
|
65
|
+
filteredImages() {
|
|
66
|
+
return this.scene.images.filter(image => image.id !== this.scene.cover?.id
|
|
67
|
+
&& (!this.category || image.category === this.category))
|
|
68
|
+
},
|
|
69
|
+
activeImage() {
|
|
70
|
+
return this.tab === 'cover' ? this.scene.cover : this.scene.images.find(image => image.id === this.selectedId)
|
|
71
|
+
},
|
|
72
|
+
storyPath() {
|
|
73
|
+
const id = this.scene.id.split('/').map(encodeURIComponent).join('/')
|
|
74
|
+
return `assets/${this.kind}/${id}/README.md`
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
beforeRouteLeave() {
|
|
78
|
+
if (this.busy) return false
|
|
79
|
+
},
|
|
80
|
+
mounted() {
|
|
81
|
+
this.refresh()
|
|
82
|
+
import.meta.hot?.on(this.changeEvent, this.refreshAssets)
|
|
83
|
+
},
|
|
84
|
+
beforeUnmount() {
|
|
85
|
+
import.meta.hot?.off(this.changeEvent, this.refreshAssets)
|
|
86
|
+
},
|
|
87
|
+
methods: {
|
|
88
|
+
toggleTag(tag) {
|
|
89
|
+
this.tagFilters = this.tagFilters.includes(tag)
|
|
90
|
+
? this.tagFilters.filter(value => value !== tag)
|
|
91
|
+
: [...this.tagFilters, tag]
|
|
92
|
+
},
|
|
93
|
+
async refreshAssets() {
|
|
94
|
+
await this.refresh()
|
|
95
|
+
const scene = this.scene
|
|
96
|
+
if (!scene || this.busy || this.imageForm || this.storyDraft !== null || this.promptDraft !== null
|
|
97
|
+
|| !this.scenes.some(item => item.id === scene.id)) return
|
|
98
|
+
try {
|
|
99
|
+
const detail = await requestAsset(this.kind, scene.id)
|
|
100
|
+
if (this.scene !== scene || this.busy || this.imageForm || this.storyDraft !== null || this.promptDraft !== null) return
|
|
101
|
+
this.scene = detail
|
|
102
|
+
if (this.inGallery) this.filterImages(this.category)
|
|
103
|
+
} catch (cause) {
|
|
104
|
+
if (this.scene === scene) this.error = cause.message
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
async refresh() {
|
|
108
|
+
const revision = ++this.revision
|
|
109
|
+
try {
|
|
110
|
+
const scenes = await requestAsset(this.kind)
|
|
111
|
+
if (revision !== this.revision) return
|
|
112
|
+
this.scenes = scenes
|
|
113
|
+
this.tagFilters = this.tagFilters.filter(tag => this.availableTags.includes(tag))
|
|
114
|
+
this.pageError = ''
|
|
115
|
+
} catch (cause) {
|
|
116
|
+
if (revision === this.revision) this.pageError = cause.message
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
async open(item) {
|
|
120
|
+
this.busy = true
|
|
121
|
+
try {
|
|
122
|
+
this.scene = await requestAsset(this.kind, item.id)
|
|
123
|
+
this.overviewDraft = {}
|
|
124
|
+
this.category = ''
|
|
125
|
+
this.selectedId = this.scene.cover?.id || ''
|
|
126
|
+
this.changeTab('overview')
|
|
127
|
+
this.$refs.detail.showModal()
|
|
128
|
+
} catch (cause) {
|
|
129
|
+
this.pageError = cause.message
|
|
130
|
+
} finally {
|
|
131
|
+
this.busy = false
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
showCreate() {
|
|
135
|
+
this.error = ''
|
|
136
|
+
this.name = ''
|
|
137
|
+
this.createTags = []
|
|
138
|
+
this.create = true
|
|
139
|
+
this.$refs.create.showModal()
|
|
140
|
+
},
|
|
141
|
+
async createScene() {
|
|
142
|
+
this.busy = true
|
|
143
|
+
this.error = ''
|
|
144
|
+
try {
|
|
145
|
+
const scene = await requestAsset(this.kind, null, 'POST', {
|
|
146
|
+
name: this.name.trim(),
|
|
147
|
+
tags: this.createTags,
|
|
148
|
+
})
|
|
149
|
+
this.$refs.create.close()
|
|
150
|
+
await this.open(scene)
|
|
151
|
+
await this.refresh()
|
|
152
|
+
} catch (cause) {
|
|
153
|
+
this.error = cause.message
|
|
154
|
+
} finally {
|
|
155
|
+
this.busy = false
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
closeDetail() {
|
|
159
|
+
this.scene = null
|
|
160
|
+
this.overviewDraft = {}
|
|
161
|
+
this.error = ''
|
|
162
|
+
this.imageForm = null
|
|
163
|
+
this.storyDraft = null
|
|
164
|
+
this.promptDraft = null
|
|
165
|
+
},
|
|
166
|
+
changeTab(tab) {
|
|
167
|
+
this.error = ''
|
|
168
|
+
this.imageForm = null
|
|
169
|
+
this.storyDraft = null
|
|
170
|
+
this.promptDraft = null
|
|
171
|
+
this.tab = tab
|
|
172
|
+
if (this.$refs.detailBody) this.$refs.detailBody.scrollTop = 0
|
|
173
|
+
if (this.inGallery) this.filterImages(this.isOther ? '' : tab, !this.isScene)
|
|
174
|
+
},
|
|
175
|
+
filterImages(category, resetSelection = false) {
|
|
176
|
+
this.category = category
|
|
177
|
+
this.imageForm = null
|
|
178
|
+
if (resetSelection || !this.filteredImages.some(image => image.id === this.selectedId)) {
|
|
179
|
+
this.selectedId = this.filteredImages[0]?.id || ''
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
selectImage(id) {
|
|
183
|
+
if (this.selectedId === id) return
|
|
184
|
+
this.selectedId = id
|
|
185
|
+
this.imageForm = null
|
|
186
|
+
this.promptDraft = null
|
|
187
|
+
this.error = ''
|
|
188
|
+
},
|
|
189
|
+
defaultImageCategory() {
|
|
190
|
+
if (this.isOther) return 'graphic'
|
|
191
|
+
if (this.inGallery) return this.category
|
|
192
|
+
return this.isProp ? 'angle' : 'view'
|
|
193
|
+
},
|
|
194
|
+
editImage(image = null, replaceFile = true) {
|
|
195
|
+
this.error = ''
|
|
196
|
+
this.promptDraft = null
|
|
197
|
+
this.imageForm = {
|
|
198
|
+
id: image?.id,
|
|
199
|
+
label: image?.label || (this.simpleCover ? '主图' : ''),
|
|
200
|
+
category: image?.category || this.defaultImageCategory(),
|
|
201
|
+
status: image?.status || 'candidate',
|
|
202
|
+
prompt: replaceFile ? '' : image.prompt || '',
|
|
203
|
+
conditions: { ...image?.conditions },
|
|
204
|
+
replaceFile,
|
|
205
|
+
file: null,
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
async save(patch) {
|
|
209
|
+
this.busy = true
|
|
210
|
+
this.error = ''
|
|
211
|
+
try {
|
|
212
|
+
this.scene = await requestAsset(this.kind, this.scene.id, 'PATCH', patch)
|
|
213
|
+
await this.refresh()
|
|
214
|
+
return true
|
|
215
|
+
} catch (cause) {
|
|
216
|
+
this.error = cause.message
|
|
217
|
+
return false
|
|
218
|
+
} finally {
|
|
219
|
+
this.busy = false
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
async uploadImage() {
|
|
223
|
+
const { file, replaceFile, ...image } = this.imageForm
|
|
224
|
+
if (replaceFile && !file) return
|
|
225
|
+
if (file?.size > 30 * 1024 * 1024) {
|
|
226
|
+
this.error = this.$t('请选择 30 MB 以内的图片')
|
|
227
|
+
return
|
|
228
|
+
}
|
|
229
|
+
this.busy = true
|
|
230
|
+
try {
|
|
231
|
+
const base64 = file && await new Promise((resolve, reject) => {
|
|
232
|
+
const reader = new FileReader()
|
|
233
|
+
reader.onload = () => resolve(reader.result.split(',')[1])
|
|
234
|
+
reader.onerror = () => reject(new Error(this.$t('读取图片失败')))
|
|
235
|
+
reader.readAsDataURL(file)
|
|
236
|
+
})
|
|
237
|
+
const previousIds = new Set(this.scene.images.map(item => item.id))
|
|
238
|
+
const main = this.tab === 'cover'
|
|
239
|
+
const upload = file ? { filename: file.name, base64, main } : {}
|
|
240
|
+
if (await this.save({ image: { ...image, ...upload } })) {
|
|
241
|
+
this.selectedId = image.id || this.scene.images.find(item => !previousIds.has(item.id))?.id || ''
|
|
242
|
+
this.changeTab(main ? 'cover' : image.category)
|
|
243
|
+
}
|
|
244
|
+
} catch (cause) {
|
|
245
|
+
this.error = cause.message
|
|
246
|
+
} finally {
|
|
247
|
+
this.busy = false
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
async deleteAsset() {
|
|
251
|
+
if (this.busy || !this.scene) return
|
|
252
|
+
this.busy = true
|
|
253
|
+
this.error = ''
|
|
254
|
+
try {
|
|
255
|
+
await requestAsset(this.kind, this.scene.id, 'DELETE', {})
|
|
256
|
+
this.$refs.detail.close()
|
|
257
|
+
await this.refresh()
|
|
258
|
+
} catch (cause) {
|
|
259
|
+
this.error = cause.message
|
|
260
|
+
} finally {
|
|
261
|
+
this.busy = false
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
async saveOverview() {
|
|
265
|
+
if (Object.keys(this.overviewDraft).length && await this.save(this.overviewDraft)) this.overviewDraft = {}
|
|
266
|
+
},
|
|
267
|
+
async saveStory() {
|
|
268
|
+
if (this.storyDraft !== null && await this.save({ story: this.storyDraft })) this.storyDraft = null
|
|
269
|
+
},
|
|
270
|
+
async saveImagePrompt() {
|
|
271
|
+
if (await this.save({ image: { id: this.activeImage.id, prompt: this.promptDraft } })) this.promptDraft = null
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
}
|
|
275
|
+
</script>
|
|
276
|
+
|
|
277
|
+
<template>
|
|
278
|
+
<section class="content">
|
|
279
|
+
<div class="heading">
|
|
280
|
+
<div><h1>{{ $t(assetLabel + '资产') }}</h1><p>{{ $t('{count} 个' + assetLabel, { count: scenes.length }) }}</p></div>
|
|
281
|
+
<button class="primary" :disabled="busy" @click="showCreate"><Plus :size="18" /> {{ $t('新建' + assetLabel) }}</button>
|
|
282
|
+
</div>
|
|
283
|
+
<div class="tools">
|
|
284
|
+
<label class="search"><Search :size="17" /><input v-model="query" :placeholder="$t('搜索名称或标签')" :aria-label="$t('搜索名称或标签')"></label>
|
|
285
|
+
<div v-if="availableTags.length" class="filter-list" :aria-label="$t('按标签筛选')">
|
|
286
|
+
<button class="tag" :class="{ chosen: !tagFilters.length }" :aria-pressed="!tagFilters.length" @click="tagFilters = []">{{ $t('全部') }}</button>
|
|
287
|
+
<button v-for="tag in availableTags" :key="tag" class="tag" :class="{ chosen: tagFilters.includes(tag) }"
|
|
288
|
+
:aria-pressed="tagFilters.includes(tag)" @click="toggleTag(tag)">{{ tag }}</button>
|
|
289
|
+
</div>
|
|
290
|
+
</div>
|
|
291
|
+
<p v-if="pageError" class="error" role="alert">{{ pageError }}</p>
|
|
292
|
+
<p v-else-if="!visibleScenes.length" class="empty">{{ $t('没有匹配的' + assetLabel) }}</p>
|
|
293
|
+
<div class="grid">
|
|
294
|
+
<article v-for="item in visibleScenes" :key="item.id" class="card scene-card">
|
|
295
|
+
<button class="cover" :class="{ 'transparent-preview': kind === 'other' || item.transparentPreview || item.cover?.category === 'graphic' }" :aria-label="$t('查看 {name}', { name: item.name })" :disabled="busy" @click="open(item)">
|
|
296
|
+
<img v-if="item.cover?.url" :src="item.cover.url" :alt="item.cover.label" loading="lazy">
|
|
297
|
+
<span v-else class="placeholder"><Image :size="24" />{{ $t('待补主图') }}</span>
|
|
298
|
+
</button>
|
|
299
|
+
<div class="scene-card-info">
|
|
300
|
+
<button class="character-name" :disabled="busy" @click="open(item)">{{ item.name }}</button>
|
|
301
|
+
<div v-if="item.tags?.length" class="card-tags image-card-tags">
|
|
302
|
+
<button v-for="tag in item.tags" :key="tag" class="tag compact" :aria-pressed="tagFilters.includes(tag)"
|
|
303
|
+
:class="{ chosen: tagFilters.includes(tag) }" @click="toggleTag(tag)">{{ tag }}</button>
|
|
304
|
+
</div>
|
|
305
|
+
<p v-else-if="!isProp && item.groupPath.length" class="asset-group-path">{{ item.groupPath.join(' / ') }}</p>
|
|
306
|
+
<small>{{ $t('{count} 张图', { count: item.count }) }}<span v-if="item.cover?.status === 'candidate'"> · {{ $t('候选封面') }}</span></small>
|
|
307
|
+
</div>
|
|
308
|
+
</article>
|
|
309
|
+
</div>
|
|
310
|
+
|
|
311
|
+
<dialog ref="create" class="dialog small-dialog" @close="create = false" @cancel.prevent="!busy && $refs.create.close()">
|
|
312
|
+
<form v-if="create" @submit.prevent="createScene">
|
|
313
|
+
<header class="dialog-head"><h2>{{ $t('新建' + assetLabel) }}</h2><button type="button" class="icon-button" :aria-label="$t('关闭')" :disabled="busy" @click="$refs.create.close()"><X :size="20" /></button></header>
|
|
314
|
+
<div class="dialog-body">
|
|
315
|
+
<label class="field">{{ $t(assetLabel + '名') }}<input v-model="name" required autofocus></label>
|
|
316
|
+
<div class="asset-tag-field">
|
|
317
|
+
<label class="field" for="create-image-asset-tags">{{ $t('标签') }}</label>
|
|
318
|
+
<AssetTagInput id="create-image-asset-tags" v-model="createTags" :disabled="busy" />
|
|
319
|
+
</div>
|
|
320
|
+
<p v-if="error" class="error" role="alert">{{ error }}</p>
|
|
321
|
+
<div class="dialog-actions create-actions">
|
|
322
|
+
<button class="primary" :disabled="busy">{{ $t('创建' + assetLabel) }}</button>
|
|
323
|
+
</div>
|
|
324
|
+
</div>
|
|
325
|
+
</form>
|
|
326
|
+
</dialog>
|
|
327
|
+
|
|
328
|
+
<dialog ref="detail" class="dialog scene-dialog asset-detail-dialog"
|
|
329
|
+
@close="closeDetail" @cancel.prevent="!busy && !$event.currentTarget.querySelector('.asset-delete-message') && $refs.detail.close()">
|
|
330
|
+
<template v-if="scene">
|
|
331
|
+
<header class="dialog-head">
|
|
332
|
+
<div>
|
|
333
|
+
<h2>{{ scene.name }}</h2>
|
|
334
|
+
<div v-if="scene.tags?.length" class="card-tags">
|
|
335
|
+
<span v-for="tag in scene.tags" :key="tag" class="tag compact">{{ tag }}</span>
|
|
336
|
+
</div>
|
|
337
|
+
<p v-else-if="scene.groupPath.length" class="asset-group-path">{{ scene.groupPath.join(' / ') }}</p>
|
|
338
|
+
</div>
|
|
339
|
+
<button class="icon-button" :aria-label="$t('关闭')" :disabled="busy" @click="$refs.detail.close()"><X :size="20" /></button>
|
|
340
|
+
</header>
|
|
341
|
+
<div class="tabs">
|
|
342
|
+
<button v-for="entry in detailTabs"
|
|
343
|
+
:key="entry.key" :disabled="busy" :class="{ current: tab === entry.key }" :aria-pressed="tab === entry.key"
|
|
344
|
+
@click="changeTab(entry.key)">{{ $t(entry.name) }}</button>
|
|
345
|
+
</div>
|
|
346
|
+
<div ref="detailBody" class="dialog-body">
|
|
347
|
+
<p v-if="error" class="error" role="alert">{{ error }}</p>
|
|
348
|
+
<form v-if="tab === 'overview'" class="edit-form" @submit.prevent="saveOverview">
|
|
349
|
+
<label class="field">{{ $t('名称') }}
|
|
350
|
+
<input :value="overviewDraft.name ?? scene.name" required :disabled="busy"
|
|
351
|
+
@input="overviewDraft.name = $event.target.value">
|
|
352
|
+
</label>
|
|
353
|
+
<div class="asset-tag-field">
|
|
354
|
+
<label class="field" for="image-asset-tags">{{ $t('标签') }}</label>
|
|
355
|
+
<AssetTagInput id="image-asset-tags" :model-value="overviewDraft.tags ?? scene.tags ?? []" :disabled="busy"
|
|
356
|
+
@update:model-value="overviewDraft.tags = $event" />
|
|
357
|
+
</div>
|
|
358
|
+
<label class="field">{{ $t('备注') }}
|
|
359
|
+
<textarea :value="overviewDraft.note ?? scene.note" rows="8" :placeholder="$t('写点笔记…')" :disabled="busy"
|
|
360
|
+
@input="overviewDraft.note = $event.target.value"></textarea>
|
|
361
|
+
</label>
|
|
362
|
+
<div class="dialog-actions overview-actions">
|
|
363
|
+
<AssetDeleteButton :asset-name="scene.name" :busy="busy" @confirm="deleteAsset" />
|
|
364
|
+
<button class="primary overview-save-button" :disabled="busy">{{ $t('保存') }}</button>
|
|
365
|
+
</div>
|
|
366
|
+
</form>
|
|
367
|
+
<template v-else-if="tab === 'cover' || inGallery">
|
|
368
|
+
<div v-if="inGallery && filteredImages.length" class="scene-thumbnails"
|
|
369
|
+
:class="{ 'contain-thumbnails': !isScene }" :aria-label="isOther ? $t('扩展图片') : $t('{category}图片', { category: $t(scene.groups[tab]) })">
|
|
370
|
+
<button v-for="image in filteredImages" :key="image.id" :disabled="busy" :aria-pressed="selectedId === image.id" @click="selectImage(image.id)">
|
|
371
|
+
<img v-if="image.url" :src="image.url" alt="" loading="lazy"><span>{{ image.label }}</span>
|
|
372
|
+
</button>
|
|
373
|
+
</div>
|
|
374
|
+
<form v-if="imageForm" class="edit-form scene-edit" @submit.prevent="uploadImage">
|
|
375
|
+
<fieldset class="scene-image-fields" :disabled="busy">
|
|
376
|
+
<label v-if="!simpleCover && (!isProp || imageForm.replaceFile)" class="field">{{ $t('图片名称') }}<input v-model="imageForm.label" required></label>
|
|
377
|
+
<div v-if="!simpleCover && (!isProp || imageForm.replaceFile)" class="scene-field-row">
|
|
378
|
+
<label v-if="!isProp && (!isScene || (imageForm.replaceFile && inGallery))" class="field">{{ $t('分类') }}<select v-model="imageForm.category"><option v-for="(label, key) in scene.groups" :key="key" :value="key">{{ $t(label) }}</option></select></label>
|
|
379
|
+
<label class="field">{{ $t('采用状态') }}<select v-model="imageForm.status"><option v-for="(label, key) in scene.statuses" :key="key" :value="key">{{ $t(label) }}</option></select></label>
|
|
380
|
+
</div>
|
|
381
|
+
<label v-if="imageForm.replaceFile" class="field">{{ $t('选择图片') }}<input type="file" accept=".png,.jpg,.jpeg,.webp,.avif" required @change="imageForm.file = $event.target.files[0]"></label>
|
|
382
|
+
<div v-if="isScene" class="scene-field-row scene-conditions">
|
|
383
|
+
<label v-for="key in ['season', 'time', 'weather']" :key="key" class="field">{{ $t('{category}(选填)', { category: $t(scene.groups[key]) }) }}<input v-model="imageForm.conditions[key]"></label>
|
|
384
|
+
</div>
|
|
385
|
+
<label class="field">{{ $t('生成词') }}<textarea v-model="imageForm.prompt" rows="4"></textarea></label>
|
|
386
|
+
<div class="dialog-actions create-actions">
|
|
387
|
+
<button type="button" class="secondary" @click="imageForm = null; error = ''">{{ $t('取消') }}</button>
|
|
388
|
+
<button class="primary">{{ $t(imageForm.replaceFile ? '保存图片' : '保存资料') }}</button>
|
|
389
|
+
</div>
|
|
390
|
+
</fieldset>
|
|
391
|
+
</form>
|
|
392
|
+
<template v-else-if="activeImage">
|
|
393
|
+
<a v-if="activeImage.url" :href="activeImage.url" target="_blank" rel="noopener noreferrer">
|
|
394
|
+
<img class="detail-image" :class="{ 'transparent-preview': kind === 'other' || scene.transparentPreview || activeImage.category === 'graphic' }" :src="activeImage.url" :alt="activeImage.label">
|
|
395
|
+
</a>
|
|
396
|
+
<p v-else class="empty">{{ $t('找不到图片文件 {file}', { file: activeImage.file }) }}</p>
|
|
397
|
+
<div v-if="tab === 'cover'" class="media-actions">
|
|
398
|
+
<button type="button" class="secondary" :disabled="busy" @click="editImage(activeImage)">
|
|
399
|
+
<RefreshCw v-if="activeImage.url" :size="14" />
|
|
400
|
+
<Upload v-else :size="15" />
|
|
401
|
+
{{ activeImage.url ? $t('替换主图') : $t('上传主图') }}
|
|
402
|
+
</button>
|
|
403
|
+
</div>
|
|
404
|
+
<div v-else class="scene-toolbar scene-image-info">
|
|
405
|
+
<div>
|
|
406
|
+
<strong>{{ activeImage.label }}</strong>
|
|
407
|
+
</div>
|
|
408
|
+
</div>
|
|
409
|
+
<section v-if="tab === 'cover' && activeImage.url" class="prompt" :aria-label="$t('生成词')">
|
|
410
|
+
<div class="prompt-heading">
|
|
411
|
+
<strong>{{ $t('生成词') }}</strong>
|
|
412
|
+
<button v-if="promptDraft === null" type="button" class="secondary" :disabled="busy"
|
|
413
|
+
@click="promptDraft = activeImage.prompt || ''; error = ''">
|
|
414
|
+
<component :is="activeImage.prompt ? 'Pencil' : 'Plus'" :size="14" aria-hidden="true" />
|
|
415
|
+
{{ activeImage.prompt ? $t('编辑生成词') : $t('添加生成词') }}
|
|
416
|
+
</button>
|
|
417
|
+
</div>
|
|
418
|
+
<form v-if="promptDraft !== null" @submit.prevent="saveImagePrompt">
|
|
419
|
+
<label class="field"><span class="visually-hidden">{{ $t('图片生成词') }}</span>
|
|
420
|
+
<textarea v-model="promptDraft" rows="4" :disabled="busy"></textarea>
|
|
421
|
+
</label>
|
|
422
|
+
<div class="dialog-actions">
|
|
423
|
+
<button class="primary" :disabled="busy">{{ $t('保存生成词') }}</button>
|
|
424
|
+
<button type="button" class="secondary" :disabled="busy" @click="promptDraft = null; error = ''">{{ $t('取消') }}</button>
|
|
425
|
+
</div>
|
|
426
|
+
</form>
|
|
427
|
+
<pre v-else-if="activeImage.prompt">{{ activeImage.prompt }}</pre>
|
|
428
|
+
</section>
|
|
429
|
+
<section v-else-if="activeImage.prompt" class="prompt"><strong>{{ $t('生成词') }}</strong><pre>{{ activeImage.prompt }}</pre></section>
|
|
430
|
+
</template>
|
|
431
|
+
<template v-else>
|
|
432
|
+
<div class="detail-placeholder"><Image :size="25" />{{ tab === 'cover' ? $t('待补主图') : $t('暂无图片') }}</div>
|
|
433
|
+
<button v-if="tab === 'cover'" class="secondary" :disabled="busy" @click="editImage()"><Upload :size="15" />{{ $t('上传主图') }}</button>
|
|
434
|
+
</template>
|
|
435
|
+
</template>
|
|
436
|
+
<AssetStoryEditor v-else-if="tab === 'story'" v-model:draft="storyDraft" :busy="busy"
|
|
437
|
+
@edit="storyDraft = scene.story; error = ''" @cancel="storyDraft = null; error = ''" @save="saveStory">
|
|
438
|
+
<ProjectMarkdown v-if="scene.story" :source="scene.story" :file="storyPath" />
|
|
439
|
+
<p v-else class="empty">{{ $t('还没有' + (isOther ? '' : assetLabel) + '说明。') }}</p>
|
|
440
|
+
</AssetStoryEditor>
|
|
441
|
+
<AssetHistory v-else-if="tab === 'history'" :versions="scene.history" :group="kind + '-history'">
|
|
442
|
+
<template #description="{ version }"><small v-if="version.note">{{ version.note }}</small></template>
|
|
443
|
+
<template #default="{ version }">
|
|
444
|
+
<div v-for="image in version.images" :key="image.file">
|
|
445
|
+
<strong>{{ image.label }}</strong>
|
|
446
|
+
<a v-if="image.url" :href="image.url" target="_blank" rel="noopener noreferrer"><img :src="image.url" :alt="image.label" loading="lazy"></a>
|
|
447
|
+
<div v-if="image.prompt" class="prompt"><strong>{{ $t('生成词') }}</strong><pre>{{ image.prompt }}</pre></div>
|
|
448
|
+
</div>
|
|
449
|
+
<ProjectMarkdown v-if="version.story" :source="version.story" :file="storyPath" />
|
|
450
|
+
</template>
|
|
451
|
+
</AssetHistory>
|
|
452
|
+
</div>
|
|
453
|
+
</template>
|
|
454
|
+
</dialog>
|
|
455
|
+
</section>
|
|
456
|
+
</template>
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { ChevronRight } from 'lucide-vue-next'
|
|
3
|
+
import ProjectMarkdown from '@/components/ProjectMarkdown.vue'
|
|
4
|
+
import { projectFileUrl } from '@/service/project-markdown.js'
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
components: { ChevronRight, ProjectMarkdown },
|
|
8
|
+
data() {
|
|
9
|
+
return { documents: [], active: null, article: '', error: '', revision: 0 }
|
|
10
|
+
},
|
|
11
|
+
computed: {
|
|
12
|
+
groups() {
|
|
13
|
+
const groups = new Map()
|
|
14
|
+
for (const document of this.documents) {
|
|
15
|
+
if (!groups.has(document.group)) groups.set(document.group, [])
|
|
16
|
+
groups.get(document.group).push(document)
|
|
17
|
+
}
|
|
18
|
+
return [...groups]
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
async mounted() {
|
|
22
|
+
import.meta.hot?.on('workbench:settings:changed', this.refresh)
|
|
23
|
+
import.meta.hot?.on('workbench:scenes:changed', this.refresh)
|
|
24
|
+
try {
|
|
25
|
+
const response = await fetch('/api/settings')
|
|
26
|
+
if (!response.ok) throw new Error(this.$t('无法读取项目设定目录'))
|
|
27
|
+
this.documents = await response.json()
|
|
28
|
+
if (this.documents.length) await this.open(this.documents[0])
|
|
29
|
+
} catch (cause) {
|
|
30
|
+
this.error = cause.message
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
beforeUnmount() {
|
|
34
|
+
this.revision++
|
|
35
|
+
import.meta.hot?.off('workbench:settings:changed', this.refresh)
|
|
36
|
+
import.meta.hot?.off('workbench:scenes:changed', this.refresh)
|
|
37
|
+
},
|
|
38
|
+
methods: {
|
|
39
|
+
refresh() {
|
|
40
|
+
if (this.active) return this.open(this.active, true)
|
|
41
|
+
},
|
|
42
|
+
async open(document, keepArticle = false) {
|
|
43
|
+
const revision = ++this.revision
|
|
44
|
+
this.active = document
|
|
45
|
+
if (!keepArticle) this.article = ''
|
|
46
|
+
this.error = ''
|
|
47
|
+
try {
|
|
48
|
+
const response = await fetch(projectFileUrl(document.file))
|
|
49
|
+
if (!response.ok) throw new Error(this.$t('无法读取 {file}', { file: document.file }))
|
|
50
|
+
const markdown = await response.text()
|
|
51
|
+
if (revision === this.revision) this.article = markdown
|
|
52
|
+
} catch (cause) {
|
|
53
|
+
if (revision === this.revision) this.error = cause.message
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<template>
|
|
61
|
+
<section class="content">
|
|
62
|
+
<div class="heading"><h1>{{ $t('项目设定') }}</h1></div>
|
|
63
|
+
<p v-if="error" class="error" role="alert">{{ error }}</p>
|
|
64
|
+
<div class="settings-layout">
|
|
65
|
+
<nav class="settings-index" :aria-label="$t('项目设定目录')">
|
|
66
|
+
<div v-for="[group, items] in groups" :key="group">
|
|
67
|
+
<h2>{{ $t(group) }}</h2>
|
|
68
|
+
<button v-for="document in items" :key="document.file" :class="{ current: active?.file === document.file }"
|
|
69
|
+
:aria-current="active?.file === document.file ? 'page' : undefined" @click="open(document)">
|
|
70
|
+
{{ $t(document.title) }}<ChevronRight :size="14" />
|
|
71
|
+
</button>
|
|
72
|
+
</div>
|
|
73
|
+
</nav>
|
|
74
|
+
<div v-if="active" class="settings-reader">
|
|
75
|
+
<div class="settings-source">{{ active.file }}</div>
|
|
76
|
+
<ProjectMarkdown :source="article" :file="active.file" show-images />
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
</section>
|
|
80
|
+
</template>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# 资产管理约定
|
|
2
|
+
|
|
3
|
+
| 资产 | 目录 |
|
|
4
|
+
| --- | --- |
|
|
5
|
+
| 角色 | [assets/characters/](assets/characters/README.md) |
|
|
6
|
+
| 场景 | [assets/scenes/](assets/scenes/README.md) |
|
|
7
|
+
| 道具 | [assets/props/](assets/props/README.md) |
|
|
8
|
+
| 其他素材 | [assets/other/](assets/other/README.md) |
|
|
9
|
+
| 音频 | [assets/audio/](assets/audio/README.md) |
|
|
10
|
+
|
|
11
|
+
- 每项资产用独立目录。资产根目录放 `index.json` 和 `README.md`,名称、标签和备注分别写入索引的 `name`、`tags`、`note`。制作说明写入 README,素材引用使用相对于资产目录的路径。
|
|
12
|
+
- 需要分组时,每层分组用内容为 `{}` 的 `group.json` 标记,例如 `assets/props/宫廷/服饰/龙纹玉佩/` 的「宫廷」和「服饰」。同库内按完整相对路径区分同名资产。分组名会继承为标签,可用 `hiddenGroupTags` 隐藏指定继承标签。
|
|
13
|
+
- 场景、道具和其他图片用 `images` 登记。条目包含 `id`、`file`、`label`、`category` 和已知的 `status`,`mainImage` 指向主图条目的 ID。实际生成词写入条目的 `prompt`,或通过 `promptRecord` 和可选的 `promptEntry` 引用。标记为采用前,先确认用户已选定该版本。
|
|
14
|
+
- 替换现行素材、修订已有生成词或资产说明前,把上一版保存到该资产的 `archive/YYYY-MM-DD-vNNN/`,并在索引的 `history` 登记。移动或改名时同步更新当前索引及相关引用。
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# 音频资产
|
|
2
|
+
|
|
3
|
+
这里存放可复用的音乐、音效和台词素材。环境底声归音效,角色音色随角色放在 `voice/`。
|
|
4
|
+
|
|
5
|
+
每项资产一个目录,音频文件放 `tracks/`。用 `index.json` 的 `tracks` 登记音轨,`mainTrack` 指向主音轨的 ID。音轨条目包含 `id`、`file`、`label` 和 `category`。资产类型 `type` 和音轨分类 `category` 都可用 `music`、`effect` 或 `dialogue`。用途记在资产的 `note`,音轨来源与授权记在 `source`,可循环时标记 `loop`。
|
package/vite.config.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url'
|
|
2
|
+
import { defineConfig } from 'vite'
|
|
3
|
+
import vue from '@vitejs/plugin-vue'
|
|
4
|
+
import { workbenchPlugins } from './server/index.js'
|
|
5
|
+
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
plugins: [vue(), ...workbenchPlugins()],
|
|
8
|
+
resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } },
|
|
9
|
+
server: { host: '127.0.0.1', port: 24074, strictPort: true },
|
|
10
|
+
})
|