This commit is contained in:
Aotumuri
2025-05-22 17:18:53 +09:00
parent f266b74c77
commit aad1f63776
4 changed files with 71 additions and 231 deletions
+31 -1
View File
@@ -5,7 +5,8 @@ const PatternSchema = z.object({
tileWidth: z.number(),
tileHeight: z.number(),
scale: z.number(),
pattern: z.array(z.array(z.number())),
pattern: z.array(z.array(z.number())).optional(),
patternBase64: z.string().optional(),
});
const TerritoryPatternsSchema = z.object({
@@ -15,6 +16,35 @@ const TerritoryPatternsSchema = z.object({
export const territoryPatterns =
TerritoryPatternsSchema.parse(rawTerritoryPatterns);
for (const [key, value] of Object.entries(territoryPatterns.patterns)) {
if (!value.pattern && value.patternBase64) {
const byteString = atob(value.patternBase64);
const bytes = new Uint8Array(byteString.length);
for (let i = 0; i < byteString.length; i++) {
bytes[i] = byteString.charCodeAt(i);
}
const bits: number[] = [];
for (const byte of bytes) {
for (let i = 7; i >= 0; i--) {
bits.push((byte >> i) & 1);
}
}
const pattern: number[][] = [];
for (let y = 0; y < value.tileHeight; y++) {
const row: number[] = [];
for (let x = 0; x < value.tileWidth; x++) {
const index = y * value.tileWidth + x;
row.push(bits[index] ?? 0);
}
pattern.push(row);
}
value.pattern = pattern;
}
}
export class TerritoryPatternStorage {
private static readonly KEY = "territoryPattern";
+23 -2
View File
@@ -48,6 +48,27 @@ export class territoryPatternsModal extends LitElement {
this.updatePreview();
});
for (const [key, p] of Object.entries(territoryPatterns.patterns)) {
if (!p.pattern && p.patternBase64) {
const bytes = Uint8Array.from(atob(p.patternBase64), (c) =>
c.charCodeAt(0),
);
const bits = Array.from(bytes).flatMap((byte) =>
[...Array(8)].map((_, i) => (byte >> (7 - i)) & 1),
);
const pattern: number[][] = [];
for (let y = 0; y < p.tileHeight; y++) {
const row: number[] = [];
for (let x = 0; x < p.tileWidth; x++) {
const index = y * p.tileWidth + x;
row.push(bits[index] ?? 0);
}
pattern.push(row);
}
p.pattern = pattern;
}
}
this.setLockedPatterns(["evan"], {
evan: "This pattern is locked because it is restricted.",
});
@@ -129,7 +150,7 @@ export class territoryPatternsModal extends LitElement {
border-radius: 4px;
"
>
${pattern.pattern.flat().map(
${(pattern.pattern ?? []).flat().map(
(cell) => html`
<div
style="
@@ -212,7 +233,7 @@ export class territoryPatternsModal extends LitElement {
border-radius: 4px;
"
>
${pattern.pattern.flat().map(
${(pattern.pattern ?? []).flat().map(
(cell) => html`
<div
style="
+1 -1
View File
@@ -306,7 +306,7 @@ export class TerritoryLayer implements Layer {
const px = Math.floor(x / scale) % tileWidth;
const py = Math.floor(y / scale) % tileHeight;
const patternValue = pattern[py][px];
const patternValue = pattern ? pattern[py][px] : 0;
const colorToUse =
patternValue === 1 ? baseColor.darken(0.2) : baseColor;