cortico-world-fun 0.9.2 → 0.9.3
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/CHANGELOG.md +6 -0
- package/describe.json +758 -610
- package/dist/webui.js +370 -63
- package/package.json +1 -1
- package/src/ENV_PROMPT.md +1 -0
- package/src/outing-service.js +11 -1
- package/src/place-service.js +94 -11
- package/src/story-venue-migration.js +2 -1
- package/src/venues.js +6 -0
- package/src/world-decls.js +30 -0
- package/src/world.js +4 -0
package/dist/webui.js
CHANGED
|
@@ -4794,6 +4794,39 @@ function mountFishStory(ctx) {
|
|
|
4794
4794
|
|
|
4795
4795
|
// webui/places/helpers.js
|
|
4796
4796
|
var list2 = (value) => Array.isArray(value) ? value : [];
|
|
4797
|
+
var PLACE_LIMITS = { name: 40, desc: 400, style: 160, scene: 40, kind: 40, aliases: 40, tags: 24, note: 80 };
|
|
4798
|
+
var DIRECTION_PATTERN = /路线|导航|坐标|左转|右转|距离|路程|公里|千米|几分钟|[\d一二三四五六七八九十百几]+\s*(?:米|分钟|小时)|(?:向|往|朝|正)[东西南北]|[东西南北](?:侧|面|边|方)|(?:左|右)(?:侧|边|面)|\b(?:routes?|navigation|coordinates?|distance|east|west|north|south)\b/i;
|
|
4799
|
+
function placeTextIssues(value, key) {
|
|
4800
|
+
const text2 = String(value ?? "").replace(/\s+/gu, " ").trim();
|
|
4801
|
+
const issues = [];
|
|
4802
|
+
if (PLACE_LIMITS[key] && Array.from(text2).length > PLACE_LIMITS[key]) issues.push(`超过 ${PLACE_LIMITS[key]} 字上限`);
|
|
4803
|
+
if (DIRECTION_PATTERN.test(text2)) issues.push("含方向或路线词,请改为空间与陈设描写");
|
|
4804
|
+
return issues;
|
|
4805
|
+
}
|
|
4806
|
+
function placePreviewIssues(place) {
|
|
4807
|
+
const issues = [];
|
|
4808
|
+
const visit = (value, path, key) => {
|
|
4809
|
+
if (typeof value === "string") issues.push(...placeTextIssues(value, key).map((issue) => `${path}:${issue}`));
|
|
4810
|
+
else if (Array.isArray(value)) value.forEach((item, index) => visit(item, `${path}[${index + 1}]`, key));
|
|
4811
|
+
else if (value && typeof value === "object") {
|
|
4812
|
+
for (const [child, entry] of Object.entries(value)) visit(entry, path ? `${path}.${child}` : child, child);
|
|
4813
|
+
}
|
|
4814
|
+
};
|
|
4815
|
+
visit(place, "", "");
|
|
4816
|
+
return issues;
|
|
4817
|
+
}
|
|
4818
|
+
function placeOpenNow(place, now = /* @__PURE__ */ new Date()) {
|
|
4819
|
+
const minutes = (value) => {
|
|
4820
|
+
if (typeof value !== "string" || !/^(?:[01]\d|2[0-3]):[0-5]\d$/.test(value)) return null;
|
|
4821
|
+
const [hour, minute] = value.split(":").map(Number);
|
|
4822
|
+
return hour * 60 + minute;
|
|
4823
|
+
};
|
|
4824
|
+
const open = minutes(place.hours?.open);
|
|
4825
|
+
const close = minutes(place.hours?.close);
|
|
4826
|
+
if (open === null || close === null) return true;
|
|
4827
|
+
const current = now.getHours() * 60 + now.getMinutes();
|
|
4828
|
+
return close <= open ? current >= open || current < close : current >= open && current < close;
|
|
4829
|
+
}
|
|
4797
4830
|
function dom(document2) {
|
|
4798
4831
|
function node2(tag, attributes, ...children) {
|
|
4799
4832
|
const element = document2.createElement(tag);
|
|
@@ -5147,7 +5180,10 @@ var HOME_STYLES = `
|
|
|
5147
5180
|
.fhm-stage-wrap{position:relative}
|
|
5148
5181
|
.fhm-stage{aspect-ratio:16/9;overflow:hidden}
|
|
5149
5182
|
.fhm-hud{position:absolute;z-index:12;left:14px;right:14px;top:12px;display:flex;align-items:center;gap:10px;padding:7px 11px;border:1px solid #ffffff70;border-radius:14px;background:#fff9;backdrop-filter:blur(12px);color:#413b38;font-size:12px}
|
|
5150
|
-
.fhm-hud strong{font-size:13px}.fhm-hud .fhm-status,.fhm-hud .fhm-place{position:static;margin:0;padding:0;border:0;background:none;max-width:
|
|
5183
|
+
.fhm-hud strong{font-size:13px;flex-shrink:0}.fhm-stage .fhm-hud .fhm-status,.fhm-stage .fhm-hud .fhm-place{position:static;margin:0;padding:0;border:0;background:none;max-width:24%;font-size:inherit;box-shadow:none}
|
|
5184
|
+
.fhm-hud .fhm-status,.fhm-hud .fhm-place,.fhm-hud .fhm-residence{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
5185
|
+
.fhm-hud .fhm-residence{flex:1 1 40%;color:inherit;text-decoration:underline;text-decoration-color:#8b684880;text-underline-offset:3px;border-radius:3px}
|
|
5186
|
+
.fhm-hud .fhm-residence:hover{color:#79572e;text-decoration-color:currentColor}.fhm-hud .fhm-residence:focus-visible{outline:2px solid #ba8b44;outline-offset:2px}
|
|
5151
5187
|
.fhm-hud .fhm-place{margin-left:auto}.fhm-away-note{position:absolute;z-index:13;top:58px;right:16px;padding:8px 12px;border-radius:8px;background:#8b6848d9;color:white;box-shadow:0 4px 12px #35251933;font-size:12px}
|
|
5152
5188
|
.fhm-light[data-lamp="1"]{background:radial-gradient(ellipse at 50% 80%,#ffd76b55,transparent 58%),linear-gradient(#ffcf6b18,#ffb83b1f)!important}
|
|
5153
5189
|
.fhm-sleep{position:absolute;z-index:14;left:58%;top:26%;font-weight:700;color:#7784b9;animation:fhm-float 2.4s ease-in-out infinite}
|
|
@@ -5223,8 +5259,7 @@ function statusOf(snapshot) {
|
|
|
5223
5259
|
}
|
|
5224
5260
|
function placeOf(snapshot) {
|
|
5225
5261
|
if (snapshot.trip?.mode === "out") return { text: `去${snapshot.trip.placeName}逛着了`, out: true };
|
|
5226
|
-
|
|
5227
|
-
return { text: "还没设住所", out: false };
|
|
5262
|
+
return { text: "在家", out: false };
|
|
5228
5263
|
}
|
|
5229
5264
|
function mountHome(ctx) {
|
|
5230
5265
|
const root = ctx.root;
|
|
@@ -5361,13 +5396,14 @@ function mountHome(ctx) {
|
|
|
5361
5396
|
const hadSnapshot = Boolean(snapshot);
|
|
5362
5397
|
const wasReadOnly = readOnly();
|
|
5363
5398
|
const previousTrip = `${snapshot?.trip?.mode}:${snapshot?.trip?.placeName}`;
|
|
5399
|
+
const previousResidence = snapshot?.place?.name;
|
|
5364
5400
|
try {
|
|
5365
5401
|
const result = await call("state");
|
|
5366
5402
|
if (!accept(result)) throw new Error("房间状态返回不完整。");
|
|
5367
5403
|
loadError = null;
|
|
5368
5404
|
const hadRefreshHint = Boolean(refreshHint);
|
|
5369
5405
|
refreshHint = "";
|
|
5370
|
-
if (!hadSnapshot || wasReadOnly !== readOnly() || hadRefreshHint || previousTrip !== `${snapshot.trip?.mode}:${snapshot.trip?.placeName}`) {
|
|
5406
|
+
if (!hadSnapshot || wasReadOnly !== readOnly() || hadRefreshHint || previousResidence !== snapshot.place?.name || previousTrip !== `${snapshot.trip?.mode}:${snapshot.trip?.placeName}`) {
|
|
5371
5407
|
render();
|
|
5372
5408
|
return;
|
|
5373
5409
|
}
|
|
@@ -5538,7 +5574,15 @@ function mountHome(ctx) {
|
|
|
5538
5574
|
const placeNode = el2(document2, "p", { class: "fhm-place", "data-out": place.out ? "1" : "0", text: place.text });
|
|
5539
5575
|
refs.status = status;
|
|
5540
5576
|
refs.place = placeNode;
|
|
5541
|
-
|
|
5577
|
+
const residenceText = snapshot.place?.name ? `住所:${snapshot.place.name}` : "去选一处住所";
|
|
5578
|
+
const residence = el2(document2, "a", {
|
|
5579
|
+
class: "fhm-residence",
|
|
5580
|
+
href: `#/provider/${encodeURIComponent(ctx.pageId || "world:fun")}/outing`,
|
|
5581
|
+
text: residenceText,
|
|
5582
|
+
title: `${residenceText} · 前往出游 / 地点册`,
|
|
5583
|
+
"aria-label": `${residenceText},前往出游 / 地点册`
|
|
5584
|
+
});
|
|
5585
|
+
stage.append(el2(document2, "div", { class: "fhm-hud" }, el2(document2, "strong", { text: "鱼的家" }), status, residence, placeNode));
|
|
5542
5586
|
stage.append(el2(document2, "div", {
|
|
5543
5587
|
class: "fhm-light",
|
|
5544
5588
|
"data-phase": snapshot.phase ?? "day",
|
|
@@ -7078,6 +7122,20 @@ var STYLES2 = `
|
|
|
7078
7122
|
.fpl input:not([type=checkbox]), .fpl textarea, .fpl select { width: 100%; }
|
|
7079
7123
|
.fpl input[type=range], .fpl input[type=checkbox] { accent-color: var(--fpl-accent); }
|
|
7080
7124
|
.fpl textarea { resize: vertical; }
|
|
7125
|
+
.fpl-paste textarea { min-height: 180px; font-family: ui-monospace, monospace; font-size: 13px; }
|
|
7126
|
+
.fpl-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--fpl-line); padding-bottom: 6px; }
|
|
7127
|
+
.fpl .fpl-tabs [aria-selected=true] { background: var(--fpl-soft); border-color: var(--fpl-accent); font-weight: 600; }
|
|
7128
|
+
.fpl-counter { justify-self: end; color: var(--fpl-muted); font-size: 12px; font-weight: 400; font-variant-numeric: tabular-nums; }
|
|
7129
|
+
.fpl [aria-invalid=true] { border-color: var(--destructive, #ae4141); }
|
|
7130
|
+
.fpl-field .fpl-error { font-size: 12px; font-weight: 400; }
|
|
7131
|
+
.fpl-diff { border: 1px solid var(--fpl-line); border-radius: 8px; overflow: hidden; }
|
|
7132
|
+
.fpl-diff summary, .fpl-diff h4 { padding: 8px 12px; background: var(--fpl-soft); }
|
|
7133
|
+
.fpl-diff-field { border-top: 1px solid var(--fpl-line); }
|
|
7134
|
+
.fpl-diff pre { margin: 0; padding: 8px 12px; white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.7 ui-monospace, monospace; }
|
|
7135
|
+
.fpl-diff-before { background: #ffebe9; color: #82071e; }
|
|
7136
|
+
.fpl-diff-after { background: #dafbe1; color: #116329; }
|
|
7137
|
+
.fpl .fpl-home-check { align-items: center; cursor: pointer; }
|
|
7138
|
+
.fpl-home-check input { width: 18px; height: 18px; margin: 0; }
|
|
7081
7139
|
.fpl button { cursor: pointer; }
|
|
7082
7140
|
.fpl button:hover:not(:disabled), .fpl button[aria-current=page] { border-color: var(--fpl-accent); background: var(--fpl-soft); }
|
|
7083
7141
|
.fpl button.fpl-primary { background: var(--fpl-primary); border-color: var(--fpl-primary); color: var(--fpl-primary-ink); font-weight: 600; }
|
|
@@ -7145,7 +7203,7 @@ var STYLES2 = `
|
|
|
7145
7203
|
.fpl-search { display: flex; align-items: center; flex: 1; min-width: 0; }
|
|
7146
7204
|
.fpl-search input { width: 100%; min-width: 0; padding: 10px 12px; border: 1px solid var(--fpl-line); border-radius: 9px; background: var(--fpl-card); }
|
|
7147
7205
|
.fpl-toolbar select { flex: none; width: 132px; max-width: 100%; padding: 9px 10px; border: 1px solid var(--fpl-line); border-radius: 9px; background: var(--fpl-card); }
|
|
7148
|
-
.fpl-panehead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
|
|
7206
|
+
.fpl-panehead { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
|
|
7149
7207
|
.fpl-pane-count { margin: 0; font-size: 11px; color: var(--fpl-muted); }
|
|
7150
7208
|
.fpl-viewtoggle { min-height: 0; padding: 4px 8px; border: 1px solid transparent; border-radius: 7px; background: none; color: var(--fpl-muted); font-size: 11.5px; }
|
|
7151
7209
|
.fpl button.fpl-viewtoggle { border-color: transparent; background: none; }
|
|
@@ -7221,6 +7279,46 @@ var STYLES2 = `
|
|
|
7221
7279
|
// webui/places/webui.js
|
|
7222
7280
|
var split = (value) => [...new Set(value.split(/[\n,、,;;]+/u).map((item) => item.trim()).filter(Boolean))];
|
|
7223
7281
|
var MAX_IMAGE_BYTES3 = 8 * 1024 * 1024;
|
|
7282
|
+
var placeBundle = (place) => ({ format: "little-world", version: 1, state: { version: 1, places: [place], homeId: null }, covers: {} });
|
|
7283
|
+
function parsePlace(text2) {
|
|
7284
|
+
let parsed;
|
|
7285
|
+
try {
|
|
7286
|
+
parsed = JSON.parse(String(text2).replace(/^\uFEFF/, ""));
|
|
7287
|
+
} catch {
|
|
7288
|
+
throw new Error("JSON 格式无效,请检查引号、逗号和括号。");
|
|
7289
|
+
}
|
|
7290
|
+
const imported = parsed?.format === "little-world" ? parsed.state?.places?.[0] : parsed?.place ?? parsed;
|
|
7291
|
+
if (!imported || typeof imported !== "object" || Array.isArray(imported) || typeof imported.name !== "string" || !imported.name.trim()) throw new Error("地点草稿缺少有效的地点名称(name)。");
|
|
7292
|
+
for (const key of ["desc", "scene", "kind", "crowd", "recommendedOutfit", "style"]) {
|
|
7293
|
+
if (imported[key] != null && typeof imported[key] !== "string") throw new Error(`地点字段 ${key} 必须是文本。`);
|
|
7294
|
+
}
|
|
7295
|
+
for (const key of ["aliases", "tags", "areas", "souvenirs", "photoSpots", "randomEvents"]) {
|
|
7296
|
+
if (imported[key] != null && (!Array.isArray(imported[key]) || imported[key].some((item) => typeof item !== "string"))) {
|
|
7297
|
+
throw new Error(`地点字段 ${key} 必须是文本数组。`);
|
|
7298
|
+
}
|
|
7299
|
+
}
|
|
7300
|
+
if (imported.food != null && (typeof imported.food !== "object" || Array.isArray(imported.food) || !["吃", "喝"].includes(imported.food.verb) || !Array.isArray(imported.food.items) || imported.food.items.some((item) => typeof item !== "string"))) throw new Error("地点字段 food 必须包含餐饮类型(吃 / 喝)与文本数组 items。");
|
|
7301
|
+
const fields = [
|
|
7302
|
+
"name",
|
|
7303
|
+
"aliases",
|
|
7304
|
+
"tags",
|
|
7305
|
+
"kind",
|
|
7306
|
+
"desc",
|
|
7307
|
+
"style",
|
|
7308
|
+
"scene",
|
|
7309
|
+
"relations",
|
|
7310
|
+
"hours",
|
|
7311
|
+
"crowd",
|
|
7312
|
+
"recommendedOutfit",
|
|
7313
|
+
"areas",
|
|
7314
|
+
"souvenirs",
|
|
7315
|
+
"photoSpots",
|
|
7316
|
+
"randomEvents",
|
|
7317
|
+
"food",
|
|
7318
|
+
"playable"
|
|
7319
|
+
];
|
|
7320
|
+
return { ...Object.fromEntries(Object.entries(imported).filter(([key]) => fields.includes(key))), name: imported.name.trim() };
|
|
7321
|
+
}
|
|
7224
7322
|
var kinds = { home: "家", around: "附近", frequent: "常去", travel: "旅行", venue: "娱乐场所", place: "普通地点" };
|
|
7225
7323
|
var kindLabel = (place) => place.kindLabel || kinds[place.kind] || place.kind || (place.playable ? "自填场所" : "普通地点");
|
|
7226
7324
|
var CATEGORY_GROUPS = [
|
|
@@ -7246,6 +7344,43 @@ var RAIL_SETTINGS = [
|
|
|
7246
7344
|
["migration", "从小世界迁入"]
|
|
7247
7345
|
];
|
|
7248
7346
|
var BROWSE_VIEWS = ["browse", "detail", "edit", "create", "cover"];
|
|
7347
|
+
var PLACE_TEMPLATES = [
|
|
7348
|
+
["居家小屋", {
|
|
7349
|
+
name: "我的小屋",
|
|
7350
|
+
kind: "home",
|
|
7351
|
+
desc: "暖灯照着木桌,柔软的沙发和书架让小屋安静舒适。",
|
|
7352
|
+
areas: ["客厅", "阅读角"],
|
|
7353
|
+
photoSpots: ["花瓶与书架"],
|
|
7354
|
+
souvenirs: ["手绘相片"],
|
|
7355
|
+
style: "温暖水彩"
|
|
7356
|
+
}],
|
|
7357
|
+
["街角小店", {
|
|
7358
|
+
name: "我的小店",
|
|
7359
|
+
kind: "food",
|
|
7360
|
+
desc: "木质柜台摆着杯碟,玻璃花瓶映着柔和的光。",
|
|
7361
|
+
areas: ["咖啡吧", "手作展示区"],
|
|
7362
|
+
photoSpots: ["花饰橱窗"],
|
|
7363
|
+
souvenirs: ["手作杯垫"],
|
|
7364
|
+
food: { verb: "喝", items: ["咖啡", "茶"] },
|
|
7365
|
+
style: "清新水彩"
|
|
7366
|
+
}],
|
|
7367
|
+
["户外去处", {
|
|
7368
|
+
name: "我的花园",
|
|
7369
|
+
kind: "park",
|
|
7370
|
+
desc: "草坪铺满阳光,花丛与树荫围着石凳。",
|
|
7371
|
+
areas: ["花圃", "草坪"],
|
|
7372
|
+
photoSpots: ["开花的树"],
|
|
7373
|
+
souvenirs: ["植物明信片"],
|
|
7374
|
+
style: "自然水彩"
|
|
7375
|
+
}]
|
|
7376
|
+
];
|
|
7377
|
+
var FILTER_CHIPS = [["open", "此刻营业中"], ["food", "能吃喝"], ["souvenirs", "有纪念品"], ["mine", "我的地点"]];
|
|
7378
|
+
var chipMatch = (place, key, now) => {
|
|
7379
|
+
if (key === "open") return placeOpenNow(place, now);
|
|
7380
|
+
if (key === "food") return list2(place.food?.items).length > 0;
|
|
7381
|
+
if (key === "souvenirs") return list2(place.souvenirs).length > 0;
|
|
7382
|
+
return place.userPlace === true;
|
|
7383
|
+
};
|
|
7249
7384
|
var quickMatch = (place, quick) => {
|
|
7250
7385
|
switch (quick) {
|
|
7251
7386
|
case "story":
|
|
@@ -7278,7 +7413,7 @@ function mountPlaces(ctx) {
|
|
|
7278
7413
|
return true;
|
|
7279
7414
|
};
|
|
7280
7415
|
const placeCardBytes = (place) => {
|
|
7281
|
-
const bundle =
|
|
7416
|
+
const bundle = placeBundle(place);
|
|
7282
7417
|
return encodePngTextChunk(
|
|
7283
7418
|
createCoverPng({ title: place.name, subtitle: "从0开始的肥鱼大冒险 · 地点卡" }),
|
|
7284
7419
|
"cortico-fun-place",
|
|
@@ -7320,12 +7455,13 @@ function mountPlaces(ctx) {
|
|
|
7320
7455
|
let busy = false;
|
|
7321
7456
|
let disposed = false;
|
|
7322
7457
|
let focusAfterRender = false;
|
|
7323
|
-
let browseFilter = { text: "", kind: "", quick: "" };
|
|
7458
|
+
let browseFilter = { text: "", kind: "", quick: "", chips: [] };
|
|
7324
7459
|
let browseMode = ctx.memo?.get("fpl-browse-view", "list") === "grid" ? "grid" : "list";
|
|
7325
7460
|
const coverCache = /* @__PURE__ */ new Map();
|
|
7326
7461
|
let detailId;
|
|
7327
7462
|
let detail;
|
|
7328
7463
|
let editRevision;
|
|
7464
|
+
let createDraft;
|
|
7329
7465
|
let image;
|
|
7330
7466
|
let imageError;
|
|
7331
7467
|
let confirmAction;
|
|
@@ -7434,9 +7570,10 @@ function mountPlaces(ctx) {
|
|
|
7434
7570
|
tell(message);
|
|
7435
7571
|
}, { write: true });
|
|
7436
7572
|
}
|
|
7437
|
-
function go(next) {
|
|
7573
|
+
function go(next, draft) {
|
|
7438
7574
|
if (!live()) return;
|
|
7439
7575
|
view = next;
|
|
7576
|
+
createDraft = next === "create" ? draft : void 0;
|
|
7440
7577
|
editRevision = ["edit", "create", "cover", "settings"].includes(next) ? snapshot?.revision : void 0;
|
|
7441
7578
|
confirmAction = void 0;
|
|
7442
7579
|
focusAfterRender = true;
|
|
@@ -7573,36 +7710,105 @@ function mountPlaces(ctx) {
|
|
|
7573
7710
|
}, { class: "fpl-viewtoggle", "aria-pressed": "false" });
|
|
7574
7711
|
const importFile = node2("input", { type: "file", accept: ".json,.png,application/json,image/png", hidden: true, "aria-label": "导入地点 JSON 或 PNG 地点卡" });
|
|
7575
7712
|
const importButton = button2("导入地点卡", () => importFile.click(), { class: "fpl-import" });
|
|
7713
|
+
const importPlace = async (input) => {
|
|
7714
|
+
const result = await call("create", { input, revision: snapshot?.revision });
|
|
7715
|
+
if (!live()) return;
|
|
7716
|
+
accept(result);
|
|
7717
|
+
tell(`已导入地点「${input.name}」。`);
|
|
7718
|
+
render();
|
|
7719
|
+
};
|
|
7720
|
+
const pasteText = node2("textarea", { rows: 8, "aria-label": "地点 JSON 或地点草稿", placeholder: '{ "name": "河畔书店", "desc": "窗边总有阳光。", "areas": ["阅读区"] }', spellcheck: "false" });
|
|
7721
|
+
const pasteEdit = node2(
|
|
7722
|
+
"div",
|
|
7723
|
+
{ role: "tabpanel", id: "fpl-paste-edit", "aria-labelledby": "fpl-tab-edit" },
|
|
7724
|
+
field("地点 JSON 或地点草稿", pasteText, '支持 little-world 地点卡(取第一个地点)、单个地点对象或 { "place": { … } }。')
|
|
7725
|
+
);
|
|
7726
|
+
const pastePreview = node2("div", { class: "fpl-stack", role: "tabpanel", id: "fpl-paste-preview", "aria-labelledby": "fpl-tab-preview", "aria-live": "polite" });
|
|
7727
|
+
const showPasteTab = (preview) => {
|
|
7728
|
+
pasteEdit.hidden = preview;
|
|
7729
|
+
pastePreview.hidden = !preview;
|
|
7730
|
+
for (const [tab, selected] of [[editTab, !preview], [previewTab, preview]]) {
|
|
7731
|
+
tab.setAttribute("aria-selected", String(selected));
|
|
7732
|
+
tab.setAttribute("tabindex", selected ? "0" : "-1");
|
|
7733
|
+
}
|
|
7734
|
+
if (!preview) return;
|
|
7735
|
+
try {
|
|
7736
|
+
const draft = parsePlace(pasteText.value);
|
|
7737
|
+
const issues = placePreviewIssues(draft);
|
|
7738
|
+
pastePreview.replaceChildren(node2(
|
|
7739
|
+
"article",
|
|
7740
|
+
{ class: "fpl-card fpl-stack" },
|
|
7741
|
+
node2("h4", {}, draft.name),
|
|
7742
|
+
note2(`分类:${kindLabel(draft)} · 可逛项目:${list2(draft.areas).length} 项`),
|
|
7743
|
+
note2(`餐饮项:${list2(draft.food?.items).join("、") || "无"}`),
|
|
7744
|
+
draft.desc ? note2(draft.desc) : null,
|
|
7745
|
+
issues.length ? node2(
|
|
7746
|
+
"div",
|
|
7747
|
+
{ class: "fpl-error", role: "alert" },
|
|
7748
|
+
node2("p", {}, "校验提示:"),
|
|
7749
|
+
node2("ul", {}, issues.map((issue) => node2("li", {}, issue)))
|
|
7750
|
+
) : note2("未发现超长或方向词;保存时仍由后端最终校验。")
|
|
7751
|
+
));
|
|
7752
|
+
} catch (error) {
|
|
7753
|
+
pastePreview.replaceChildren(node2("p", { class: "fpl-error", role: "alert" }, error.message));
|
|
7754
|
+
}
|
|
7755
|
+
};
|
|
7756
|
+
const editTab = button2("编辑", () => showPasteTab(false), { role: "tab", id: "fpl-tab-edit", "aria-controls": "fpl-paste-edit" });
|
|
7757
|
+
const previewTab = button2("预览", () => showPasteTab(true), { role: "tab", id: "fpl-tab-preview", "aria-controls": "fpl-paste-preview" });
|
|
7758
|
+
const pasteTabs = node2("div", { class: "fpl-tabs", role: "tablist", "aria-label": "粘贴导入模式" }, editTab, previewTab);
|
|
7759
|
+
pasteTabs.addEventListener("keydown", (event) => {
|
|
7760
|
+
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
|
|
7761
|
+
event.preventDefault();
|
|
7762
|
+
const preview = event.key === "End" || event.key !== "Home" && previewTab.getAttribute("aria-selected") !== "true";
|
|
7763
|
+
showPasteTab(preview);
|
|
7764
|
+
(preview ? previewTab : editTab).focus();
|
|
7765
|
+
});
|
|
7766
|
+
showPasteTab(false);
|
|
7767
|
+
const pastePanel = node2(
|
|
7768
|
+
"section",
|
|
7769
|
+
{ class: "fpl-card fpl-stack fpl-paste", "aria-label": "粘贴导入地点" },
|
|
7770
|
+
pasteTabs,
|
|
7771
|
+
pasteEdit,
|
|
7772
|
+
pastePreview,
|
|
7773
|
+
row(
|
|
7774
|
+
button2("直接导入", () => void run(() => importPlace(parsePlace(pasteText.value)), { write: true }), { class: "fpl-primary" }),
|
|
7775
|
+
button2("填入新建表单", () => void run(async () => {
|
|
7776
|
+
const draft = parsePlace(pasteText.value);
|
|
7777
|
+
go("create", draft);
|
|
7778
|
+
tell("已填入新建表单,微调后点击「添加地点」保存。");
|
|
7779
|
+
})),
|
|
7780
|
+
button2("取消粘贴", () => {
|
|
7781
|
+
pastePanel.hidden = true;
|
|
7782
|
+
pasteButton.setAttribute("aria-expanded", "false");
|
|
7783
|
+
pasteButton.focus();
|
|
7784
|
+
})
|
|
7785
|
+
)
|
|
7786
|
+
);
|
|
7787
|
+
pastePanel.hidden = true;
|
|
7788
|
+
const pasteButton = button2("粘贴导入", () => {
|
|
7789
|
+
pastePanel.hidden = !pastePanel.hidden;
|
|
7790
|
+
pasteButton.setAttribute("aria-expanded", String(!pastePanel.hidden));
|
|
7791
|
+
if (!pastePanel.hidden) {
|
|
7792
|
+
showPasteTab(false);
|
|
7793
|
+
pasteText.focus();
|
|
7794
|
+
}
|
|
7795
|
+
}, { class: "fpl-import", "aria-expanded": "false" });
|
|
7576
7796
|
importFile.addEventListener("change", () => {
|
|
7577
7797
|
const file = importFile.files?.[0];
|
|
7578
7798
|
importFile.value = "";
|
|
7579
7799
|
if (!file) return;
|
|
7580
7800
|
void run(async () => {
|
|
7581
|
-
let
|
|
7801
|
+
let text2;
|
|
7582
7802
|
try {
|
|
7583
7803
|
if (String(file.type).toLowerCase() === "image/png" || /\.png$/iu.test(file.name)) {
|
|
7584
7804
|
const encoded = decodePngTextChunk(new Uint8Array(await file.arrayBuffer()), "cortico-fun-place");
|
|
7585
7805
|
if (!encoded) throw new Error("这张 PNG 没有地点卡元数据。");
|
|
7586
|
-
|
|
7587
|
-
} else
|
|
7806
|
+
text2 = new TextDecoder().decode(base64ToBytes(encoded));
|
|
7807
|
+
} else text2 = await file.text();
|
|
7588
7808
|
} catch (error) {
|
|
7589
7809
|
throw new Error(error?.message || "地点卡文件无法读取。");
|
|
7590
7810
|
}
|
|
7591
|
-
|
|
7592
|
-
if (!imported || typeof imported !== "object" || !String(imported.name || "").trim()) throw new Error("地点卡缺少地点名称。");
|
|
7593
|
-
const input = { ...imported };
|
|
7594
|
-
delete input.id;
|
|
7595
|
-
delete input.cover;
|
|
7596
|
-
delete input.coverFocus;
|
|
7597
|
-
delete input.kindLabel;
|
|
7598
|
-
delete input.storyBound;
|
|
7599
|
-
delete input.userPlace;
|
|
7600
|
-
delete input.effectiveStyle;
|
|
7601
|
-
delete input.isHome;
|
|
7602
|
-
const result = await call("create", { input, revision: snapshot?.revision });
|
|
7603
|
-
accept(result);
|
|
7604
|
-
tell(`已导入地点「${imported.name}」。`);
|
|
7605
|
-
render();
|
|
7811
|
+
await importPlace(parsePlace(text2));
|
|
7606
7812
|
}, { write: true });
|
|
7607
7813
|
});
|
|
7608
7814
|
const paintView = () => {
|
|
@@ -7614,8 +7820,9 @@ function mountPlaces(ctx) {
|
|
|
7614
7820
|
};
|
|
7615
7821
|
const display = () => {
|
|
7616
7822
|
const query = browseFilter.text.trim().toLocaleLowerCase();
|
|
7617
|
-
const
|
|
7618
|
-
const
|
|
7823
|
+
const now = /* @__PURE__ */ new Date();
|
|
7824
|
+
const matches = places().filter((place) => quickMatch(place, browseFilter.quick) && browseFilter.chips.every((key) => chipMatch(place, key, now)) && (!browseFilter.kind || categoryValue(place) === browseFilter.kind) && (!query || [place.name, place.desc, ...list2(place.aliases), ...list2(place.tags)].some((text2) => String(text2 ?? "").toLocaleLowerCase().includes(query))));
|
|
7825
|
+
const filtered = browseFilter.quick || browseFilter.kind || browseFilter.text.trim() || browseFilter.chips.length;
|
|
7619
7826
|
count.textContent = filtered ? `${matches.length} 处地点(共 ${places().length} 处)` : `${matches.length} 处地点 · 按分类浏览`;
|
|
7620
7827
|
const empty = () => createEmptyState({
|
|
7621
7828
|
doc: document2,
|
|
@@ -7623,7 +7830,7 @@ function mountPlaces(ctx) {
|
|
|
7623
7830
|
description: filtered ? "试试清除筛选,或者把喜欢的新地方加进来。" : "从一处喜欢的地方开始,写下名字和一句介绍就好。",
|
|
7624
7831
|
actionLabel: filtered ? "清除筛选" : "添加地点",
|
|
7625
7832
|
onAction: () => {
|
|
7626
|
-
browseFilter = { text: "", kind: "", quick: "" };
|
|
7833
|
+
browseFilter = { text: "", kind: "", quick: "", chips: [] };
|
|
7627
7834
|
go(filtered ? "browse" : "create");
|
|
7628
7835
|
}
|
|
7629
7836
|
});
|
|
@@ -7641,12 +7848,22 @@ function mountPlaces(ctx) {
|
|
|
7641
7848
|
browseFilter.kind = category.value;
|
|
7642
7849
|
display();
|
|
7643
7850
|
});
|
|
7851
|
+
const chips = node2("div", { class: "fpl-filters", role: "group", "aria-label": "快捷筛选" }, FILTER_CHIPS.map(([key, label2]) => {
|
|
7852
|
+
const toggle = button2(label2, () => {
|
|
7853
|
+
browseFilter.chips = browseFilter.chips.includes(key) ? browseFilter.chips.filter((item) => item !== key) : [...browseFilter.chips, key];
|
|
7854
|
+
toggle.setAttribute("aria-pressed", String(browseFilter.chips.includes(key)));
|
|
7855
|
+
display();
|
|
7856
|
+
}, { class: "fpl-chip-toggle", "aria-pressed": String(browseFilter.chips.includes(key)) });
|
|
7857
|
+
return toggle;
|
|
7858
|
+
}));
|
|
7644
7859
|
display();
|
|
7645
7860
|
return node2(
|
|
7646
7861
|
"section",
|
|
7647
7862
|
{ class: "fpl-stack" },
|
|
7648
7863
|
node2("div", { class: "fpl-toolbar" }, node2("label", { class: "fpl-search" }, search), category),
|
|
7649
|
-
|
|
7864
|
+
chips,
|
|
7865
|
+
node2("div", { class: "fpl-panehead" }, count, viewToggle, importButton, pasteButton, importFile),
|
|
7866
|
+
pastePanel,
|
|
7650
7867
|
listResults,
|
|
7651
7868
|
tileResults,
|
|
7652
7869
|
node2("p", { class: "fpl-pane-hint" }, "有「能逛的」就是可玩场所,留空也能作为地点保留。")
|
|
@@ -7828,12 +8045,26 @@ function mountPlaces(ctx) {
|
|
|
7828
8045
|
node2("h4", {}, place.food.verb === "喝" ? "能喝的" : "能吃的"),
|
|
7829
8046
|
row(place.food.items.map(chip))
|
|
7830
8047
|
) : null;
|
|
8048
|
+
const diffValue = (value) => value == null ? "(未设置)" : typeof value === "string" ? value || "(空)" : JSON.stringify(value, null, 2);
|
|
8049
|
+
const diff = place.preset && place.overridden && Array.isArray(place.overrideDiff) && place.overrideDiff.length ? node2(
|
|
8050
|
+
"details",
|
|
8051
|
+
{ class: "fpl-diff" },
|
|
8052
|
+
node2("summary", {}, "查看改动(Diff)"),
|
|
8053
|
+
place.overrideDiff.filter((entry) => entry && typeof entry === "object").map((entry) => node2(
|
|
8054
|
+
"section",
|
|
8055
|
+
{ class: "fpl-diff-field" },
|
|
8056
|
+
node2("h4", {}, entry.label || entry.field || entry.key || "字段"),
|
|
8057
|
+
node2("pre", { class: "fpl-diff-before" }, `- 原预设:${diffValue(Object.hasOwn(entry, "before") ? entry.before : entry.original)}`),
|
|
8058
|
+
node2("pre", { class: "fpl-diff-after" }, `+ 我的修改:${diffValue(Object.hasOwn(entry, "after") ? entry.after : entry.current)}`)
|
|
8059
|
+
))
|
|
8060
|
+
) : null;
|
|
7831
8061
|
return node2(
|
|
7832
8062
|
"section",
|
|
7833
8063
|
{ class: "fpl-card fpl-stack" },
|
|
7834
8064
|
row(node2("h3", { tabindex: -1 }, place.name), ...facts.map(chip)),
|
|
7835
8065
|
coverPreview(place),
|
|
7836
8066
|
node2("p", { class: "fpl-wrap" }, place.desc || "还没有地点描写。"),
|
|
8067
|
+
diff,
|
|
7837
8068
|
node2(
|
|
7838
8069
|
"div",
|
|
7839
8070
|
{ class: "fpl-stack" },
|
|
@@ -7861,6 +8092,10 @@ function mountPlaces(ctx) {
|
|
|
7861
8092
|
button2("导出地点卡 (PNG)", () => {
|
|
7862
8093
|
if (!downloadBytes(placeCardBytes(place), `${place.id || "place-card"}.png`, "image/png")) tell("当前环境不支持下载 PNG 地点卡。", true);
|
|
7863
8094
|
}),
|
|
8095
|
+
button2("导出 JSON", () => {
|
|
8096
|
+
const bytes2 = new TextEncoder().encode(JSON.stringify(placeBundle(place), null, 2));
|
|
8097
|
+
if (!downloadBytes(bytes2, `${place.name}.json`, "application/json;charset=utf-8")) tell("当前环境不支持下载 JSON。", true);
|
|
8098
|
+
}),
|
|
7864
8099
|
isHome(place) ? confirm("取消住所", `取消把「${place.name}」设为住所?`, () => submit("setHome", { id: null }, "已取消住所。", () => {
|
|
7865
8100
|
detail = find(place.id) ?? detail;
|
|
7866
8101
|
render();
|
|
@@ -7881,32 +8116,41 @@ function mountPlaces(ctx) {
|
|
|
7881
8116
|
)
|
|
7882
8117
|
);
|
|
7883
8118
|
}
|
|
7884
|
-
function editor(place) {
|
|
8119
|
+
function editor(place, draft) {
|
|
7885
8120
|
const locked = Boolean(place?.preset);
|
|
7886
|
-
const
|
|
7887
|
-
const
|
|
7888
|
-
const
|
|
8121
|
+
const source = place ?? draft;
|
|
8122
|
+
const setHome = node2("input", { type: "checkbox", checked: false, "aria-label": "顺便设为住所" });
|
|
8123
|
+
const name = node2("input", { value: source?.name || "", required: true });
|
|
8124
|
+
const aliases = node2("input", { value: list2(source?.aliases).join("、") });
|
|
8125
|
+
const kind = node2("input", { value: source?.kind || "", placeholder: "例如:附近", maxlength: 40, ...locked ? { readonly: "" } : {} });
|
|
7889
8126
|
const desc = node2("textarea", {
|
|
7890
8127
|
rows: place ? 4 : 2,
|
|
7891
|
-
maxlength: 400,
|
|
7892
8128
|
required: !place,
|
|
7893
8129
|
placeholder: "例如:一间临河的小书店,窗边总有阳光。"
|
|
7894
|
-
},
|
|
7895
|
-
const tags = node2("input", { value: list2(
|
|
7896
|
-
const scene = node2("input", { value:
|
|
7897
|
-
const open2 = node2("input", { value:
|
|
7898
|
-
const close = node2("input", { value:
|
|
8130
|
+
}, source?.desc || "");
|
|
8131
|
+
const tags = node2("input", { value: list2(source?.tags).join("、") });
|
|
8132
|
+
const scene = node2("input", { value: source?.scene || "", maxlength: 40, ...locked ? { readonly: "" } : {} });
|
|
8133
|
+
const open2 = node2("input", { value: source?.hours?.open || "09:00", placeholder: "HH:MM", maxlength: 5 });
|
|
8134
|
+
const close = node2("input", { value: source?.hours?.close || "21:00", placeholder: "HH:MM", maxlength: 5 });
|
|
7899
8135
|
const crowd = node2("select", {}, option("quiet", "人不多"), option("normal", "人不算多"), option("packed", "人很多"));
|
|
7900
|
-
crowd.value =
|
|
7901
|
-
const outfit = node2("input", { value:
|
|
7902
|
-
const areas = node2("textarea", { rows: 4, placeholder: "一行一处,至少一处才算能逛的场所" }, lines(
|
|
7903
|
-
const souvenirs = node2("textarea", { rows: 2, placeholder: "一行一样" }, lines(
|
|
7904
|
-
const photoSpots = node2("textarea", { rows: 2, placeholder: "一行一处" }, lines(
|
|
7905
|
-
const randomEvents = node2("textarea", { rows: 2, placeholder: "一行一条,可选" }, lines(
|
|
8136
|
+
crowd.value = source?.crowd ?? "normal";
|
|
8137
|
+
const outfit = node2("input", { value: source?.recommendedOutfit || "", maxlength: 40, placeholder: "可选,例如「外出外套」" });
|
|
8138
|
+
const areas = node2("textarea", { rows: 4, placeholder: "一行一处,至少一处才算能逛的场所" }, lines(source?.areas));
|
|
8139
|
+
const souvenirs = node2("textarea", { rows: 2, placeholder: "一行一样" }, lines(source?.souvenirs));
|
|
8140
|
+
const photoSpots = node2("textarea", { rows: 2, placeholder: "一行一处" }, lines(source?.photoSpots));
|
|
8141
|
+
const randomEvents = node2("textarea", { rows: 2, placeholder: "一行一条,可选" }, lines(source?.randomEvents));
|
|
7906
8142
|
const foodVerb = node2("select", {}, option("none", "没有"), option("喝", "喝的"), option("吃", "吃的"));
|
|
7907
|
-
foodVerb.value =
|
|
7908
|
-
const foodItems = node2("textarea", { rows: 2, placeholder: "品类名,一行一样;别写味道" }, lines(
|
|
7909
|
-
const style = node2("textarea", { rows: 2
|
|
8143
|
+
foodVerb.value = source?.food?.verb === "喝" ? "喝" : source?.food?.verb === "吃" ? "吃" : "none";
|
|
8144
|
+
const foodItems = node2("textarea", { rows: 2, placeholder: "品类名,一行一样;别写味道" }, lines(source?.food?.items));
|
|
8145
|
+
const style = node2("textarea", { rows: 2 }, source?.style || "");
|
|
8146
|
+
const validation = /* @__PURE__ */ new Map();
|
|
8147
|
+
const countedField = (label2, control, key, hint) => {
|
|
8148
|
+
const counter = node2("span", { class: "fpl-counter", id: `fpl-${key}-count` });
|
|
8149
|
+
const message = node2("span", { class: "fpl-error", id: `fpl-${key}-issues`, "aria-live": "polite" });
|
|
8150
|
+
control.setAttribute("aria-describedby", `fpl-${key}-count fpl-${key}-issues`);
|
|
8151
|
+
validation.set(key, { control, counter, message });
|
|
8152
|
+
return field(label2, [control, counter, message], hint);
|
|
8153
|
+
};
|
|
7910
8154
|
const relations = node2("div", { class: "fpl-stack" });
|
|
7911
8155
|
const relationRows = [];
|
|
7912
8156
|
const addRelation = (existing) => {
|
|
@@ -7929,7 +8173,7 @@ function mountPlaces(ctx) {
|
|
|
7929
8173
|
return target;
|
|
7930
8174
|
};
|
|
7931
8175
|
const addButton = button2("添加地点关联", () => addRelation()?.focus(), { disabled: !places().some((item) => item.id !== place?.id) });
|
|
7932
|
-
for (const existing of list2(
|
|
8176
|
+
for (const existing of list2(source?.relations)) addRelation(existing);
|
|
7933
8177
|
let group = 0;
|
|
7934
8178
|
const panels = [];
|
|
7935
8179
|
const statusText = node2("span", {});
|
|
@@ -7965,14 +8209,20 @@ function mountPlaces(ctx) {
|
|
|
7965
8209
|
style,
|
|
7966
8210
|
relationRows
|
|
7967
8211
|
});
|
|
7968
|
-
const initial = JSON.stringify(editorValues(place));
|
|
7969
|
-
const dirty = () => JSON.stringify(editorValues(place, controls())) !== initial;
|
|
8212
|
+
const initial = JSON.stringify(editorValues(place, controls()));
|
|
8213
|
+
const dirty = () => setHome.checked || JSON.stringify(editorValues(place, controls())) !== initial;
|
|
7970
8214
|
function paint() {
|
|
7971
8215
|
for (const [index, panel] of panels.entries()) panel.hidden = Boolean(place) && index !== group;
|
|
7972
8216
|
headTitle.textContent = GROUPS[group][0];
|
|
7973
8217
|
headNote.textContent = GROUPS[group][1];
|
|
7974
8218
|
statusText.textContent = dirty() ? "有未保存的修改" : "还没有改动";
|
|
7975
8219
|
statusLine.setAttribute("data-dirty", String(dirty()));
|
|
8220
|
+
for (const [key, { control, counter, message }] of validation) {
|
|
8221
|
+
counter.textContent = `${Array.from(control.value).length} / ${PLACE_LIMITS[key]}`;
|
|
8222
|
+
const issues = placeTextIssues(control.value, key);
|
|
8223
|
+
message.textContent = issues.join(";");
|
|
8224
|
+
control.setAttribute("aria-invalid", String(issues.length > 0));
|
|
8225
|
+
}
|
|
7976
8226
|
}
|
|
7977
8227
|
nav.append(...GROUPS.map(([label2], index) => button2(`${index + 1}. ${label2}`, () => {
|
|
7978
8228
|
group = index;
|
|
@@ -8012,29 +8262,39 @@ function mountPlaces(ctx) {
|
|
|
8012
8262
|
};
|
|
8013
8263
|
if (!locked) venue.kind = kind.value.trim();
|
|
8014
8264
|
const values = { venue, style: style.value.trim(), relations: relationValues };
|
|
8265
|
+
const makeHome = !place && setHome.checked;
|
|
8015
8266
|
void submit(
|
|
8016
8267
|
place ? "update" : "create",
|
|
8017
8268
|
place ? { id: place.id, patch: values } : { input: { ...venue, style: values.style, relations: values.relations } },
|
|
8018
|
-
place ? "已保存地点。" : "已添加地点。",
|
|
8269
|
+
place ? "已保存地点。" : makeHome ? "已添加地点并设为住所。" : "已添加地点。",
|
|
8019
8270
|
async (result) => {
|
|
8020
8271
|
const id = place?.id ?? result.place?.id ?? result.id;
|
|
8021
8272
|
if (!id) {
|
|
8022
8273
|
go("browse");
|
|
8023
8274
|
return;
|
|
8024
8275
|
}
|
|
8276
|
+
let homeError;
|
|
8277
|
+
if (makeHome) {
|
|
8278
|
+
try {
|
|
8279
|
+
accept(await call("setHome", { id, revision: snapshot?.revision }));
|
|
8280
|
+
} catch (error) {
|
|
8281
|
+
homeError = new Error(`地点已添加,但设为住所失败:${error?.message || "请稍后在详情页重试。"}`);
|
|
8282
|
+
}
|
|
8283
|
+
}
|
|
8025
8284
|
await readDetail(id);
|
|
8026
8285
|
if (live()) {
|
|
8027
8286
|
detailId = id;
|
|
8028
8287
|
go("detail");
|
|
8029
8288
|
}
|
|
8289
|
+
if (homeError) throw homeError;
|
|
8030
8290
|
}
|
|
8031
8291
|
);
|
|
8032
8292
|
} });
|
|
8033
8293
|
body.append(
|
|
8034
8294
|
groupPanel(
|
|
8035
8295
|
0,
|
|
8036
|
-
node2("div", { class: "fpl-grid" }, place ?
|
|
8037
|
-
place ?
|
|
8296
|
+
node2("div", { class: "fpl-grid" }, place ? countedField("名字", name, "name") : null, field("别名", aliases, "用顿号或逗号分隔。"), field("分类", kind, locked ? "预设分类由内置定义决定。" : null), field("标签", tags, "用顿号或逗号分隔。")),
|
|
8297
|
+
place ? countedField("描写", desc, "desc", "只写空间与陈设,别写她在干什么。") : null,
|
|
8038
8298
|
field("场景名(可选)", scene, locked ? "预设的场景名由内置素材决定。" : "素材库里的正名;不知道就留空。"),
|
|
8039
8299
|
locked ? note2("这是预设地点:改名、描写、时间、能逛的、纪念品这些会存成覆盖层,预设本身不动;分类和场景名由内置定义决定。") : null
|
|
8040
8300
|
),
|
|
@@ -8048,7 +8308,7 @@ function mountPlaces(ctx) {
|
|
|
8048
8308
|
),
|
|
8049
8309
|
groupPanel(
|
|
8050
8310
|
2,
|
|
8051
|
-
|
|
8311
|
+
countedField("地点画风", style, "style", "留空时使用全局默认画风。画风更新后,封面仍使用已保存的图片。"),
|
|
8052
8312
|
note2("封面在浏览列表里打开一处地点后点「编辑封面」上传;这里只改画风。")
|
|
8053
8313
|
),
|
|
8054
8314
|
groupPanel(
|
|
@@ -8066,19 +8326,20 @@ function mountPlaces(ctx) {
|
|
|
8066
8326
|
body.replaceChildren(node2(
|
|
8067
8327
|
"section",
|
|
8068
8328
|
{ class: "fpl-formgroup fpl-stack" },
|
|
8069
|
-
|
|
8070
|
-
|
|
8329
|
+
countedField("地点名称(必填)", name, "name"),
|
|
8330
|
+
countedField("一句话介绍(必填)", desc, "desc", "写写这里的空间与陈设。")
|
|
8071
8331
|
), more);
|
|
8072
8332
|
form.addEventListener("invalid", () => {
|
|
8073
8333
|
more.open = true;
|
|
8074
8334
|
}, true);
|
|
8075
8335
|
}
|
|
8076
|
-
for (const control of [name, aliases, tags, desc, scene, kind, open2, close, crowd, outfit, areas, souvenirs, photoSpots, randomEvents, foodVerb, foodItems, style]) {
|
|
8336
|
+
for (const control of [name, aliases, tags, desc, scene, kind, open2, close, crowd, outfit, areas, souvenirs, photoSpots, randomEvents, foodVerb, foodItems, style, setHome]) {
|
|
8077
8337
|
control.addEventListener?.("input", paint);
|
|
8078
8338
|
control.addEventListener?.("change", paint);
|
|
8079
8339
|
}
|
|
8080
8340
|
savebar.append(
|
|
8081
8341
|
statusLine,
|
|
8342
|
+
!place ? node2("label", { class: "fpl-check fpl-home-check" }, setHome, "顺便设为住所") : null,
|
|
8082
8343
|
row(
|
|
8083
8344
|
node2("button", { type: "submit", class: "fpl-primary" }, place ? "保存地点" : "添加地点"),
|
|
8084
8345
|
place?.preset && place.overridden ? button2("恢复预设", () => confirm("恢复预设", `把「${place.name}」恢复成预设?你改过的字段会丢掉。`, () => submit("reset", { id: place.id }, "已恢复预设。", async () => {
|
|
@@ -8093,6 +8354,54 @@ function mountPlaces(ctx) {
|
|
|
8093
8354
|
button2("取消编辑", () => go(place ? "detail" : "browse"))
|
|
8094
8355
|
)
|
|
8095
8356
|
);
|
|
8357
|
+
if (!place) {
|
|
8358
|
+
const templateConfirm = node2("div", { class: "fpl-notice fpl-stack", role: "status" });
|
|
8359
|
+
templateConfirm.hidden = true;
|
|
8360
|
+
const applyTemplate = (draft2) => {
|
|
8361
|
+
for (const [key, control] of Object.entries({ name, aliases, tags, desc, scene, kind, crowd, areas, souvenirs, photoSpots, randomEvents, style })) {
|
|
8362
|
+
const value = draft2[key] ?? (key === "crowd" ? "normal" : "");
|
|
8363
|
+
control.value = Array.isArray(value) ? value.join("\n") : value;
|
|
8364
|
+
}
|
|
8365
|
+
open2.value = "09:00";
|
|
8366
|
+
close.value = "21:00";
|
|
8367
|
+
outfit.value = "";
|
|
8368
|
+
foodVerb.value = draft2.food?.verb ?? "none";
|
|
8369
|
+
foodItems.value = lines(draft2.food?.items);
|
|
8370
|
+
relationRows.splice(0);
|
|
8371
|
+
relations.replaceChildren();
|
|
8372
|
+
setHome.checked = false;
|
|
8373
|
+
templateConfirm.hidden = true;
|
|
8374
|
+
paint();
|
|
8375
|
+
name.focus();
|
|
8376
|
+
};
|
|
8377
|
+
const templates = node2(
|
|
8378
|
+
"section",
|
|
8379
|
+
{ class: "fpl-card fpl-stack", "aria-label": "地点模板" },
|
|
8380
|
+
node2("h4", {}, "地点模板"),
|
|
8381
|
+
note2("填入可修改的骨架,检查后再保存。"),
|
|
8382
|
+
row(PLACE_TEMPLATES.map(([label2, draft2]) => {
|
|
8383
|
+
const pick = button2(label2, () => {
|
|
8384
|
+
if (!dirty()) {
|
|
8385
|
+
applyTemplate(draft2);
|
|
8386
|
+
return;
|
|
8387
|
+
}
|
|
8388
|
+
templateConfirm.hidden = false;
|
|
8389
|
+
const apply = button2("确认使用模板", () => applyTemplate(draft2), { class: "fpl-primary" });
|
|
8390
|
+
templateConfirm.replaceChildren(
|
|
8391
|
+
node2("p", {}, `当前表单有未保存的修改。使用「${label2}」将替换表单内容。`),
|
|
8392
|
+
row(apply, button2("保留当前内容", () => {
|
|
8393
|
+
templateConfirm.hidden = true;
|
|
8394
|
+
pick.focus();
|
|
8395
|
+
}))
|
|
8396
|
+
);
|
|
8397
|
+
apply.focus();
|
|
8398
|
+
});
|
|
8399
|
+
return pick;
|
|
8400
|
+
})),
|
|
8401
|
+
templateConfirm
|
|
8402
|
+
);
|
|
8403
|
+
form.append(templates);
|
|
8404
|
+
}
|
|
8096
8405
|
form.append(body, savebar);
|
|
8097
8406
|
const wrapper = node2(
|
|
8098
8407
|
"div",
|
|
@@ -8249,8 +8558,6 @@ function mountPlaces(ctx) {
|
|
|
8249
8558
|
() => {
|
|
8250
8559
|
tell();
|
|
8251
8560
|
browseFilter.quick = key;
|
|
8252
|
-
browseFilter.text = "";
|
|
8253
|
-
browseFilter.kind = "";
|
|
8254
8561
|
go("browse");
|
|
8255
8562
|
}
|
|
8256
8563
|
)));
|
|
@@ -8276,7 +8583,7 @@ function mountPlaces(ctx) {
|
|
|
8276
8583
|
else if (view === "settings") contents = settings();
|
|
8277
8584
|
else if (view === "artwork") contents = artworkView();
|
|
8278
8585
|
else if (view === "migration") contents = migration.render();
|
|
8279
|
-
else if (view === "create") contents = editor();
|
|
8586
|
+
else if (view === "create") contents = editor(void 0, createDraft);
|
|
8280
8587
|
else if (view === "edit" && detail) contents = editor(detail);
|
|
8281
8588
|
else if (view === "cover" && detail) contents = coverEditor(detail);
|
|
8282
8589
|
else if (view === "detail" && detail) contents = describePlace(detail);
|