Chain2D.Update
릴리스의 파일을 내려받습니다. 언제 받을지는 창작자가 정합니다 — 셀룰러에서 오백 메가를 묻지도 않고 받는 클라이언트는 만들면 안 되고, 연출이 도는 동안 미리 받고 싶을 수도 있습니다. 넘기는 것은 시점뿐입니다: 무엇을 받을지와 순서와 검증은 엔진이 쥐고 있어서, 건너뛰는 방법도 다 받았다고 말하는 방법도 없습니다.
Update.start
Chain2D.Update.start() -> (boolean, string?)(boolean, string?)시작했으면 `true`. 시작하지 못했으면 `false` 와 이유가 함께 옵니다.
내려받기를 시작합니다. 진행은 값으로 돌아오지 않고 `Update.onProgress` 와 `Update.state` 로 옵니다 — 이 호출은 시작했다는 것까지만 답합니다. 내려받기를 붙이지 않은 빌드에서 부르면 값 대신 `this build cannot update` 오류가 납니다.
언제로그인한 뒤(`Chain2D.stage()` 가 `"authenticated"` 부터)에만 — 부트 모퉁이 너머의 파일은 세션이 있어야 받을 수 있기 때문입니다. 로그인 전에 부르면 `not signed in` 이 값이 아니라 오류로 올라옵니다: `false, "not signed in"` 이 돌아오는 것이 아니라 그 줄에서 스크립트가 멈추므로, 단계가 확실하지 않은 자리에서는 `Chain2D.stage()` 를 먼저 보거나 `pcall` 로 감쌉니다. 이 점이 `Chain2D.join` 과 다릅니다 — 그쪽은 단계 거부도 값으로 옵니다.
if Chain2D.stage() ~= "boot" then
local ok, why = Chain2D.Update.start()
if not ok then
print("받기 시작하지 못했습니다: " .. why)
end
endUpdate.onProgress
Chain2D.Update.onProgress(handler: (progress: { stage: string, receivedBytes: number, totalBytes: number, fileIndex: number, fileCount: number, error: string? }) -> ())| handler | (progress: { stage: string, receivedBytes: number, totalBytes: number, fileIndex: number, fileCount: number, error: string? }) -> () | 진행이 바뀔 때마다 불립니다. 인자는 `Update.state` 가 돌려주는 것과 같은 표입니다: `stage`, `receivedBytes`, `totalBytes`, `fileIndex`, `fileCount`, 그리고 실패했을 때만 있는 `error`. 함수가 아니면 오류가 납니다. |
받는 동안의 진행을 듣습니다. 여기에 손댈 것은 없습니다 — 파일을 건너뛰거나 다 받았다고 선언하는 방법이 없는 것은, 기계는 Chain2D 의 것이고 그림만 창작자의 것이기 때문입니다. handler 는 보호된 채로 불립니다: 진행 막대가 오류를 내도 그것이 그리고 있던 내려받기는 멈추지 않고, 진행은 계속 기록되어 `Update.state` 로 읽힙니다. 다만 오류를 낸 스크립트는 꺼지고 그 뒤의 핸들러는 불리지 않습니다. 여러 번 부르면 여럿이 걸리고 등록한 순서대로 모두 불립니다 — 로비와 게임 화면은 한 VM 에서 도는 두 스크립트이고, 한 자리만 두면 나중 등록이 앞의 것을 조용히 지웁니다.
Chain2D.Update.onProgress(function(progress)
if progress.stage == "failed" then
warn(progress.error)
return
end
print(progress.receivedBytes, progress.totalBytes)
end)Update.state
Chain2D.Update.state() -> { stage: string, receivedBytes: number, totalBytes: number, fileIndex: number, fileCount: number, error: string? }{ stage: string, receivedBytes: number, totalBytes: number, fileIndex: number, fileCount: number, error: string? }`stage` 는 `"idle"`, `"manifest"`, `"downloading"`, `"verifying"`, `"done"`, `"failed"` 중 하나입니다. `error` 는 이유가 있을 때만 있고, 없으면 `nil` 입니다. 아직 아무 일도 없었으면 `stage` 는 `"idle"` 이고 나머지 수는 0 입니다.
지금까지의 진행을 묻습니다. `onProgress` 의 handler 가 받는 것과 같은 표를 돌려줍니다 — 핸들러를 늦게 단 화면도 지금이 어디인지 알 수 있어야 하므로, 마지막 상태는 물어서도 읽힙니다.
if Chain2D.Update.state().stage == "idle" then
Chain2D.Update.start()
end