slow.monster

STUDIO HAZE · kakao

Topaz source

Open by house policy. Topaz is our own language.

Topaz 5.6.1 · 4 files

games/domain-war/core/state.tpz

Topaz · 3573 B · Original file

1// 도메인 전쟁 STATE 문자열. 순수 코어는 브라우저 저장소나 URL을 읽지 않고, 이 한 줄 상태만 주고받는다.
2// Domain War STATE string. The pure core never reads browser storage or the URL; it only receives and returns this one-line state.
3//
4// 하우스룰(core): export는 타입/함수/불변 값만. 최상위 가변 상태, print, input, now_millis, 파일 IO 금지.
5// House rule (core): export only types/functions/immutable values; no module-level mutability, print, input, now_millis, or file IO.
6//
7// STATE v1:
8// v1:<currentScene>:<visitedSceneIds comma-separated>
9// 예: v1:ch3_scene4:ch1_scene0,ch1_scene1,ch1_scene3,ch2_scene0
10// Example: v1:ch3_scene4:ch1_scene0,ch1_scene1,ch1_scene3,ch2_scene0
11//
12// 방문경로는 "뒤로"를 위한 순수 스택이다. URL deep-link는 빈 방문경로로 특정 장면을 렌더한다.
13// visitedPath is the pure stack for Back. URL deep links render a scene with an empty path.
15import data.scenes
17export type 상태 = {
18 버전: int,
19 현재: scenes.장면아이디,
20 방문경로: Array<scenes.장면아이디>
23export function 기본상태() -> 상태 {
24 { 버전: 1, 현재: scenes.시작장면(), 방문경로: [] }
27export function 위치상태(아이디: scenes.장면아이디) -> 상태 {
28 { 버전: 1, 현재: 아이디, 방문경로: [] }
31function 경로직렬화(경로: Array<scenes.장면아이디>) -> string {
32 경로.map((아이디) => "{아이디}").join(",")
35export function 직렬화(에스: 상태) -> string {
36 "v1:{에스.현재}:{경로직렬화(에스.방문경로)}"
39function 경로파싱(토큰: string) -> Array<scenes.장면아이디> {
40 let mut 결과: Array<scenes.장면아이디> = []
41 let 다듬 = 토큰.trim()
42 if 다듬 == "" { return 결과 }
43 let 조각들 = 다듬.split(",")
44 let 시작 = if 조각들.length > 128 { 조각들.length - 128 } else { 0 }
45 for i in 시작..<조각들.length {
46 let 조각 = 조각들[i].trim()
47 if 조각 != "" { 결과.push(scenes.장면파싱(조각)) }
48 }
49 결과
52export function 역직렬화(문자열: string) -> 상태 {
53 let 다듬 = 문자열.trim()
54 if 다듬 == "" { return 기본상태() }
55 let 부분 = 다듬.split(":")
56 if 부분.length < 2 { return 기본상태() }
57 let 현재 = scenes.장면파싱(부분[1])
58 let 경로 = if 부분.length >= 3 { 경로파싱(부분[2]) } else { [] }
59 { 버전: 1, 현재: 현재, 방문경로: 경로 }
62function 경로복사추가(경로: Array<scenes.장면아이디>, 아이디: scenes.장면아이디) -> Array<scenes.장면아이디> {
63 let mut 결과: Array<scenes.장면아이디> = []
64 let 시작 = if 경로.length > 127 { 경로.length - 127 } else { 0 }
65 for i in 시작..<경로.length {
66 결과.push(경로[i])
67 }
68 결과.push(아이디)
69 결과
72function 경로끝제거(경로: Array<scenes.장면아이디>) -> Array<scenes.장면아이디> {
73 let mut 결과: Array<scenes.장면아이디> = []
74 let 한계 = if 경로.length == 0 { 0 } else { 경로.length - 1 }
75 for i in 0..<한계 {
76 결과.push(경로[i])
77 }
78 결과
81export function 이동(에스: 상태, 다음: scenes.장면아이디) -> 상태 {
82 { 버전: 1, 현재: 다음, 방문경로: 경로복사추가(에스.방문경로, 에스.현재) }
85export function 뒤로(에스: 상태) -> 상태 {
86 if 에스.방문경로.length == 0 { return 에스 }
87 let 이전 = 에스.방문경로[에스.방문경로.length - 1]
88 { 버전: 1, 현재: 이전, 방문경로: 경로끝제거(에스.방문경로) }

SHA256 e10215723bb0eef57c011410dcfb08aca9c5827c8de83f1de8600944d1a957b3