Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions _templates/material/new/material.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
to: ogl-engine/materials/<%= name %>/<%= name %>.ts
---

interface <%= h.capitalize(name) %>MaterialArgs {

}

import type { Engine3D } from "@ogl-engine/engine/engine3d";
import fragment from "./shader.frag.glsl";
import vertex from "./shader.vert.glsl";
import { Material } from "../material";

interface <%= h.capitalize(name) %>MaterialArgs {

}

export class <%= h.capitalize(name) %>Material extends Material {
uniforms: Material["uniforms"] & {

Expand Down
Binary file added assets/textures/skybox/deepspace1/back.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/skybox/deepspace1/bottom.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/skybox/deepspace1/front.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions assets/textures/skybox/deepspace1/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import back from "./back.webp";
import front from "./front.webp";
import bottom from "./bottom.webp";
import top from "./top.webp";
import left from "./left.webp";
import right from "./right.webp";

export const deepspace1 = {
back,
front,
bottom,
top,
left,
right,
};
Binary file added assets/textures/skybox/deepspace1/left.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/skybox/deepspace1/right.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/skybox/deepspace1/top.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions assets/textures/skybox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { sectoralpha } from "./sectoralpha";
import { teegarden1 } from "./teegarden1";
import { teegarden2 } from "./teegarden2";
import { gaia } from "./gaia";
import { deepspace1 } from "./deepspace1";

export const skyboxes = {
example,
Expand All @@ -12,5 +13,6 @@ export const skyboxes = {
teegarden1,
teegarden2,
gaia,
deepspace1,
};
export type SkyboxTexture = keyof typeof skyboxes;
7 changes: 1 addition & 6 deletions core/archetypes/asteroidField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ export const fieldColors = {
silica: "#ededed",
} as Record<MineableCommodity, string>;

export const asteroidFieldComponents = [
"mineable",
"children",
"position",
] as const;
export const asteroidFieldComponents = ["mineable", "position"] as const;

export type AsteroidFieldComponent = (typeof asteroidFieldComponents)[number];
export type AsteroidField = RequireComponent<AsteroidFieldComponent>;
Expand Down Expand Up @@ -111,7 +107,6 @@ export function createAsteroidField(
getFPoints(data.size)
)
)
.addComponent({ name: "children", entities: [] })
.addComponent({
name: "position",
coord: position,
Expand Down
42 changes: 39 additions & 3 deletions core/archetypes/facilityModule.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import type { Commodity } from "@core/economy/commodity";
import { fromEntries, pipe, map } from "@fxts/core";
import type { Damage } from "@core/components/damage";
import { fromPolar } from "@core/utils/misc";
import { findInAncestors } from "@core/utils/findInAncestors";
import { Entity } from "../entity";
import type { PAC } from "../components/production";
import { createProduction } from "../components/production";
import type { Sim } from "../sim";
import type { RequireComponent } from "../tsHelpers";
import modules from "../world/data/facilityModules.json";
import { createTurret } from "./turret";

export interface FacilityModuleCommonInput {
name: string;
Expand Down Expand Up @@ -104,10 +107,43 @@ export function createFacilityModule(
});
} else if (input.type === "military") {
entity.addComponent({
...input.damage,
name: "damage",
targetId: null,
name: "children",
entities: [],
slots: Array(4)
.fill(0)
.map((_, i) => ({
angle: (i * Math.PI) / 2,
slug: `turret-${i}`,
})),
});
const turrets = Array(4)
.fill(0)
.map((_, i) =>
createTurret(sim, {
slug: "rapidKinetic",
angle: (i * Math.PI) / 2,
damage: {
angle: Math.PI / 2,
},
slot: `turret-${i}`,
parentId: entity.id,
transform: {
coord: fromPolar((i * Math.PI) / 2, 0.01),
angle: (i * Math.PI) / 2,
world: {
coord: findInAncestors(input.parent, "position")
.cp.position.coord.clone()
.add(fromPolar((i * Math.PI) / 2, 0.01)),
angle: (i * Math.PI) / 2,
},
},
})
);
entity.cp.children!.entities = turrets.map((turret, turretIndex) => ({
id: turret.id,
role: "turret",
slot: `turret-${turretIndex}`,
}));
}
if (input.crew.cost > 0) {
entity.addComponent({
Expand Down
61 changes: 50 additions & 11 deletions core/archetypes/ship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import pick from "lodash/pick";
import type { DockSize } from "@core/components/dockable";
import { createDocks } from "@core/components/dockable";
import { Vec2 } from "ogl";
import { random } from "mathjs";
import { applyParentTransform } from "@core/systems/moving";
import { createDrive } from "../components/drive";
import { Entity } from "../entity";
import { createMining } from "../components/mining";
Expand All @@ -13,6 +15,7 @@ import type { RequireComponent } from "../tsHelpers";
import type { Sector } from "./sector";
import type { Faction } from "./faction";
import type { ShipInput } from "../world/ships";
import { createTurret } from "./turret";

export const shipComponents = [
"autoOrder",
Expand All @@ -29,6 +32,7 @@ export const shipComponents = [
"model",
"subordinates",
"experience",
"children",
] as const;

export type ShipComponent = (typeof shipComponents)[number];
Expand Down Expand Up @@ -66,7 +70,7 @@ export function createShipName(
}

export function createShip(sim: Sim, initial: InitialShipInput): Ship {
const entity = new Entity(sim);
const entity = new Entity(sim) as Ship;

entity
.addComponent({
Expand Down Expand Up @@ -132,16 +136,6 @@ export function createShip(sim: Sim, initial: InitialShipInput): Ship {
},
hitBy: {},
})
.addComponent({
...initial.damage,
name: "damage",
targetId: null,
output: {
base: initial.damage.value,
current: initial.damage.value,
},
modifiers: {},
})
.addComponent({
name: "model",
slug: initial.slug,
Expand All @@ -157,10 +151,41 @@ export function createShip(sim: Sim, initial: InitialShipInput): Ship {
rank: 1,
amount: 0,
})
.addComponent({
name: "children",
entities: [],
slots: initial.slots,
})
.addTag("selection")
.addTag("ship")
.addTag(`role:${initial.role}`);

for (const turretInput of initial.turrets) {
const slot = entity.cp.children.slots.find(
({ slug }) => slug === turretInput.slot
);
const slotPosition = new Vec2(random(-4e-2, 4e-2), random(-4e-2, 4e-2));

const turret = createTurret(sim, {
slug: turretInput.class,
angle: slot!.angle,
damage: {
angle: turretInput.angle,
},
slot: turretInput.slot,
parentId: entity.id,
transform: {
coord: slotPosition.clone(),
angle: slot!.angle,
world: {
coord: new Vec2(),
angle: slot!.angle,
},
},
});
applyParentTransform(turret, entity.cp.position);
}

if (initial.mining) {
entity.addComponent(createMining(initial.mining));
}
Expand All @@ -183,6 +208,20 @@ export function createShip(sim: Sim, initial: InitialShipInput): Ship {
});
}

// if (initial.damage) {
// entity.addComponent({
// ...initial.damage,
// name: "damage",
// targetId: null,
// output: {
// base: initial.damage.value,
// current: initial.damage.value,
// },
// modifiers: {},
// type: "kinetic",
// });
// }

if (initial.docks) {
entity.addComponent(createDocks(initial.docks));
}
Expand Down
74 changes: 74 additions & 0 deletions core/archetypes/turret.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import type { Sim } from "@core/sim";
import { Entity } from "@core/entity";
import type { Transform } from "@core/components/transform";
import { attach } from "@core/components/children";
import { getTurretBySlug } from "@core/world/turrets";
import { MissingComponentError } from "../errors";
import type { RequireComponent } from "../tsHelpers";

export const turretComponents = [
"damage",
"color",
"transform",
"parent",
] as const;

export type TurretComponent = (typeof turretComponents)[number];
export type Turret = RequireComponent<TurretComponent>;

export function turret(entity: Entity): Turret {
if (!entity.hasComponents(turretComponents)) {
throw new MissingComponentError(entity, turretComponents);
}

return entity as Turret;
}

export interface TurretInput {
angle: number;
parentId: number;
transform: Omit<Transform, "name">;
slot: string;
slug: string;
damage: {
angle: number;
};
}

export function createTurret(sim: Sim, input: TurretInput) {
const entity = new Entity(sim) as Turret;
const parent = sim.getOrThrow(input.parentId).requireComponents(["children"]);
const turretInfo = getTurretBySlug(input.slug)!;

entity
.addComponent({
angle: input.damage.angle,
cooldown: turretInfo.cooldown,
range: turretInfo.range,
name: "damage",
targetId: null,
output: {
base: turretInfo.damage,
current: turretInfo.damage,
},
modifiers: {},
type: turretInfo.type,
})
.addComponent({
name: "color",
value: turretInfo.color,
})
.addComponent({
name: "transform",
angle: input.angle,
coord: input.transform.coord,
world: {
angle: input.angle,
coord: input.transform.coord.clone(),
},
});

attach(entity, parent, input.slot, "turret");

return entity as Turret;
}
49 changes: 48 additions & 1 deletion core/components/children.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
import type { RequireComponent } from "@core/tsHelpers";
import { applyParentTransform } from "@core/systems/moving";
import type { Entity } from "@core/entity";
import { componentLogger } from "@core/log";
import type { BaseComponent } from "./component";

export type ChildRole = "turret";
export interface Children extends BaseComponent<"children"> {
entities: number[];
slots: Array<{ slug: string; angle: number }>;
entities: Array<{
role: ChildRole;
id: number;
slot: string;
}>;
}

export function attach(
child: Entity,
parent: RequireComponent<"children">,
slot: string,
role: ChildRole
) {
if (!parent.cp.children.slots.some(({ slug }) => slug === slot)) {
throw new Error(`Slot ${slot} does not exist on parent entity`);
}

if (!child.hasComponents(["parent"])) {
child.addComponent({
name: "parent",
id: parent.id,
});
} else {
componentLogger.log(
`Entity ${child.id} already has a parent, replacing with new parent ${parent.id}`,
"warn"
);
child.cp.parent.id = parent.id;
}

parent.cp.children.entities.push({
id: child.id,
role,
slot,
});

if (
child.hasComponents(["transform"]) &&
parent.hasComponents(["position"])
) {
applyParentTransform(child, parent.cp.position);
}
}
2 changes: 2 additions & 0 deletions core/components/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import type { Movable } from "./movable";
import type { StorageTransfer } from "./storageTransfer";
import type { Policies } from "./policies";
import type { Experience } from "./experience";
import type { Transform } from "./transform";

export interface CoreComponents {
ai: Ai;
Expand Down Expand Up @@ -102,6 +103,7 @@ export interface CoreComponents {
systemManager: SystemManager;
teleport: Teleport;
trade: Trade;
transform: Transform;
}

/**
Expand Down
Loading
Loading