-
-
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(Star Map): Add the APIs for adding, removing, and updating solar…
… system plugins. Refs #173
- Loading branch information
1 parent
febab2c
commit f469d69
Showing
5 changed files
with
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import SolarSystemPlugin from "server/src/classes/Plugins/Universe/SolarSystem"; | ||
import {DataContext} from "server/src/utils/DataContext"; | ||
import {pubsub} from "server/src/utils/pubsub"; | ||
import {AstronomicalUnit, LightMinute} from "server/src/utils/unitTypes"; | ||
import {getPlugin} from "./utils"; | ||
|
||
export const solarSystemsPluginInputs = { | ||
pluginSolarSystemCreate( | ||
context: DataContext, | ||
params: { | ||
pluginId: string; | ||
position: { | ||
x: LightMinute; | ||
y: LightMinute; | ||
z: LightMinute; | ||
}; | ||
} | ||
) { | ||
const plugin = getPlugin(context, params.pluginId); | ||
const solarSystem = new SolarSystemPlugin( | ||
{position: params.position}, | ||
plugin | ||
); | ||
plugin.aspects.solarSystems.push(solarSystem); | ||
|
||
pubsub.publish("pluginSolarSystems", {pluginId: params.pluginId}); | ||
|
||
return {solarSystemId: solarSystem.name}; | ||
}, | ||
async pluginSolarSystemDelete( | ||
context: DataContext, | ||
params: { | ||
pluginId: string; | ||
solarSystemId: string; | ||
} | ||
) { | ||
const plugin = getPlugin(context, params.pluginId); | ||
const solarSystem = plugin.aspects.solarSystems.find( | ||
solarSystem => solarSystem.name === params.solarSystemId | ||
); | ||
if (!solarSystem) return; | ||
plugin.aspects.solarSystems.splice( | ||
plugin.aspects.solarSystems.indexOf(solarSystem), | ||
1 | ||
); | ||
|
||
await solarSystem?.removeFile(); | ||
pubsub.publish("pluginShips", {pluginId: params.pluginId}); | ||
}, | ||
async pluginSolarSystemUpdate( | ||
context: DataContext, | ||
params: { | ||
pluginId: string; | ||
solarSystemId: string; | ||
position?: { | ||
x: LightMinute; | ||
y: LightMinute; | ||
z: LightMinute; | ||
}; | ||
name?: string; | ||
description?: string; | ||
tags?: string[]; | ||
habitableZoneInner?: AstronomicalUnit; | ||
habitableZoneOuter?: AstronomicalUnit; | ||
skyboxKey?: string; | ||
} | ||
) { | ||
const plugin = getPlugin(context, params.pluginId); | ||
if (!params.solarSystemId) throw new Error("Solar System ID is required"); | ||
const solarSystem = plugin.aspects.solarSystems.find( | ||
solarSystem => solarSystem.name === params.solarSystemId | ||
); | ||
if (!solarSystem) return {solarSystemId: ""}; | ||
if (params.position) solarSystem.position = params.position; | ||
if (params.name) solarSystem.name = params.name; | ||
if (params.description) solarSystem.description = params.description; | ||
if (params.tags) solarSystem.tags = params.tags; | ||
if (params.habitableZoneInner) | ||
solarSystem.habitableZoneInner = params.habitableZoneInner; | ||
if (params.habitableZoneOuter) | ||
solarSystem.habitableZoneOuter = params.habitableZoneOuter; | ||
if (params.skyboxKey) solarSystem.skyboxKey = params.skyboxKey; | ||
|
||
pubsub.publish("pluginSolarSystems", {pluginId: params.pluginId}); | ||
pubsub.publish("pluginSolarSystem", { | ||
pluginId: params.pluginId, | ||
solarSystemId: solarSystem.name, | ||
}); | ||
return {solarSystemId: solarSystem.name}; | ||
}, | ||
}; |
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,27 @@ | ||
import {DataContext} from "server/src/utils/DataContext"; | ||
import {getPlugin} from "./utils"; | ||
|
||
export const pluginSolarSystemsRequest = { | ||
pluginSolarSystems( | ||
context: DataContext, | ||
params: {pluginId: string}, | ||
publishParams: {pluginId: string} | null | ||
) { | ||
if (publishParams && params.pluginId !== publishParams.pluginId) throw null; | ||
const plugin = getPlugin(context, params.pluginId); | ||
return plugin.aspects.solarSystems; | ||
}, | ||
pluginSolarSystem( | ||
context: DataContext, | ||
params: {pluginId: string; solarSystemId: string}, | ||
publishParams: {pluginId: string; solarSystemId: string} | null | ||
) { | ||
if (publishParams && params.pluginId !== publishParams.pluginId) throw null; | ||
const plugin = getPlugin(context, params.pluginId); | ||
const solarSystem = plugin.aspects.solarSystems.find( | ||
solarSystem => solarSystem.name === params.solarSystemId | ||
); | ||
if (!solarSystem) throw null; | ||
return solarSystem; | ||
}, | ||
}; |