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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import childProcess from "child_process"; import Path from "path"; import { checksumFile, checksumString } from "lib/helpers/checksum"; import { readFile, ensureDir, pathExists, writeFile, unlink } from "fs-extra"; import ensureBuildTools from "./ensureBuildTools"; import { exportToC, loadUGESong } from "shared/lib/uge/ugeHelper"; import { assetFilename } from "shared/lib/helpers/assets"; export interface PrecompiledMusicTrack { id: string; name: string; dataName: string; filename: string; settings: { disableSpeedConversion?: boolean; }; } interface CompileMusicOptions { tmpPath: string; projectRoot: string; engine: "gbt" | "huge"; output: Record<string, string>; progress: (msg: string) => void; warnings: (msg: string) => void; } interface CompileModTrackOptions { projectRoot: string; buildToolsPath: string; buildToolsVersion: string; cacheRoot: string; progress: (msg: string) => void; warnings: (msg: string) => void; } interface CompileHugeTrackOptions { projectRoot: string; buildToolsPath: string; buildToolsVersion: string; cacheRoot: string; progress: (msg: string) => void; warnings: (msg: string) => void; } const compileModTrack = async ( track: PrecompiledMusicTrack, { projectRoot, buildToolsPath, buildToolsVersion, cacheRoot, progress = (_msg) => {}, warnings = (_msg) => {}, }: CompileModTrackOptions ): Promise<string> => { const env = { ...process.env }; env.PATH = [Path.join(buildToolsPath, "mod2gbt"), env.PATH ?? env.Path].join( Path.delimiter ); const command = process.platform === "win32" ? `"${buildToolsPath}\\mod2gbt\\mod2gbt.exe"` : "mod2gbt"; const modPath = assetFilename(projectRoot, "music", track); const checksum = await checksumFile(modPath); const buildChecksum = checksumString( checksum + buildToolsVersion + JSON.stringify(track.settings) ); const cachedFilePath = `${cacheRoot}/${buildChecksum}`; Iif (await pathExists(cachedFilePath)) { return readFile(cachedFilePath, "utf8"); } const outputFile = "output.c"; const tmpFilePath = `${cacheRoot}/${outputFile}`; const args = [`"${modPath}"`, "MUSICTRACKNAME", "255"]; Iif (track.settings.disableSpeedConversion) { args.push("-speed"); } progress(`${command} ${args.join(" ")}`); const options = { cwd: cacheRoot, env, shell: true, }; await new Promise<void>((resolve, reject) => { const child = childProcess.spawn(command, args, options); child.on("error", (err) => { warnings(err.toString()); }); child.stdout.on("data", (data) => { const lines = data.toString().split("\n"); lines.forEach((line: string) => { progress(line); }); }); child.stderr.on("data", (data) => { const lines = data.toString().split("\n"); lines.forEach((line: string) => { warnings(line); }); }); child.on("close", (code) => { if (code === 0) resolve(); else reject(code); }); }); const output = (await readFile(tmpFilePath, "utf8")).replace( /#pragma bank=255/, `#pragma bank 255\n\n#include "gbs_types.h"\n\nBANKREF(MUSICTRACKNAME_Data)\n` ); await writeFile(cachedFilePath, output); await unlink(tmpFilePath); return output; }; const compileModTracks = async ( tracks: PrecompiledMusicTrack[], { tmpPath, projectRoot, output, progress = (_msg) => {}, warnings = (_msg) => {}, }: CompileMusicOptions ): Promise<void> => { const buildToolsPath = await ensureBuildTools(tmpPath); const cacheRoot = Path.normalize(`${tmpPath}/_gbscache/music`); ensureDir(cacheRoot); const buildToolsVersion = await readFile( `${buildToolsPath}/tools_version`, "utf8" ); for (const track of tracks) { const fileData = await compileModTrack(track, { projectRoot, buildToolsPath, buildToolsVersion, cacheRoot, progress, warnings, }); output[`music/${track.dataName}_Data.c`] = fileData.replace( /MUSICTRACKNAME/g, track.dataName ); } }; const compileUgeTrack = async ( track: PrecompiledMusicTrack, { projectRoot }: CompileHugeTrackOptions ): Promise<string> => { const ugePath = assetFilename(projectRoot, "music", track); const data = await readFile(ugePath); const song = loadUGESong(new Uint8Array(data).buffer); if (song) { return exportToC(song, track.dataName); } else { return "// No song found"; } }; const compileUgeTracks = async ( tracks: PrecompiledMusicTrack[], { tmpPath, projectRoot, output, progress = (_msg) => {}, warnings = (_msg) => {}, }: CompileMusicOptions ): Promise<void> => { const buildToolsPath = await ensureBuildTools(tmpPath); const cacheRoot = Path.normalize(`${tmpPath}/_gbscache/music`); ensureDir(cacheRoot); const buildToolsVersion = await readFile( `${buildToolsPath}/tools_version`, "utf8" ); for (const track of tracks) { output[`music/${track.dataName}_Data.c`] = await compileUgeTrack(track, { projectRoot, buildToolsPath, buildToolsVersion, cacheRoot, progress, warnings, }); } }; export const compileMusicHeader = (tracks: PrecompiledMusicTrack[]) => { return `#ifndef MUSIC_DATA_H #define MUSIC_DATA_H ${tracks .map( (track) => `extern const void __bank_${track.dataName}_Data; extern const void ${track.dataName}_Data;` ) .join("\n")} #endif `; }; export const compileMusicTracks = ( tracks: PrecompiledMusicTrack[], options: CompileMusicOptions ) => { Iif (options.engine === "gbt") { return compileModTracks(tracks, options); } else { return compileUgeTracks(tracks, options); } }; |