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.
86 lines (85 loc) • 3.07 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 'reflect-metadata';
import { Expose, plainToClassFromExist, Transform, Type } from 'class-transformer';
import DAT from '../dat.js';
import Game from '../game.js';
import Header from './header.js';
/**
* Logiqx-schema DAT that documents {@link Game}s.
* @see http://www.logiqx.com/DatFAQs/DatCreation.php
*/
export default class LogiqxDAT extends DAT {
header;
game;
// NOTE(cemmer): this is not Logiqx DTD-compliant, but it's what pleasuredome Datfiles use
machine;
constructor(props) {
super(props);
this.header = props?.header;
this.game = props?.games;
this.generateGameNamesToParents();
}
/**
* Construct a {@link LogiqxDAT} from a generic object, such as one from reading an XML file.
*/
static fromObject(obj, props) {
// WARN(cemmer): plainToClassFromExist requires all class properties to be undefined, it will
// not overwrite properties with a defined value
const dat = new LogiqxDAT(props);
return plainToClassFromExist(dat, obj, {
enableImplicitConversion: true,
excludeExtraneousValues: true,
}).generateGameNamesToParents();
}
// Property getters
getHeader() {
return this.header ?? new Header();
}
getGames() {
if (Array.isArray(this.game)) {
if (this.game.length > 0) {
return this.game;
}
}
else if (this.game) {
return [this.game];
}
if (Array.isArray(this.machine)) {
if (this.machine.length > 0) {
return this.machine;
}
}
else if (this.machine) {
return [this.machine];
}
return [];
}
withGames(games) {
return new LogiqxDAT({ ...this, games });
}
}
__decorate([
Expose(),
Type(() => Header),
__metadata("design:type", Header)
], LogiqxDAT.prototype, "header", void 0);
__decorate([
Expose(),
Type(() => Game),
Transform(({ value }) => value ?? []),
__metadata("design:type", Object)
], LogiqxDAT.prototype, "game", void 0);
__decorate([
Expose(),
Type(() => Game),
Transform(({ value }) => value ?? []),
__metadata("design:type", Object)
], LogiqxDAT.prototype, "machine", void 0);