Skip to content

Commit

Permalink
Commiting everything could work...
Browse files Browse the repository at this point in the history
Something broke with the newer codec version, so we downgrade again
  • Loading branch information
platz1de committed Dec 12, 2024
1 parent 10cf247 commit 6617ad7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
32 changes: 22 additions & 10 deletions scripts/theme-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ module.exports = async function (theme) {
if (!(key in data)) data[key] = defaultTheme[key];
}

const obj = {};
for (const key of ["territory", "border", "tiles"]) {
const obj = {tiles: []};
for (const key of ["territory", "border"]) {
obj[key] = parseColorAction(data[key]);
}

const overwrites = {};
for (const key in data.tileOverwrite) {
overwrites[key] = parseColor(data.tileOverwrite[key]);
for (const key in data.tileColors) {
obj.tiles.push(`case "${key}":
return ${parseColorVariant(data.tileColors[key])};`);
}

const shaders = [];
Expand All @@ -48,8 +48,11 @@ module.exports = async function (theme) {
return ${obj.border};
},
getTileColor(tile: TileType): HSLColor {
const color = tile.baseColor;
return ${obj.tiles};
switch (tile.colorBase) {
${obj.tiles.join("\n")}
default:
return HSLColor.fromRGB(255, 255, 0);
}
},
getBackgroundColor(): HSLColor {
return ${parseColor(data.background)};
Expand All @@ -64,12 +67,11 @@ module.exports = async function (theme) {

themes.push({
name: name,
obj: stringified,
overwrites: Object.keys(overwrites).map(key => `"${key}": ${overwrites[key]}`)
obj: stringified
});
}

theme = theme.replace(/\/\/ BUILD_THEMES_REGISTER/, themes.map(m => `registerTheme("${m.name}", ${m.obj}, {${m.overwrites.join(", ")}});`).join("\n"));
theme = theme.replace(/\/\/ BUILD_THEMES_REGISTER/, themes.map(m => `registerTheme("${m.name}", ${m.obj});`).join("\n"));
}
return theme;
}
Expand Down Expand Up @@ -107,6 +109,16 @@ function parseColor(color) {
throw new Error("Invalid color format: " + color);
}

function parseColorVariant(variant) {
if (variant.match(/rgb\([\d*+\-i ]*, [\d*+\-i ]*, [\d*+\-i ]*\)/)) {
return "HSLColor.fromRGB(" + variant.substring(4, variant.length - 1).replace(/i/g, "tile.colorVariant") + ")";
}
if (variant.match(/hsl\([\d*+\-i ]*, [\d*+\-i ]*, [\d*+\-i ]*\)/)) {
return "new HSLColor(" + variant.substring(4, variant.length - 1).replace(/i/g, "tile.colorVariant") + ")";
}
throw new Error("Invalid color variant: " + variant);
}

const defaultTheme = {
territory: [],
border: [],
Expand Down
14 changes: 7 additions & 7 deletions src/map/GameMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class GameMap {
*/
calculateAreaMap(): void {
for (let i = 0; i < this.areaMap.length; i++) {
if (!this.areaMap[i] && this.getTile(i).isSolid) {
if (!this.areaMap[i] && this.getTile(i).conquerable) {
const stack: number[] = [i];
let stackPointer = 1;
let areaSize = 0;
Expand All @@ -76,10 +76,10 @@ export class GameMap {
if (this.areaMap[current]) continue;
this.areaMap[current] = this.areaSizes.length;
areaSize++;
if (current % this.width !== 0 && this.getTile(current - 1).isSolid) stack[stackPointer++] = current - 1;
if (current % this.width !== this.width - 1 && this.getTile(current + 1).isSolid) stack[stackPointer++] = current + 1;
if (current >= this.width && this.getTile(current - this.width).isSolid) stack[stackPointer++] = current - this.width;
if (current < this.tiles.length - this.width && this.getTile(current + this.width).isSolid) stack[stackPointer++] = current + this.width;
if (current % this.width !== 0 && this.getTile(current - 1).conquerable) stack[stackPointer++] = current - 1;
if (current % this.width !== this.width - 1 && this.getTile(current + 1).conquerable) stack[stackPointer++] = current + 1;
if (current >= this.width && this.getTile(current - this.width).conquerable) stack[stackPointer++] = current - this.width;
if (current < this.tiles.length - this.width && this.getTile(current + this.width).conquerable) stack[stackPointer++] = current + this.width;
}
this.areaSizes.push(areaSize);
}
Expand Down Expand Up @@ -132,7 +132,7 @@ export class GameMap {
* @private
*/
private initDistanceContext(index: number): DistanceContext {
if (this.getTile(index).isSolid) {
if (this.getTile(index).conquerable) {
return {distance: 2 ** 15 - 1, bias: 0, lastSolid: index};
}
return {distance: -1 * 2 ** 15, bias: 0, lastSolid: index};
Expand All @@ -145,7 +145,7 @@ export class GameMap {
* @private
*/
private updateDistanceContext(index: number, context: DistanceContext): void {
if (this.getTile(index).isSolid) {
if (this.getTile(index).conquerable) {
context.distance = Math.max(context.distance + 1, 0);
context.lastSolid = index;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/map/codec

0 comments on commit 6617ad7

Please sign in to comment.