Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"fix-missing-heads:prod": "node dist/scripts/fixCharactersMissingHeads.js",
"import-game-data": "tsx src/scripts/importGameData.ts",
"import-game-data:prod": "node dist/scripts/importGameData.js npcs",
"import-game-maps": "tsx src/scripts/importGameData.ts maps",
"remove-newbie-items": "tsx src/scripts/removeNewbieItemsFromHighLevelCharacters.ts",
"remove-newbie-items:prod": "node dist/scripts/removeNewbieItemsFromHighLevelCharacters.js",
"reset-spell-stats": "tsx src/scripts/resetSpellStats.ts",
Expand Down
48 changes: 47 additions & 1 deletion api/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,48 @@ CREATE TABLE IF NOT EXISTS game_balance (
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- OpenAO #3: map persistence (measured: grid as JSONB doc, palette relational)

CREATE TABLE IF NOT EXISTS game_maps (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
terreno TEXT NOT NULL DEFAULT '',
zona TEXT NOT NULL DEFAULT '',
restringir TEXT NOT NULL DEFAULT '',
min_level INTEGER NOT NULL DEFAULT 0,
max_level INTEGER NOT NULL DEFAULT 0,
pk BOOLEAN NOT NULL DEFAULT FALSE,
metadata JSONB NOT NULL,
npcs JSONB NOT NULL DEFAULT '[]'::jsonb,
specials JSONB NOT NULL DEFAULT '{}'::jsonb,
checksum TEXT NOT NULL,
source_checksum TEXT NOT NULL,
is_edited BOOLEAN NOT NULL DEFAULT FALSE,
version BIGINT NOT NULL DEFAULT 0,
updated_by_account_id UUID REFERENCES accounts(id) ON DELETE SET NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE TABLE IF NOT EXISTS game_map_palette (
map_id INTEGER NOT NULL REFERENCES game_maps(id) ON DELETE CASCADE,
palette_key INTEGER NOT NULL CHECK (palette_key > 0),
graphics JSONB,
blocked BOOLEAN NOT NULL DEFAULT FALSE,
tile JSONB NOT NULL DEFAULT '{}'::jsonb,
PRIMARY KEY (map_id, palette_key)
);

CREATE TABLE IF NOT EXISTS game_map_grids (
map_id INTEGER PRIMARY KEY REFERENCES game_maps(id) ON DELETE CASCADE,
width INTEGER NOT NULL CHECK (width > 0),
height INTEGER NOT NULL CHECK (height > 0),
rows JSONB NOT NULL
);

CREATE INDEX IF NOT EXISTS idx_game_map_palette_map
ON game_map_palette(map_id);

CREATE TABLE IF NOT EXISTS game_data_revisions (
id BIGSERIAL PRIMARY KEY,
kind TEXT NOT NULL,
Expand All @@ -522,7 +564,7 @@ CREATE TABLE IF NOT EXISTS game_data_revisions (
ALTER TABLE game_data_revisions DROP CONSTRAINT IF EXISTS game_data_revisions_kind_check;
ALTER TABLE game_data_revisions
ADD CONSTRAINT game_data_revisions_kind_check
CHECK (kind IN ('objs', 'npcs', 'crafting_recipes', 'smelting_recipes', 'balance'));
CHECK (kind IN ('objs', 'npcs', 'crafting_recipes', 'smelting_recipes', 'balance', 'maps'));

CREATE INDEX IF NOT EXISTS idx_accounts_email ON accounts(email);
CREATE INDEX IF NOT EXISTS idx_characters_account_id ON characters(account_id);
Expand Down Expand Up @@ -558,6 +600,10 @@ CREATE INDEX IF NOT EXISTS idx_game_crafting_recipes_item_id ON game_crafting_re
CREATE INDEX IF NOT EXISTS idx_game_smelting_recipes_updated_at ON game_smelting_recipes(updated_at DESC);
CREATE INDEX IF NOT EXISTS idx_game_smelting_recipes_mineral_item_id ON game_smelting_recipes(mineral_item_id);
CREATE INDEX IF NOT EXISTS idx_game_balance_updated_at ON game_balance(updated_at DESC);
CREATE INDEX IF NOT EXISTS idx_game_maps_updated_at ON game_maps(updated_at DESC);
CREATE INDEX IF NOT EXISTS idx_game_maps_name_lower ON game_maps(LOWER(name));
CREATE INDEX IF NOT EXISTS idx_game_maps_zone_terrain ON game_maps(zona, terreno);
CREATE INDEX IF NOT EXISTS idx_game_maps_edited ON game_maps(is_edited) WHERE is_edited = TRUE;
CREATE INDEX IF NOT EXISTS idx_game_data_revisions_kind_id ON game_data_revisions(kind, id DESC);
CREATE INDEX IF NOT EXISTS idx_challenge_history_finished_at ON challenge_history(finished_at DESC);

Expand Down
Loading