shortik-creator-mcp 0.4.1 → 0.5.0
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 +15 -0
- package/bundled/MANIFEST.json +1 -1
- package/bundled/bridge/hwik-bridge.js +264 -3
- package/bundled/templates/animal-ears/index.html +576 -9
- package/bundled/templates/balance-game/index.html +576 -9
- package/bundled/templates/birthday-candles/index.html +576 -9
- package/bundled/templates/blink-jump/index.html +576 -9
- package/bundled/templates/brain-numbers/index.html +576 -9
- package/bundled/templates/breathe/index.html +576 -9
- package/bundled/templates/brow-lift/index.html +576 -9
- package/bundled/templates/brush-stroke/index.html +576 -9
- package/bundled/templates/calorie-battle/index.html +576 -9
- package/bundled/templates/campfire/index.html +576 -9
- package/bundled/templates/checkout-rush/index.html +576 -9
- package/bundled/templates/cheer-shout/index.html +576 -9
- package/bundled/templates/cheer-sign/index.html +576 -9
- package/bundled/templates/chosung-quiz/index.html +576 -9
- package/bundled/templates/clap-rhythm/index.html +576 -9
- package/bundled/templates/cola-shake/index.html +576 -9
- package/bundled/templates/color-diff/index.html +576 -9
- package/bundled/templates/color-sort/index.html +576 -9
- package/bundled/templates/compass-hunt/index.html +576 -9
- package/bundled/templates/conductor/index.html +576 -9
- package/bundled/templates/cover-maker/index.html +576 -9
- package/bundled/templates/daily-ox/index.html +576 -9
- package/bundled/templates/dawn-birds/index.html +576 -9
- package/bundled/templates/day-receipt/index.html +576 -9
- package/bundled/templates/desktop-tidy/index.html +576 -9
- package/bundled/templates/dice-board/index.html +576 -9
- package/bundled/templates/doodle-pad/index.html +576 -9
- package/bundled/templates/draft-hunt/index.html +576 -9
- package/bundled/templates/english-words/index.html +576 -9
- package/bundled/templates/f1-reaction/index.html +576 -9
- package/bundled/templates/face-copy/index.html +576 -9
- package/bundled/templates/face-filter/index.html +576 -9
- package/bundled/templates/face-shape/index.html +576 -9
- package/bundled/templates/face-yoga/index.html +576 -9
- package/bundled/templates/flag-quiz/index.html +576 -9
- package/bundled/templates/fruit-merge/index.html +576 -9
- package/bundled/templates/glasses-fit/index.html +576 -9
- package/bundled/templates/hat-tryon/index.html +576 -9
- package/bundled/templates/head-dodge/index.html +576 -9
- package/bundled/templates/hidden-objects/index.html +576 -9
- package/bundled/templates/hole-wall/index.html +576 -9
- package/bundled/templates/hop-hop/index.html +576 -9
- package/bundled/templates/hurray-pose/index.html +576 -9
- package/bundled/templates/id-photo/index.html +576 -9
- package/bundled/templates/ink-bloom/index.html +576 -9
- package/bundled/templates/jumping-jacks/index.html +576 -9
- package/bundled/templates/latte-art/index.html +576 -9
- package/bundled/templates/level-tool/index.html +576 -9
- package/bundled/templates/library-quiet/index.html +576 -9
- package/bundled/templates/line-draw/index.html +576 -9
- package/bundled/templates/lip-color/index.html +576 -9
- package/bundled/templates/live-ox-quiz/index.html +265 -4
- package/bundled/templates/live-penguin-run/index.html +265 -4
- package/bundled/templates/live-snowman/index.html +265 -4
- package/bundled/templates/live-stairs-race/index.html +265 -4
- package/bundled/templates/lofi-maker/index.html +576 -9
- package/bundled/templates/lucky-direction/index.html +576 -9
- package/bundled/templates/market-memory/index.html +576 -9
- package/bundled/templates/match3-mini/index.html +576 -9
- package/bundled/templates/maze-roll/index.html +576 -9
- package/bundled/templates/memory-match/index.html +576 -9
- package/bundled/templates/menu-cards/index.html +576 -9
- package/bundled/templates/merge-numbers/index.html +576 -9
- package/bundled/templates/mine-sweep/index.html +576 -9
- package/bundled/templates/mini-golf/index.html +576 -9
- package/bundled/templates/mocktail-bar/index.html +576 -9
- package/bundled/templates/mole-tap/index.html +576 -9
- package/bundled/templates/mouth-munch/index.html +576 -9
- package/bundled/templates/mukbang-course/index.html +576 -9
- package/bundled/templates/music-box/index.html +576 -9
- package/bundled/templates/my-constellation/index.html +576 -9
- package/bundled/templates/neck-shoulder-stretch/index.html +576 -9
- package/bundled/templates/next-panel/index.html +576 -9
- package/bundled/templates/nod-quiz/index.html +576 -9
- package/bundled/templates/office-stretch/index.html +576 -9
- package/bundled/templates/omok/index.html +576 -9
- package/bundled/templates/one-leg/index.html +576 -9
- package/bundled/templates/one-minute-plant/index.html +576 -9
- package/bundled/templates/paper-crane/index.html +576 -9
- package/bundled/templates/pet-sticker/index.html +576 -9
- package/bundled/templates/photo-palette/index.html +576 -9
- package/bundled/templates/photo-puzzle/index.html +576 -9
- package/bundled/templates/photo-spot-diff/index.html +576 -9
- package/bundled/templates/pixel-snake/index.html +576 -9
- package/bundled/templates/plank-timer/index.html +576 -9
- package/bundled/templates/polaroid-shake/index.html +576 -9
- package/bundled/templates/pose-mirror/index.html +576 -9
- package/bundled/templates/posture-check/index.html +576 -9
- package/bundled/templates/quiz-flash/index.html +574 -7
- package/bundled/templates/rain-window/index.html +576 -9
- package/bundled/templates/reaction-test/index.html +576 -9
- package/bundled/templates/recycle-sort/index.html +576 -9
- package/bundled/templates/riso-maker/index.html +576 -9
- package/bundled/templates/say-it/index.html +576 -9
- package/bundled/templates/scratch-card/index.html +574 -7
- package/bundled/templates/scratch-deck/index.html +576 -9
- package/bundled/templates/screw-sort/index.html +576 -9
- package/bundled/templates/season-food/index.html +576 -9
- package/bundled/templates/sfx-maker/index.html +576 -9
- package/bundled/templates/shake-shake/index.html +576 -9
- package/bundled/templates/simon-memory/index.html +576 -9
- package/bundled/templates/slide-puzzle/index.html +576 -9
- package/bundled/templates/smile-charge/index.html +576 -9
- package/bundled/templates/smile-hold/index.html +576 -9
- package/bundled/templates/spelling-quiz/index.html +576 -9
- package/bundled/templates/spot-diff/index.html +576 -9
- package/bundled/templates/squat-counter/index.html +576 -9
- package/bundled/templates/stack-tower/index.html +576 -9
- package/bundled/templates/star-finder/index.html +576 -9
- package/bundled/templates/stare-contest/index.html +576 -9
- package/bundled/templates/syllable-typing/index.html +576 -9
- package/bundled/templates/tap-rush/index.html +574 -7
- package/bundled/templates/tilt-bowling/index.html +576 -9
- package/bundled/templates/tips-cards/index.html +576 -9
- package/bundled/templates/today-card/index.html +576 -9
- package/bundled/templates/today-dots/index.html +576 -9
- package/bundled/templates/today-fate/index.html +576 -9
- package/bundled/templates/tongue-twister/index.html +576 -9
- package/bundled/templates/transfer-puzzle/index.html +576 -9
- package/bundled/templates/travel-type/index.html +576 -9
- package/bundled/templates/trivia-banana/index.html +576 -9
- package/bundled/templates/trivia-giraffe/index.html +576 -9
- package/bundled/templates/trivia-hangul/index.html +576 -9
- package/bundled/templates/trivia-jupiter/index.html +576 -9
- package/bundled/templates/trivia-octopus/index.html +576 -9
- package/bundled/templates/trivia-thunder/index.html +576 -9
- package/bundled/templates/voice-balloon/index.html +576 -9
- package/bundled/templates/walk-math/index.html +576 -9
- package/bundled/templates/water-glass/index.html +576 -9
- package/bundled/templates/wave-breath/index.html +576 -9
- package/bundled/templates/wink-shoot/index.html +576 -9
- package/bundled/templates/word-chain/index.html +576 -9
- package/bundled/templates/word-recall/index.html +576 -9
- package/bundled/templates/wrist-eye-break/index.html +576 -9
- package/dist/index.js +4561 -367
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# 변경 기록 — `shortik-creator-mcp` (옛 이름 `hwik-creator-mcp`)
|
|
2
2
|
|
|
3
|
+
## 0.5.0 (2026-11-24, 제작자 MCP 고도화 — docs/research/mcp-advancement/)
|
|
4
|
+
- **브리지 1.11**(ADR-0035): 동봉 브리지가 1.11.0 — `SHORTIK.save`/`load`(진행 저장), `vote`/`poll`(투표 집계), `locale`/`t()`(언어), `ghost`, 시리즈. 시작 틀 `poll`·`series-episode`.
|
|
5
|
+
- **공용 에셋**(ADR-0034): play-cdn `/assets/`(Kenney CC0 그림·효과음)·`/lib/matter@0.20.0.js`를 카탈로그로 안내하고, 없는 경로는 `ASSET_NOT_FOUND`로 잡습니다.
|
|
6
|
+
- **검사·가이드**: `WASM_NOT_ALLOWED`, 영어 보상·사행성 문구 검사, 고치는 법(`fixes`)·`lang` 지원, 「글 없는 UX 우선」 가이드, 도구 설명 앞 영어 한 줄.
|
|
7
|
+
- **실행 검사**: `hwik_check_draft`가 서버 실행 결과 스크린샷을 이미지로 돌려줍니다(원격 MCP).
|
|
8
|
+
|
|
9
|
+
### 장르 넓히기 (M2·M5·M8·M9·M12·M17)
|
|
10
|
+
- **시작 틀**: `hwik_new_playable { kind }`에 `story`(선택지 이야기·`hwik-strings`)·`cards`(카드 짝 맞추기)·`live-coop`(다 함께 채우기, 혼자 대체)·`tutorial-free`(글 없는 첫 화면) 추가. 장르 요령은 리소스 `hwik://recipes/{genre}`.
|
|
11
|
+
- **키트**: `hwik_new_playable { kits: ['shell', 'art/food'] }` — 오리지널 공용 셸과 그림·소리 키트를 `kits/`에 넣어 바이너리 없이 그림·효과음. 목록은 리소스 `hwik://kits`. 셸은 `HwikShell.run({ ready, complete })` 훅으로 페이지가 브리지 호출을 직접 합니다.
|
|
12
|
+
- **데이터 팩**: `hwik_list_datasets`·`hwik_get_dataset { dir, name }`(원격과 같은 `data/<name>.js`).
|
|
13
|
+
- **리믹스**: `hwik_find_remixable`, `hwik_fork_content { content_id, title, out_dir }`(원작 코드를 새 폴더로 복사, 게시하면 원작 표시).
|
|
14
|
+
- **캠페인 대조**: `hwik_check_campaign { dir, campaign_id }`. `hwik_publish_playable`에 `campaign_id`를 주면 먼저 대조하고 실패하면 올리지 않습니다(점수·순위별 혜택 표현, iOS 「설치」 문구, 직접 링크, 브리프 금지 표현, 브랜드명).
|
|
15
|
+
- **성과**: `hwik_content_insights { content_id }` — 완주율·단계별 도달·평균 플레이 시간·리믹스 수(집계만).
|
|
16
|
+
- 데이터 팩·포크·성과·캠페인 대조는 숏틱 API가 새 경로를 배포한 뒤에 동작합니다.
|
|
17
|
+
|
|
3
18
|
## 0.4.1 (2026-11-19)
|
|
4
19
|
- **심사 정보 필수(ADR-0030)**: `hwik_publish_playable`·`hwik_upload_video`에 `description`(한 줄 소개 10자+)·`purpose`(기획 의도 20자+)·`sources`(소재·출처 5자+)·`how_to_play`(플레이 방법 10자+, 플레이어블)·`creator_confirmed`(제작자가 요약을 보고 확인)가 필요합니다. 빠지면 업로드 전에 무엇이 모자란지 알려 줍니다(서버도 같은 기준으로 거절).
|
|
5
20
|
- 프롬프트·가이드라인 7-1절: 로컬 미리보기로 결과를 보여 주고 → 심사 정보를 함께 정하고 → 요약을 보여 「이대로 심사 넣을까요?」를 확인받은 뒤 올리는 순서.
|
package/bundled/MANIFEST.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* HWIK Playable Bridge SDK v1.
|
|
2
|
+
* HWIK Playable Bridge SDK v1.11.0 (SHORTIK)
|
|
3
3
|
* ---------------------------------------------------------------
|
|
4
4
|
* Tiny, dependency-free bridge between a playable (HTML5 mini-game /
|
|
5
5
|
* interactive card) and the SHORTIK host (Flutter WebView or web iframe).
|
|
@@ -83,6 +83,30 @@
|
|
|
83
83
|
* frames carry `solo: true`; host frames that show up during a solo round are ignored for that round. So a live page
|
|
84
84
|
* always plays to the end alone. Nothing about a room (order, place, counters) is ever a reward input (rule 4).
|
|
85
85
|
*
|
|
86
|
+
* Bridge 1.11 (ADR-0035, ADR-0033 §2-5, ADR-0029 §2-2) — content APIs. Every one of them works alone on an old host:
|
|
87
|
+
* Start values: the host appends the key "hwik" to the page URL fragment (last key, after any other key=value pairs,
|
|
88
|
+
* joined with &): hwik=<base64url of JSON {v:1, locale, save}>. The SDK reads it synchronously when it loads; a host
|
|
89
|
+
* that cannot change the URL may send HWIK._dispatch('init', {locale, save}) instead (save only until load() ran).
|
|
90
|
+
* SHORTIK.locale the app language ('ko', 'en', 'ja', …): host value → navigator.language → 'ko'. No country.
|
|
91
|
+
* SHORTIK.t(key, fallback) text from the JSON script element with id "hwik-strings" ({"v":1,"default":"ko","strings":
|
|
92
|
+
* {"hint":{"ko":"…","en":"…"}}}), then the built-in common phrases ('common.start',
|
|
93
|
+
* 'common.retry', 'common.score', 'common.best', 'common.time_left', 'common.level', 'common.success',
|
|
94
|
+
* 'common.fail', 'common.next', 'common.tap_to_start', 'common.you', 'common.ghost', 'common.votes',
|
|
95
|
+
* 'common.few_votes', 'common.saved' in ko / en / ja), then fallback, then the key itself.
|
|
96
|
+
* SHORTIK.save(obj) / SHORTIK.load() progress kept ON THE DEVICE by the host (never sent to a server, so it can never
|
|
97
|
+
* be a reward input — rule 4). JSON of numbers / strings / booleans / null / arrays / objects,
|
|
98
|
+
* ≤ 4,096 bytes serialized; save(null) clears. Scope from the meta named "hwik-save" (content
|
|
99
|
+
* "content" = this content, "series" = shared by the episodes of its series). load() returns the
|
|
100
|
+
* latest save, else the host's start value, else null — synchronously. Old hosts: memory only.
|
|
101
|
+
* SHORTIK.vote(q, i) vote option i (0-based) of question q (0-based; vote(i) = question 0) on a page that declares
|
|
102
|
+
* the meta named "hwik-poll" (options per question, 2–6 each, up to 10, e.g. content "3,2").
|
|
103
|
+
* The host answers SHORTIK.on('poll', {q, total, counts:[…], mine}) or {q, total, few:true, mine}
|
|
104
|
+
* (under 30 votes). No answer within 1.5 s (old host, web, preview) → {q, available:false, mine:i}.
|
|
105
|
+
* SHORTIK.ghost.trace(samples) this round's [[second, score], …] (≤ 120 integer pairs, ≤ 2 KB) right before complete() on
|
|
106
|
+
* a page with the meta named "hwik-together" (content "ghost"); the host sends it with the
|
|
107
|
+
* record. SHORTIK.on('ghost', {name, samples}) delivers another player's run (pseudonym) at the
|
|
108
|
+
* start, or nothing. Votes, saves and ghosts are display only — never rewards.
|
|
109
|
+
*
|
|
86
110
|
* Host → playable: call HWIK._dispatch('pause'|'resume'|'mute'|'capabilities'|'capability'|'clip_start'|'clip_stop'|'live'|<stream>, data)
|
|
87
111
|
* (Flutter: controller.runJavaScript("HWIK._dispatch('pause')");
|
|
88
112
|
* iframe: iframe.contentWindow.postMessage({source:"hwik-host",event:"pause"}, origin))
|
|
@@ -95,7 +119,7 @@
|
|
|
95
119
|
// Idempotent, and self-upgrading: a page loads the CDN copy first and then its own inline copy. A stale CDN copy
|
|
96
120
|
// (cached, or deployed late) must not win over a newer inline one — v1.1 silently dropped request options.
|
|
97
121
|
// Both run before any game script, so nothing has subscribed to the old object yet.
|
|
98
|
-
var SDK_VERSION = '1.
|
|
122
|
+
var SDK_VERSION = '1.11.0';
|
|
99
123
|
function olderThanThis(v) {
|
|
100
124
|
var a = String(v || '1.0.0').split('.'), b = SDK_VERSION.split('.');
|
|
101
125
|
for (var i = 0; i < 3; i++) { var x = +a[i] || 0, y = +b[i] || 0; if (x !== y) return x < y; }
|
|
@@ -117,7 +141,8 @@
|
|
|
117
141
|
// v1.6 (ADR-0012): 'snapshot' {state: 'saved'|'shared'|'closed'|'unavailable', reason?} after HWIK.snapshot().
|
|
118
142
|
// v1.9 (ADR-0022): 'clip_start' {max_sec, watermark:{lines}} and 'clip_stop' — handled by the SDK itself (pages may listen).
|
|
119
143
|
// v1.10 (ADR-0029 §11): 'live' — live room frames relayed by the host (or simulated by the solo fallback).
|
|
120
|
-
|
|
144
|
+
// v1.11 (ADR-0035): 'init' {locale, save} (handled by the SDK, pages may listen), 'poll' vote tallies, 'ghost' a ghost run.
|
|
145
|
+
var EVENTS = ['pause', 'resume', 'mute', 'capabilities', 'capability', 'motion', 'face', 'blink', 'pose', 'camera', 'sound', 'clap', 'speech', 'mic', 'shake', 'compass', 'photo', 'snapshot', 'result', 'clip_start', 'clip_stop', 'live', 'init', 'poll', 'ghost'];
|
|
121
146
|
var listeners = {};
|
|
122
147
|
for (var ei = 0; ei < EVENTS.length; ei++) listeners[EVENTS[ei]] = [];
|
|
123
148
|
var readySent = false;
|
|
@@ -744,6 +769,185 @@
|
|
|
744
769
|
}
|
|
745
770
|
};
|
|
746
771
|
|
|
772
|
+
// ---- bridge 1.11 content APIs (ADR-0035, ADR-0033 §2-5, ADR-0029 §2-2) ------------------------------------------
|
|
773
|
+
var SAVE_MAX_BYTES = 4096;
|
|
774
|
+
var GHOST_MAX_SAMPLES = 120;
|
|
775
|
+
var GHOST_MAX_BYTES = 2048;
|
|
776
|
+
var POLL_FALLBACK_MS = 1500;
|
|
777
|
+
var LOCALE_RE = /^[a-z]{2,3}$/;
|
|
778
|
+
|
|
779
|
+
function metaContent(name) {
|
|
780
|
+
var doc = global.document;
|
|
781
|
+
if (!doc || typeof doc.querySelector !== 'function') return null;
|
|
782
|
+
try {
|
|
783
|
+
var m = doc.querySelector('meta[name="' + name + '"]');
|
|
784
|
+
return m ? String(m.getAttribute('content') || '').trim() : null;
|
|
785
|
+
} catch (e) { return null; }
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
function normLocale(v) {
|
|
789
|
+
if (typeof v !== 'string') return null;
|
|
790
|
+
var p = v.trim().toLowerCase().split(/[-_]/)[0];
|
|
791
|
+
return LOCALE_RE.test(p) ? p : null;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/** base64url → UTF-8 string, without TextDecoder (old WebViews). */
|
|
795
|
+
function b64urlDecode(s) {
|
|
796
|
+
var b64 = String(s).replace(/-/g, '+').replace(/_/g, '/');
|
|
797
|
+
while (b64.length % 4) b64 += '=';
|
|
798
|
+
var bin = typeof global.atob === 'function' ? global.atob(b64) : (typeof Buffer !== 'undefined' ? Buffer.from(b64, 'base64').toString('binary') : '');
|
|
799
|
+
var pct = '';
|
|
800
|
+
for (var i = 0; i < bin.length; i++) pct += '%' + ('0' + bin.charCodeAt(i).toString(16)).slice(-2);
|
|
801
|
+
return decodeURIComponent(pct);
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/** The host's start values from the URL fragment key "hwik" (any position, normally last), or {}. */
|
|
805
|
+
function readStart() {
|
|
806
|
+
try {
|
|
807
|
+
var h = global.location && typeof global.location.hash === 'string' ? global.location.hash.replace(/^#/, '') : '';
|
|
808
|
+
if (!h) return {};
|
|
809
|
+
var parts = h.split('&');
|
|
810
|
+
for (var i = parts.length - 1; i >= 0; i--) {
|
|
811
|
+
if (parts[i].indexOf('hwik=') !== 0) continue;
|
|
812
|
+
var json = JSON.parse(b64urlDecode(parts[i].slice(5)));
|
|
813
|
+
return json && typeof json === 'object' && !Array.isArray(json) ? json : {};
|
|
814
|
+
}
|
|
815
|
+
} catch (e) { /* a broken fragment is ignored */ }
|
|
816
|
+
return {};
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/** A JSON-safe copy of a plain data value, or undefined when it holds anything else (functions, NaN, cycles, …). */
|
|
820
|
+
function plainCopy(v, depth) {
|
|
821
|
+
if (depth > 20) return undefined;
|
|
822
|
+
if (v === null || typeof v === 'string' || typeof v === 'boolean') return v;
|
|
823
|
+
if (typeof v === 'number') return isFinite(v) ? v : undefined;
|
|
824
|
+
if (Array.isArray(v)) {
|
|
825
|
+
var a = [];
|
|
826
|
+
for (var i = 0; i < v.length; i++) { var x = plainCopy(v[i], depth + 1); if (x === undefined) return undefined; a.push(x); }
|
|
827
|
+
return a;
|
|
828
|
+
}
|
|
829
|
+
if (typeof v === 'object' && Object.prototype.toString.call(v) === '[object Object]') {
|
|
830
|
+
var o = {};
|
|
831
|
+
for (var k in v) {
|
|
832
|
+
if (!Object.prototype.hasOwnProperty.call(v, k)) continue;
|
|
833
|
+
var y = plainCopy(v[k], depth + 1);
|
|
834
|
+
if (y === undefined) return undefined;
|
|
835
|
+
o[k] = y;
|
|
836
|
+
}
|
|
837
|
+
return o;
|
|
838
|
+
}
|
|
839
|
+
return undefined;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
function saveScope() {
|
|
843
|
+
return metaContent('hwik-save') === 'series' ? 'series' : 'content';
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
function pollSpec() {
|
|
847
|
+
var raw = metaContent('hwik-poll');
|
|
848
|
+
if (!raw) return null;
|
|
849
|
+
var parts = raw.split(','), out = [];
|
|
850
|
+
if (parts.length < 1 || parts.length > 10) return null;
|
|
851
|
+
for (var i = 0; i < parts.length; i++) {
|
|
852
|
+
var p = parts[i].trim();
|
|
853
|
+
if (!/^\d{1,2}$/.test(p)) return null;
|
|
854
|
+
var n = +p;
|
|
855
|
+
if (n < 2 || n > 6) return null;
|
|
856
|
+
out.push(n);
|
|
857
|
+
}
|
|
858
|
+
return out;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
var start = readStart();
|
|
862
|
+
var content = {
|
|
863
|
+
locale: normLocale(start.locale) || normLocale(global.navigator && global.navigator.language) || 'ko',
|
|
864
|
+
// undefined = nothing saved in this page yet (load() falls back to the start value); null = cleared.
|
|
865
|
+
saved: undefined,
|
|
866
|
+
startSave: start.save === undefined ? null : plainCopy(start.save, 0),
|
|
867
|
+
loaded: false,
|
|
868
|
+
pollTimers: {}
|
|
869
|
+
};
|
|
870
|
+
if (content.startSave === undefined) content.startSave = null;
|
|
871
|
+
|
|
872
|
+
var COMMON = {
|
|
873
|
+
ko: { start: '시작', retry: '다시 하기', score: '점수', best: '최고 기록', time_left: '남은 시간', level: '레벨', success: '성공', fail: '실패', next: '다음', tap_to_start: '탭해서 시작', you: '나', ghost: '유령', votes: '표', few_votes: '아직 표가 적어요', saved: '저장했어요' },
|
|
874
|
+
en: { start: 'Start', retry: 'Retry', score: 'Score', best: 'Best', time_left: 'Time left', level: 'Level', success: 'Success', fail: 'Fail', next: 'Next', tap_to_start: 'Tap to start', you: 'You', ghost: 'Ghost', votes: 'votes', few_votes: 'Not enough votes yet', saved: 'Saved' },
|
|
875
|
+
ja: { start: 'スタート', retry: 'もう一度', score: 'スコア', best: 'ベスト', time_left: '残り時間', level: 'レベル', success: '成功', fail: '失敗', next: '次へ', tap_to_start: 'タップでスタート', you: 'あなた', ghost: 'ゴースト', votes: '票', few_votes: 'まだ票が少ないです', saved: '保存しました' }
|
|
876
|
+
};
|
|
877
|
+
|
|
878
|
+
function pageStrings() {
|
|
879
|
+
var doc = global.document;
|
|
880
|
+
if (!doc || typeof doc.getElementById !== 'function') return null;
|
|
881
|
+
var el = doc.getElementById('hwik-strings');
|
|
882
|
+
if (!el) return null;
|
|
883
|
+
try {
|
|
884
|
+
var j = JSON.parse(String(el.textContent || ''));
|
|
885
|
+
return j && typeof j === 'object' && j.strings && typeof j.strings === 'object' ? j : null;
|
|
886
|
+
} catch (e) { return null; }
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
function translate(key, fallback) {
|
|
890
|
+
var k = String(key == null ? '' : key);
|
|
891
|
+
var loc = content.locale;
|
|
892
|
+
var ps = pageStrings();
|
|
893
|
+
if (ps && Object.prototype.hasOwnProperty.call(ps.strings, k)) {
|
|
894
|
+
var e = ps.strings[k];
|
|
895
|
+
if (typeof e === 'string') return e;
|
|
896
|
+
if (e && typeof e === 'object') {
|
|
897
|
+
if (typeof e[loc] === 'string') return e[loc];
|
|
898
|
+
var d = typeof ps['default'] === 'string' ? ps['default'] : 'ko';
|
|
899
|
+
if (typeof e[d] === 'string') return e[d];
|
|
900
|
+
for (var any in e) if (Object.prototype.hasOwnProperty.call(e, any) && typeof e[any] === 'string') return e[any];
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
if (k.indexOf('common.') === 0) {
|
|
904
|
+
var c = k.slice(7);
|
|
905
|
+
var dict = COMMON[loc] || COMMON.en;
|
|
906
|
+
if (Object.prototype.hasOwnProperty.call(dict, c)) return dict[c];
|
|
907
|
+
}
|
|
908
|
+
return typeof fallback === 'string' ? fallback : k;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
function contentWarn(msg) {
|
|
912
|
+
if (global.console && console.warn) console.warn('[SHORTIK bridge] ' + msg);
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
/** Delivers an event to page listeners (shared by host dispatches and SDK-made fallbacks). */
|
|
916
|
+
function deliver(event, data) {
|
|
917
|
+
var list = listeners[event] ? listeners[event].slice() : [];
|
|
918
|
+
for (var i = 0; i < list.length; i++) {
|
|
919
|
+
try { list[i](data || {}); } catch (e) {
|
|
920
|
+
if (global.console && console.error) console.error('[HWIK bridge] listener error', e);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
function applyInit(data) {
|
|
926
|
+
if (!data || typeof data !== 'object') return;
|
|
927
|
+
var l = normLocale(data.locale);
|
|
928
|
+
if (l) { content.locale = l; HWIK.locale = l; }
|
|
929
|
+
if (Object.prototype.hasOwnProperty.call(data, 'save') && !content.loaded && content.saved === undefined) {
|
|
930
|
+
var c = plainCopy(data.save, 0);
|
|
931
|
+
content.startSave = c === undefined ? null : c;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
var ghostApi = {
|
|
936
|
+
/** This round's run, [[second, score], …] (integers, ≤ 120 pairs, ≤ 2 KB), right before complete(). Display only. */
|
|
937
|
+
trace: function (samples) {
|
|
938
|
+
if (!Array.isArray(samples) || samples.length < 1 || samples.length > GHOST_MAX_SAMPLES) { contentWarn('ghost.trace: 1–120 [second, score] pairs'); return false; }
|
|
939
|
+
var out = [];
|
|
940
|
+
for (var i = 0; i < samples.length; i++) {
|
|
941
|
+
var p = samples[i];
|
|
942
|
+
if (!Array.isArray(p) || p.length !== 2 || !isInt(p[0], 0, 3600) || !isInt(p[1], 0, 10000000)) { contentWarn('ghost.trace: pairs of integers [second 0–3600, score 0–10,000,000]'); return false; }
|
|
943
|
+
out.push([p[0], p[1]]);
|
|
944
|
+
}
|
|
945
|
+
if (JSON.stringify(out).length > GHOST_MAX_BYTES) { contentWarn('ghost.trace: over 2 KB'); return false; }
|
|
946
|
+
send('ghost_trace', { samples: out });
|
|
947
|
+
return true;
|
|
948
|
+
}
|
|
949
|
+
};
|
|
950
|
+
|
|
747
951
|
var HWIK = {
|
|
748
952
|
__isHwikBridge: true,
|
|
749
953
|
version: VERSION,
|
|
@@ -860,6 +1064,58 @@
|
|
|
860
1064
|
*/
|
|
861
1065
|
live: liveApi,
|
|
862
1066
|
|
|
1067
|
+
/** v1.11: the app language ('ko', 'en', 'ja', …); updated by the host's 'init'. No country is ever passed. */
|
|
1068
|
+
locale: content.locale,
|
|
1069
|
+
|
|
1070
|
+
/** v1.11: page text from the "hwik-strings" block, else the common phrases ('common.start', …), else fallback / key. */
|
|
1071
|
+
t: function (key, fallback) {
|
|
1072
|
+
return translate(key, fallback);
|
|
1073
|
+
},
|
|
1074
|
+
|
|
1075
|
+
/**
|
|
1076
|
+
* v1.11 progress save, kept on the device by the host (never on a server): a JSON value ≤ 4,096 bytes.
|
|
1077
|
+
* Returns false (and keeps the previous value) for anything else. save(null) clears.
|
|
1078
|
+
*/
|
|
1079
|
+
save: function (obj) {
|
|
1080
|
+
var c = plainCopy(obj, 0);
|
|
1081
|
+
if (c === undefined) { contentWarn('save(obj): only numbers, strings, booleans, null, arrays and plain objects'); return false; }
|
|
1082
|
+
var raw = JSON.stringify(c);
|
|
1083
|
+
if (utf8Bytes(raw) > SAVE_MAX_BYTES) { contentWarn('save(obj): ' + utf8Bytes(raw) + ' bytes > ' + SAVE_MAX_BYTES); return false; }
|
|
1084
|
+
content.saved = c;
|
|
1085
|
+
send('save', { scope: saveScope(), data: c });
|
|
1086
|
+
return true;
|
|
1087
|
+
},
|
|
1088
|
+
|
|
1089
|
+
/** v1.11: the latest save of this page, else the host's start value, else null (a fresh copy every call). */
|
|
1090
|
+
load: function () {
|
|
1091
|
+
content.loaded = true;
|
|
1092
|
+
var v = content.saved !== undefined ? content.saved : content.startSave;
|
|
1093
|
+
return v === null || v === undefined ? null : JSON.parse(JSON.stringify(v));
|
|
1094
|
+
},
|
|
1095
|
+
|
|
1096
|
+
/**
|
|
1097
|
+
* v1.11 vote: option i of question q (both 0-based; vote(i) = question 0) as declared by the "hwik-poll" meta.
|
|
1098
|
+
* The tally arrives as SHORTIK.on('poll', …); without a host answer in 1.5 s, {q, available:false, mine:i}.
|
|
1099
|
+
*/
|
|
1100
|
+
vote: function (q, i) {
|
|
1101
|
+
if (i === undefined) { i = q; q = 0; }
|
|
1102
|
+
var spec = pollSpec();
|
|
1103
|
+
if (!spec) { contentWarn('vote(): declare the meta named "hwik-poll" (options per question, e.g. "3,2")'); return false; }
|
|
1104
|
+
if (!isInt(q, 0, spec.length - 1) || !isInt(i, 0, spec[q] - 1)) { contentWarn('vote(q, i): q 0–' + (spec.length - 1) + ', i 0–' + ((spec[q] || 2) - 1)); return false; }
|
|
1105
|
+
send('vote', { q: q, i: i });
|
|
1106
|
+
if (content.pollTimers[q] && typeof global.clearTimeout === 'function') global.clearTimeout(content.pollTimers[q]);
|
|
1107
|
+
if (typeof global.setTimeout === 'function') {
|
|
1108
|
+
content.pollTimers[q] = global.setTimeout(function () {
|
|
1109
|
+
content.pollTimers[q] = null;
|
|
1110
|
+
deliver('poll', { q: q, available: false, mine: i });
|
|
1111
|
+
}, POLL_FALLBACK_MS);
|
|
1112
|
+
}
|
|
1113
|
+
return true;
|
|
1114
|
+
},
|
|
1115
|
+
|
|
1116
|
+
/** v1.11 ghost runs (declare the "hwik-together" meta with content "ghost"); the other run arrives as on('ghost'). */
|
|
1117
|
+
ghost: ghostApi,
|
|
1118
|
+
|
|
863
1119
|
/** Campaign CTA. The host resolves the id to a tracking link; never navigate yourself. */
|
|
864
1120
|
cta: function (opts) {
|
|
865
1121
|
var id = sanitizeId(opts && opts.id);
|
|
@@ -926,6 +1182,11 @@
|
|
|
926
1182
|
if (EVENTS.indexOf(event) < 0) return false;
|
|
927
1183
|
// v1.10 live frames: delivered by the live module (ignored during a solo round or when no room was joined).
|
|
928
1184
|
if (event === 'live') return liveFromHost(data);
|
|
1185
|
+
if (event === 'init') applyInit(data);
|
|
1186
|
+
if (event === 'poll' && data && typeof data === 'object' && isInt(data.q, 0, 9) && content.pollTimers[data.q]) {
|
|
1187
|
+
if (typeof global.clearTimeout === 'function') global.clearTimeout(content.pollTimers[data.q]);
|
|
1188
|
+
content.pollTimers[data.q] = null;
|
|
1189
|
+
}
|
|
929
1190
|
if (event === 'capabilities' && data && typeof data === 'object') {
|
|
930
1191
|
capabilityMap = {};
|
|
931
1192
|
for (var k in data) if (Object.prototype.hasOwnProperty.call(data, k)) capabilityMap[k] = !!data[k];
|