From 1154414885c8448bb6ee0637f10a1e2d8a3e0963 Mon Sep 17 00:00:00 2001 From: BemaniWitch Date: Sat, 31 Oct 2020 19:33:14 -0400 Subject: [PATCH] idz: Add field "c" to story cell tuple --- schema/init/idz.sql | 1 + schema/migrate/M0017-idz-v2-support.sql | 37 +++++++++++++++++++++++++ src/idz/userdb/decoder/saveProfile2.ts | 3 +- src/idz/userdb/decoder/saveProfile3.ts | 3 +- src/idz/userdb/model/story.ts | 1 + src/idz/userdb/sql/story.ts | 7 +++-- 6 files changed, 48 insertions(+), 4 deletions(-) diff --git a/schema/init/idz.sql b/schema/init/idz.sql index 6252169..3b25008 100644 --- a/schema/init/idz.sql +++ b/schema/init/idz.sql @@ -144,6 +144,7 @@ create table "idz_story_cell_state" ( "col_no" integer not null, "a" integer not null, "b" integer not null, + "c" integer not null, constraint "idz_story_cell_state_uq" unique ( "profile_id", "row_no", diff --git a/schema/migrate/M0017-idz-v2-support.sql b/schema/migrate/M0017-idz-v2-support.sql index d04bffb..81fac1f 100644 --- a/schema/migrate/M0017-idz-v2-support.sql +++ b/schema/migrate/M0017-idz-v2-support.sql @@ -38,6 +38,23 @@ create table "idz_stamp_unlock" ( constraint "idz_stamp_unlock_uq" unique ("profile_id", "stamp_no") ); +create table "new_idz_story_cell_state" ( + "id" integer primary key not null, + "profile_id" integer not null + references "idz_profile"("id") + on delete cascade, + "row_no" integer not null, + "col_no" integer not null, + "a" integer not null, + "b" integer not null, + "c" integer not null, + constraint "idz_story_cell_state_uq" unique ( + "profile_id", + "row_no", + "col_no" + ) +); + create table "idz_weekly_missions" ( "id" integer primary key not null references "idz_profile"("id") @@ -69,6 +86,26 @@ insert into "new_idz_settings" ( 0 from "idz_settings" as x; +insert into "new_idz_story_cell_state" ( + "id", + "profile_id", + "row_no", + "col_no", + "a", + "b", + "c" +) select + x."id", + x."profile_id", + x."row_no", + x."col_no", + x."a", + x."b", + 0 +from "idz_story_cell_state" as x; + drop table "idz_settings"; +drop table "idz_story_cell_state"; alter table "new_idz_settings" rename to "idz_settings"; +alter table "new_idz_story_cell_state" rename to "idz_story_cell_state"; diff --git a/src/idz/userdb/decoder/saveProfile2.ts b/src/idz/userdb/decoder/saveProfile2.ts index 5fc9071..ffe3641 100644 --- a/src/idz/userdb/decoder/saveProfile2.ts +++ b/src/idz/userdb/decoder/saveProfile2.ts @@ -19,7 +19,8 @@ export function saveProfile2(buf: Buffer): SaveProfileRequest { for (let j = 0; j < 9; j++) { const a = buf.readUInt32LE(rowOffset + 0x04 + j * 4); const b = buf.readUInt16LE(rowOffset + 0x28 + j * 2); - const cell = { a, b }; + const c = 0; // Added in idz2 + const cell = { a, b, c }; cells.set(j, cell); } diff --git a/src/idz/userdb/decoder/saveProfile3.ts b/src/idz/userdb/decoder/saveProfile3.ts index f586086..c7a992d 100644 --- a/src/idz/userdb/decoder/saveProfile3.ts +++ b/src/idz/userdb/decoder/saveProfile3.ts @@ -21,7 +21,8 @@ export function saveProfile3(buf: Buffer): SaveProfileRequest { for (let j = 0; j < 9; j++) { const a = buf.readUInt8(rowOffset + 0x00 + j); const b = buf.readUInt8(rowOffset + 0x09 + j); - const cell = { a, b }; + const c = 0; // Added in idz2 + const cell = { a, b, c }; cells.set(j, cell); } diff --git a/src/idz/userdb/model/story.ts b/src/idz/userdb/model/story.ts index 296177c..f42174f 100644 --- a/src/idz/userdb/model/story.ts +++ b/src/idz/userdb/model/story.ts @@ -1,6 +1,7 @@ export interface StoryCell { a: number; b: number; + c: number; } export interface StoryRow { diff --git a/src/idz/userdb/sql/story.ts b/src/idz/userdb/sql/story.ts index 8eada11..4fa35bd 100644 --- a/src/idz/userdb/sql/story.ts +++ b/src/idz/userdb/sql/story.ts @@ -18,7 +18,7 @@ function cellChanged( return true; } - return lhs.a !== rhs.a || lhs.b !== rhs.b; + return lhs.a !== rhs.a || lhs.b !== rhs.b || lhs.c !== rhs.c; } export class SqlStoryRepository implements FacetRepository { @@ -63,6 +63,7 @@ export class SqlStoryRepository implements FacetRepository { gridRow.cells.set(colNo, { a: 0, b: 0, + c: 0, }); } @@ -70,6 +71,7 @@ export class SqlStoryRepository implements FacetRepository { cell.a = parseInt(row.a!); cell.b = parseInt(row.b!); + cell.c = parseInt(row.c!); } return result; @@ -109,9 +111,10 @@ export class SqlStoryRepository implements FacetRepository { col_no: j, a: cell.a, b: cell.b, + c: cell.c, }) .onConflict("profile_id", "row_no", "col_no") - .doUpdate(["a", "b"]); + .doUpdate(["a", "b", "c"]); await this._txn.modify(cellSql); }