Games asked entity.records for their progress with hand-written JSON and converted completion marks themselves. GameProgressGetRequest, GameProgressPutRequest and GameProgressReply carry the record, and GameProgressSetLevels and GameProgressMarkLevels convert a game's completed levels.
54 lines
2.7 KiB
Ziran
54 lines
2.7 KiB
Ziran
#import "std/text_buffer"
|
|
#import "std/json_scan"
|
|
#import "std/vec"
|
|
#import "game_progress"
|
|
#import "game_progress_id"
|
|
#import "model"
|
|
|
|
#program_export
|
|
main :: () -> s32 {
|
|
record_id: [33]u8
|
|
if !GameProgressID("shovey.classic", record_id[:]) || TextUntilNul(record_id[:]) != "fd65a3d7ac3d5ceb2d4d96cc5224a740" { return 8 }
|
|
left: GameProgressRecord
|
|
right: GameProgressRecord
|
|
if !GameProgressRead("{\"game\":\"shovey.classic\",\"unlocked\":40,\"completed\":\"1101\",\"state\":\"newer\",\"updated_at\":20}", *left) { return 1 }
|
|
if !GameProgressRead("{\"game\":\"shovey.classic\",\"unlocked\":20,\"completed\":\"101\",\"state\":\"older\",\"updated_at\":10}", *right) { return 2 }
|
|
original := left
|
|
if !GameProgressMerge(*left, *right) || left.unlocked != 40 ||
|
|
TextUntilNul(left.completed[:]) != "1111" { return 3 }
|
|
if !GameProgressMerge(*right, *original) || !GameProgressSame(*left, *right) { return 4 }
|
|
out: Vec(u8)
|
|
GameProgressWrite(*left, *out)
|
|
if FieldAt(TextView(VecSlice(out, 0, out.count)), 0, "state") >= 0 { return 11 }
|
|
restored: GameProgressRecord
|
|
valid := GameProgressRead(TextView(VecSlice(out, 0, out.count)), *restored)
|
|
VecFree(out)
|
|
if !valid || !GameProgressSame(*left, *restored) { return 5 }
|
|
if GameProgressRead("{\"game\":\"g\",\"unlocked\":0,\"completed\":\"1\",\"state\":\"\"}", *restored) ||
|
|
GameProgressRead("{\"game\":\"g\",\"unlocked\":1.5,\"completed\":\"1\",\"state\":\"\"}", *restored) ||
|
|
GameProgressRead("{\"game\":\"g\",\"unlocked\":2,\"completed\":\"2\",\"state\":\"\"}", *restored) { return 6 }
|
|
restored.game[0] = #char "x"
|
|
if GameProgressMerge(*left, *restored) || TextUntilNul(left.game[:]) != "shovey.classic" { return 7 }
|
|
levels: [6]bool = .[true, false, true, false, false, false]
|
|
marked: GameProgressRecord
|
|
GameProgressSetLevels(*marked, levels[:])
|
|
if TextUntilNul(marked.completed[:]) != "101" { return 12 }
|
|
seen: [6]bool
|
|
seen[4] = true
|
|
GameProgressMarkLevels(*marked, seen[:])
|
|
if !seen[0] || seen[1] || !seen[2] || seen[3] || !seen[4] { return 13 }
|
|
get: Vec(u8)
|
|
GameProgressGetRequest("wurm", *get)
|
|
expected := "{\"operation\":\"get\",\"kind\":\"game-progress\",\"game\":\"wurm\"}"
|
|
if TextView(VecSlice(get, 0, get.count)) != expected { return 14 }
|
|
VecFree(get)
|
|
put: Vec(u8)
|
|
GameProgressPutRequest(*left, *put)
|
|
request := TextView(VecSlice(put, 0, put.count))
|
|
stored: GameProgressRecord
|
|
if FieldAt(request, 0, "schema") < 0 || !GameProgressReply(request, *stored) || !GameProgressSame(*left, *stored) { return 15 }
|
|
VecFree(put)
|
|
if GameProgressReply("{\"status\":\"missing\"}", *stored) { return 16 }
|
|
return 0
|
|
}
|