Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | 5x 5x 5x 5x 5x 15x 3x 12x 37x 6x 6x 5x 7x 5x 15x 2x 13x 13x 13x 3x 10x 10x 1x 9x 9x 9x 9x 9x 5x 4x 4x 2x 2x 2x 1x 1x 5x 8x 8x 7x 7x 1x 6x 8x | import type { BuildUsageSource } from "lib/compiler/buildUsage";
export type BuildAssetType =
"scene" | "sprite" | "background" | "music" | "sound";
export type BuildAssetSourceType =
| "data"
| "actors"
| "collisions"
| "triggers"
| "sprites"
| "projectiles"
| "tileset"
| "cgbTileset"
| "tilemap"
| "tilemapAttr";
export type KnownAssetSymbols = {
scenes: ReadonlySet<string>;
sprites: ReadonlySet<string>;
backgrounds: ReadonlySet<string>;
};
export type BuildAssetMatch = {
type: BuildAssetType;
symbol: string;
};
export type BuildAssetSourceMatch = BuildAssetMatch & {
sourceType: BuildAssetSourceType;
};
const DATA_PREFIX = "src/data/";
const SCENE_SUFFIXES: [string, BuildAssetSourceType][] = [
["_actors", "actors"],
["_collisions", "collisions"],
["_triggers", "triggers"],
["_sprites", "sprites"],
["_projectiles", "projectiles"],
];
const SPRITE_SUFFIXES: [string, BuildAssetSourceType][] = [
["_tileset", "tileset"],
["_bank2_tileset", "cgbTileset"],
];
const BACKGROUND_SUFFIXES: [string, BuildAssetSourceType][] = [
["_tileset", "tileset"],
["_cgb_tileset", "cgbTileset"],
["_tilemap", "tilemap"],
["_tilemap_attr", "tilemapAttr"],
];
const matchSymbol = (
base: string,
knownSymbols: ReadonlySet<string>,
suffixes: [string, BuildAssetSourceType][],
): Pick<BuildAssetSourceMatch, "symbol" | "sourceType"> | undefined => {
if (knownSymbols.has(base)) {
return { symbol: base, sourceType: "data" };
}
for (const [suffix, sourceType] of suffixes) {
if (base.endsWith(suffix)) {
const candidate = base.slice(0, base.length - suffix.length);
if (knownSymbols.has(candidate)) {
return { symbol: candidate, sourceType };
}
}
}
return undefined;
};
export const matchBuildAssetSource = (
sourceFile: string,
knownSymbols: KnownAssetSymbols,
): BuildAssetSourceMatch | undefined => {
if (!sourceFile.startsWith(DATA_PREFIX)) {
return undefined;
}
const rest = sourceFile.slice(DATA_PREFIX.length);
const musicMatch = /^music\/(.+)_Data\.c$/.exec(rest);
if (musicMatch) {
return { type: "music", symbol: musicMatch[1], sourceType: "data" };
}
const soundMatch = /^sounds\/(.+)\.c$/.exec(rest);
if (soundMatch) {
return { type: "sound", symbol: soundMatch[1], sourceType: "data" };
}
const baseMatch = /^([^/]+)\.c$/.exec(rest);
Iif (!baseMatch) {
return undefined;
}
const base = baseMatch[1];
const sceneSymbol = matchSymbol(base, knownSymbols.scenes, SCENE_SUFFIXES);
if (sceneSymbol) {
return { type: "scene", ...sceneSymbol };
}
const spriteSymbol = matchSymbol(base, knownSymbols.sprites, SPRITE_SUFFIXES);
if (spriteSymbol) {
return { type: "sprite", ...spriteSymbol };
}
const backgroundSymbol = matchSymbol(
base,
knownSymbols.backgrounds,
BACKGROUND_SUFFIXES,
);
if (backgroundSymbol) {
return { type: "background", ...backgroundSymbol };
}
return undefined;
};
export type BuildAssetUsageRow = {
type: BuildAssetType;
symbol: string;
sourceType: BuildAssetSourceType;
rom: number;
sourceFile: string;
};
export const buildAssetUsageRows = (
sources: BuildUsageSource[],
knownSymbols: KnownAssetSymbols,
): BuildAssetUsageRow[] => {
const rows: BuildAssetUsageRow[] = [];
for (const source of sources) {
const match = matchBuildAssetSource(source.sourceFile, knownSymbols);
if (!match) {
continue;
}
rows.push({
type: match.type,
symbol: match.symbol,
sourceType: match.sourceType,
rom: source.usage.bank0 + source.usage.bankedRom,
sourceFile: source.sourceFile,
});
}
return rows;
};
|