Skip to content

Commit 919397f

Browse files
authored
feat: add planet texture images in webp format (#50)
* feat: add `imageUrl` property to `Planet` model * refractor: make environment variable more reusable * feat: populate `imageUrl` property * fix: resolve issues with invalid url
1 parent 02002dd commit 919397f

File tree

7 files changed

+77
-9
lines changed

7 files changed

+77
-9
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ env:
88
HISTORY_API_URL: "https://helldivers-b.omnedia.com/api"
99
API_URL: "https://api.live.prod.thehelldiversgame.com/api"
1010
# stratagem setup
11-
STRATAGEM_IMAGE_URL: "https://vxspqnuarwhjjbxzgauv.supabase.co/storage/v1/object/public/stratagems"
11+
STORAGE_URL: "https://vxspqnuarwhjjbxzgauv.supabase.co/storage/v1/object/public"
1212

1313
on:
1414
pull_request:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ENV RATE_LIMIT="200"
88
ENV DATABASE_URL="file:./database/data.db"
99
ENV HISTORY_API_URL="https://helldivers-b.omnedia.com/api"
1010
ENV API_URL="https://api.live.prod.thehelldiversgame.com/api"
11-
ENV STRATAGEM_IMAGE_URL="https://vxspqnuarwhjjbxzgauv.supabase.co/storage/v1/object/public/stratagems"
11+
ENV STORAGE_URL="https://vxspqnuarwhjjbxzgauv.supabase.co/storage/v1/object/public"
1212

1313
# install dependencies into temp directory
1414
# this will cache them and speed up future builds
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Warnings:
3+
4+
- Added the required column `imageUrl` to the `Planet` table without a default value. This is not possible if the table is not empty.
5+
6+
*/
7+
-- RedefineTables
8+
PRAGMA foreign_keys=OFF;
9+
CREATE TABLE "new_Planet" (
10+
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
11+
"index" BIGINT NOT NULL,
12+
"name" TEXT NOT NULL,
13+
"ownerId" INTEGER NOT NULL,
14+
"sectorId" INTEGER NOT NULL,
15+
"health" INTEGER NOT NULL,
16+
"maxHealth" INTEGER NOT NULL,
17+
"imageUrl" TEXT NOT NULL,
18+
"players" INTEGER NOT NULL,
19+
"disabled" BOOLEAN NOT NULL,
20+
"regeneration" INTEGER NOT NULL,
21+
"liberation" REAL NOT NULL,
22+
"liberationRate" REAL NOT NULL,
23+
"liberationState" TEXT NOT NULL,
24+
"initialOwnerId" INTEGER NOT NULL,
25+
"positionX" REAL NOT NULL,
26+
"positionY" REAL NOT NULL,
27+
"globalEventId" INTEGER,
28+
"biomeId" INTEGER NOT NULL,
29+
"statisticId" INTEGER,
30+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
31+
"updatedAt" DATETIME NOT NULL,
32+
CONSTRAINT "Planet_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "Faction" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
33+
CONSTRAINT "Planet_sectorId_fkey" FOREIGN KEY ("sectorId") REFERENCES "Sector" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
34+
CONSTRAINT "Planet_initialOwnerId_fkey" FOREIGN KEY ("initialOwnerId") REFERENCES "Faction" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
35+
CONSTRAINT "Planet_globalEventId_fkey" FOREIGN KEY ("globalEventId") REFERENCES "GlobalEvent" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
36+
CONSTRAINT "Planet_biomeId_fkey" FOREIGN KEY ("biomeId") REFERENCES "Biome" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
37+
CONSTRAINT "Planet_statisticId_fkey" FOREIGN KEY ("statisticId") REFERENCES "Stats" ("id") ON DELETE SET NULL ON UPDATE CASCADE
38+
);
39+
INSERT INTO "new_Planet" ("biomeId", "createdAt", "disabled", "globalEventId", "health", "id", "index", "initialOwnerId", "liberation", "liberationRate", "liberationState", "maxHealth", "name", "ownerId", "players", "positionX", "positionY", "regeneration", "sectorId", "statisticId", "updatedAt") SELECT "biomeId", "createdAt", "disabled", "globalEventId", "health", "id", "index", "initialOwnerId", "liberation", "liberationRate", "liberationState", "maxHealth", "name", "ownerId", "players", "positionX", "positionY", "regeneration", "sectorId", "statisticId", "updatedAt" FROM "Planet";
40+
DROP TABLE "Planet";
41+
ALTER TABLE "new_Planet" RENAME TO "Planet";
42+
CREATE UNIQUE INDEX "Planet_index_key" ON "Planet"("index");
43+
CREATE UNIQUE INDEX "Planet_statisticId_key" ON "Planet"("statisticId");
44+
PRAGMA foreign_key_check;
45+
PRAGMA foreign_keys=ON;

prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ model Planet {
5353
sectorId Int
5454
health Int
5555
maxHealth Int
56+
imageUrl String
5657
players Int
5758
disabled Boolean
5859
regeneration Int

src/controllers/stratagems.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ export const getStratagemById = await witCache(async (ctx: Context) => {
3030
}
3131

3232
// slightly transform the data
33-
const imageBaseUrl = process.env.STRATAGEM_IMAGE_URL || "";
33+
const imageBaseUrl = process.env.STORAGE_URL
34+
? `${process.env.STORAGE_URL}/stratagems`
35+
: "";
36+
3437
stratagem.imageUrl = `${imageBaseUrl}${stratagem.imageUrl}`;
3538
(stratagem as any).keys = stratagem.keys.split(",");
3639

@@ -57,7 +60,10 @@ export const getAllStratagems = await witCache(async (ctx: Context) => {
5760
return ctx.json({
5861
data: stratagems.map(stratagem => {
5962
// slightly transform the data
60-
const imageBaseUrl = process.env.STRATAGEM_IMAGE_URL || "";
63+
const imageBaseUrl = process.env.STORAGE_URL
64+
? `${process.env.STORAGE_URL}/stratagems`
65+
: "";
66+
6167
stratagem.imageUrl = `${imageBaseUrl}${stratagem.imageUrl}`;
6268
(stratagem as any).keys = stratagem.keys.split(",");
6369
return stratagem;

src/static/json/planets.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"0": {
33
"name": "Super Earth",
44
"biome": "unknown",
5-
"effects": ["none"]
5+
"effects": ["none"],
6+
"imageName": "superearth"
67
},
78
"1": {
89
"name": "Klen Dahth II",
@@ -1197,7 +1198,8 @@
11971198
"239": {
11981199
"name": "Tien Kwan",
11991200
"biome": "icemoss_special",
1200-
"effects": ["extreme_cold", "meteor_storms"]
1201+
"effects": ["extreme_cold", "meteor_storms"],
1202+
"imageName": "tienkwan"
12011203
},
12021204
"240": {
12031205
"name": "Troost",
@@ -1302,6 +1304,7 @@
13021304
"260": {
13031305
"name": "Cyberstan",
13041306
"biome": "icemoss_special",
1305-
"effects": ["tremors"]
1307+
"effects": ["tremors"],
1308+
"imageName": "cyberstan"
13061309
}
13071310
}

src/utils/generate.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface PlanetEntry {
2424
name: string;
2525
index: number;
2626
biome: string;
27+
imageName: string;
2728
effects: string[];
2829
}
2930

@@ -47,7 +48,7 @@ export interface EffectEntry extends BiomeEntry {}
4748
export async function prepareForSourceData() {
4849
const [factions, planets, sectors, biomes, effects]: [
4950
NameEntry[],
50-
Array<NameEntry & { biome: string; effects: string[] }>,
51+
Array<NameEntry & { imageUrl: string; biome: string; effects: string[] }>,
5152
SectorEntry[],
5253
Array<Omit<NameEntry, "index"> & { index: string; description: string }>,
5354
Array<Omit<NameEntry, "index"> & { index: string; description: string }>,
@@ -106,7 +107,18 @@ export async function prepareForSourceData() {
106107

107108
// populate planets
108109
for (const key in planetsJSON) {
109-
planets.push({ ...planetsJSON[key], index: parseInt(key) });
110+
const entry = planetsJSON[key];
111+
const folder = entry.imageName ? "unique" : "biome";
112+
const file = `${entry.imageName ?? entry.biome}.webp`;
113+
const baseImageUrl = process.env.STORAGE_URL
114+
? `${process.env.STORAGE_URL}`
115+
: "";
116+
117+
planets.push({
118+
...planetsJSON[key],
119+
index: parseInt(key),
120+
imageUrl: `${baseImageUrl}/planets/${folder}/${file}`,
121+
});
110122
}
111123

112124
// populate sectors
@@ -412,6 +424,7 @@ export async function transformAndStoreSourceData() {
412424
disabled: info.disabled,
413425
players: status.players,
414426
maxHealth: info.maxHealth,
427+
imageUrl: planet.imageUrl,
415428
positionX: info.position.x,
416429
positionY: info.position.y,
417430
regeneration: status.regenPerSecond,

0 commit comments

Comments
 (0)