-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Stations): Create the necessary scaffolding for a station comple…
…ment plugin aspect. This is necessary so assets can be included with stations, including station logos and card icons. It opens the possibility of folks creating custom station sets in the future, but we won't build any APIs or UIs for that right now. Closes #87 * Add automated tests for the Station Complement plugin aspect * Fix test
- Loading branch information
1 parent
8b5b58a
commit 3b02377
Showing
6 changed files
with
121 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import StationComplementPlugin from "./StationComplement"; | ||
import Plugin from "./index"; | ||
import {ServerDataModel} from "../ServerDataModel"; | ||
import {promises as fs} from "fs"; | ||
import path from "path"; | ||
const testYaml = `apiVersion: "stations/v1" | ||
kind: "stations" | ||
name: "Test Station" | ||
hasShipMap: false | ||
stations: | ||
- name: Pilot | ||
description: A single player position that controls all aspects of the ship. | ||
logo: Pilot.svg | ||
cards: | ||
- name: Pilot | ||
component: Pilot | ||
`; | ||
describe("StationComplementPlugin", () => { | ||
afterAll(async () => { | ||
await fs.rm("./plugins", {recursive: true}); | ||
}); | ||
it("should instantiate correctly", async () => { | ||
const plugin = new Plugin({}, {plugins: []} as unknown as ServerDataModel); | ||
const stationComplement = new StationComplementPlugin({}, plugin); | ||
expect(stationComplement).toBeInstanceOf(StationComplementPlugin); | ||
expect(stationComplement.name).toBe("New Station Complement"); | ||
expect(stationComplement.stationCount).toBe(0); | ||
}); | ||
it("should load test yaml", async () => { | ||
const plugin = new Plugin({name: "Test Plugin"}, { | ||
plugins: [], | ||
} as unknown as ServerDataModel); | ||
await plugin.writeFile(true); | ||
await fs.mkdir( | ||
path.resolve( | ||
path.join(".", plugin.path, "../stationComplements/Test Station") | ||
), | ||
{recursive: true} | ||
); | ||
await fs.writeFile( | ||
path.resolve( | ||
path.join( | ||
".", | ||
plugin.path, | ||
"../stationComplements/Test Station/manifest.yml" | ||
) | ||
), | ||
testYaml | ||
); | ||
const stationComplement = new StationComplementPlugin( | ||
{name: "Test Station"}, | ||
plugin | ||
); | ||
expect(stationComplement.name).toBe("Test Station"); | ||
expect(stationComplement.stationCount).toBe(1); | ||
expect(stationComplement.stations[0].name).toBe("Pilot"); | ||
expect(stationComplement.assets["Pilot-logo"]).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import {generateIncrementedName} from "server/src/utils/generateIncrementedName"; | ||
import BasePlugin from "."; | ||
import Station from "../Station"; | ||
import {Aspect} from "./Aspect"; | ||
|
||
export default class StationComplementPlugin extends Aspect { | ||
apiVersion = "stations/v1" as const; | ||
kind = "stationComplements" as const; | ||
name!: string; | ||
hasShipMap!: boolean; | ||
stations!: Station[]; | ||
get stationCount() { | ||
return this.stations.length; | ||
} | ||
assets!: Record<string, string>; | ||
constructor(params: Partial<StationComplementPlugin>, plugin: BasePlugin) { | ||
const name = generateIncrementedName( | ||
params.name || "New Station Complement", | ||
plugin.aspects.stationComplements.map(station => station.name) | ||
); | ||
super({name, ...params}, {kind: "stationComplements"}, plugin); | ||
|
||
this.stations = this.stations || params.stations || []; | ||
this.hasShipMap = this.hasShipMap || params.hasShipMap || false; | ||
this.assets = this.assets || params.assets || {}; | ||
|
||
this.assets = this.stations.reduce((assets, station) => { | ||
const cardIcons = station.cards.reduce( | ||
(icons: Record<string, string>, card) => { | ||
if (card.icon) { | ||
icons[`${station.name}-${card.name}-icon`] = card.icon; | ||
} | ||
return icons; | ||
}, | ||
{} | ||
); | ||
|
||
return { | ||
...assets, | ||
[`${station.name}-logo`]: station.logo, | ||
...cardIcons, | ||
}; | ||
}, {}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters