Skip to content

Commit

Permalink
[#29] Add support for sprite diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
allenkinzalow committed May 31, 2024
1 parent c3f1ae4 commit 8be0bcf
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-rings-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@osrs-wiki/cache-mediawiki": minor
---

Add support for Sprite diffs
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,5 @@ node_modules
.vscode/settings.json
.vscode/

./**/.DS_Store
./**/.DS_Store
.DS_Store
11 changes: 11 additions & 0 deletions src/scripts/differences/builder/builder.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
NPC,
Obj,
Param,
Sprites,
Struct,
} from "../../../utils/cache2";
import { PerFileLoadable } from "../../../utils/cache2/Loadable";
Expand All @@ -30,6 +31,7 @@ export type IndexFeatures =
| IndexFeature<NPC, "Npcs">
| IndexFeature<Obj, "Objects">
| IndexFeature<Param, "Params">
| IndexFeature<Sprites, "Sprites">
| IndexFeature<Struct, "Structs">;

export const resultNameMap: { [key in Difference]: string } = {
Expand Down Expand Up @@ -118,4 +120,13 @@ export const indexNameMap: {
},
},
},
[IndexType.Sprites]: {
name: "Sprites",
identifiers: ["id"],
fields: ["width", "height"],
urls: {
chisel: "",
abex: "https://abextm.github.io/cache2/#/viewer/sprite/",
},
},
};
37 changes: 18 additions & 19 deletions src/scripts/differences/differences.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mkdir, writeFile } from "fs/promises";

import differencesBuilder from "./builder";
import { indexNameMap } from "./builder/builder.types";
import {
ArchiveDifferences,
CacheDifferences,
Expand All @@ -13,12 +14,7 @@ import {
getCacheProviderGithub,
getCacheProviderLocal,
} from "../../utils/cache";
import {
FlatIndexData,
ArchiveData,
IndexType,
DiskIndexData,
} from "../../utils/cache2";
import { FlatIndexData, ArchiveData, DiskIndexData } from "../../utils/cache2";
import { LazyPromise } from "../../utils/cache2/LazyPromise";

/**
Expand All @@ -44,19 +40,22 @@ const differencesCache = async ({
).asPromise();

const cacheDifferences: CacheDifferences = {};
// TODO: Support more than index 2
for (let index = 0; index <= IndexType.Configs; index++) {
const oldIndex = await oldCache.getIndex(index);
const newIndex = await newCache.getIndex(index);
if (oldIndex.crc !== newIndex.crc) {
console.log(
`[Index=${index}] ${oldIndex.revision} -> ${newIndex.revision}`
);
cacheDifferences[index] = differencesIndex(oldIndex, newIndex);
} else {
console.log(`No changes in index ${index}.`);
}
}
await Promise.all(
Object.keys(indexNameMap).map(async (indexString) => {
const index = parseInt(indexString);
console.log(`Checking index ${index} differences`);
const oldIndex = await oldCache.getIndex(index);
const newIndex = await newCache.getIndex(index);
if (oldIndex.crc !== newIndex.crc) {
console.log(
`[Index=${index}] ${oldIndex.revision} -> ${newIndex.revision}`
);
cacheDifferences[index] = differencesIndex(oldIndex, newIndex);
} else {
console.log(`No changes in index ${index}.`);
}
})
);

const builder = differencesBuilder(cacheDifferences);
const dir = `./out/differences`;
Expand Down
31 changes: 31 additions & 0 deletions src/scripts/differences/file/content/sprites.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import _ from "underscore";

Check warning on line 1 in src/scripts/differences/file/content/sprites.ts

View workflow job for this annotation

GitHub Actions / Lint, Built, & Test / Lint, Built, & Test

'_' is defined but never used

import { Reader, SpriteID, Sprites } from "../../../../utils/cache2";
import { CompareFn } from "../../differences.types";
import { getFileDifferences } from "../file.utils";

const compareSprites: CompareFn = ({ oldFile, newFile }) => {
const oldEntry = oldFile
? Sprites.decode(
new Reader(oldFile.file.data, {
era: "osrs",
indexRevision: oldFile.index.revision,
}),
<SpriteID>oldFile.archive.archive
)
: undefined;

const newEntry = newFile
? Sprites.decode(
new Reader(newFile.file.data, {
era: "osrs",
indexRevision: newFile.index.revision,
}),
<SpriteID>newFile.archive.archive
)
: undefined;

return getFileDifferences(oldEntry, newEntry);
};

export default compareSprites;
2 changes: 2 additions & 0 deletions src/scripts/differences/file/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import compareItems from "./content/items";
import compareNpcs from "./content/npcs";
import compareObjects from "./content/objects";
import compareParams from "./content/params";
import compareSprites from "./content/sprites";
import compareStructs from "./content/struct";
import { ConfigType, IndexType } from "../../../utils/cache2";
import { CompareFn, FileDifferences } from "../differences.types";
Expand All @@ -23,6 +24,7 @@ const indexMap: {
[ConfigType.Params]: compareParams,
[ConfigType.Struct]: compareStructs,
},
[IndexType.Sprites]: compareSprites,
};

/**
Expand Down

0 comments on commit 8be0bcf

Please sign in to comment.