-
-
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(Ship Map): Initializes the ship map on the player ship when the …
…flight starts. Closes #246
- Loading branch information
1 parent
f94f407
commit cc83b62
Showing
7 changed files
with
63 additions
and
3 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
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,42 @@ | ||
import DeckPlugin, {DeckEdge} from "../classes/Plugins/Ship/Deck"; | ||
import {Component} from "./utils"; | ||
|
||
const roundTo1000 = (num: number) => Math.round(num * 1000) / 1000; | ||
export class ShipMapComponent extends Component { | ||
static id = "shipMap" as const; | ||
static serialize(data: ShipMapComponent) { | ||
return { | ||
decks: data.decks.map(deck => ({ | ||
...deck, | ||
nodes: deck.nodes.map( | ||
({flags, icon, id, isRoom, name, radius, x, y}) => { | ||
const output: Partial<DeckPlugin["nodes"][0]> = { | ||
id, | ||
x: roundTo1000(x), | ||
y: roundTo1000(y), | ||
}; | ||
if (name) output.name = name; | ||
if (icon) output.icon = icon; | ||
if (isRoom) output.isRoom = isRoom; | ||
if (radius) output.radius = radius; | ||
if (flags?.length > 0) output.flags = flags; | ||
return output; | ||
} | ||
), | ||
})), | ||
deckEdges: data.deckEdges.map(({id, flags, from, to, isOpen, weight}) => { | ||
const output: Partial<DeckEdge> = { | ||
id, | ||
from, | ||
to, | ||
}; | ||
if (weight) output.weight = weight; | ||
if (!isOpen) output.isOpen = isOpen; | ||
if (flags?.length > 0) output.flags = flags; | ||
return output; | ||
}), | ||
}; | ||
} | ||
decks: DeckPlugin[] = []; | ||
deckEdges: DeckEdge[] = []; | ||
} |
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