igir
Version:
🕹 A zero-setup ROM collection manager that sorts, filters, extracts or archives, patches, and reports on collections of any size on any OS.
69 lines (68 loc) • 2.71 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Memoize } from 'typescript-memoize';
/**
* A container holding a {@link Game}, optionally a {@link Release} for that {@link Game}, and a
* {@link ROMWithFiles} with input and output {@link File} information for every {@link ROM}.
* In other words, a {@link WriteCandidate} will only exist if every {@link ROM} of a {@link Game}
* has been found.
*/
export default class WriteCandidate {
game;
romsWithFiles;
constructor(game, romsWithFiles) {
this.game = game;
this.romsWithFiles = romsWithFiles;
}
// Property getters
getGame() {
return this.game;
}
getRomsWithFiles() {
return this.romsWithFiles;
}
// Computed getters
getName() {
return this.game.getName();
}
/**
* Returns true if any {@link ROMWithFiles} input {@link File} has a {@link Patch} attached to it.
*/
isPatched() {
return this.getRomsWithFiles().some((romWithFiles) => romWithFiles.getInputFile().getPatch() !== undefined);
}
// Immutable setters
withRomsWithFiles(romsWithFiles) {
if (romsWithFiles === this.romsWithFiles ||
(romsWithFiles.length === this.romsWithFiles.length &&
romsWithFiles.every((rwf, idx) => this.romsWithFiles[idx] === rwf))) {
return this;
}
return new WriteCandidate(this.game, romsWithFiles);
}
// Pseudo Built-Ins
/**
* A string hash code to uniquely identify this {@link WriteCandidate}.
*/
hashCode() {
let hashCode = this.game.hashCode();
hashCode += `|${this.romsWithFiles
.map((romWithFiles) => romWithFiles.hashCode())
.sort()
.join(',')}`;
return hashCode;
}
}
__decorate([
Memoize(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", String)
], WriteCandidate.prototype, "hashCode", null);