~starkingdoms/starkingdoms

fcf6f8d9e77eadc5a90d144379c8fc7a5cca4040 — ghostlyzsh 1 year, 11 months ago b7300c2
red planet and red planet with hubs
M server/src/component.rs => server/src/component.rs +1 -0
@@ 22,6 22,7 @@ use serde::{Deserialize, Serialize};
pub enum PlanetType {
    Earth,
    Moon,
    Mars,
}

#[derive(Component, Clone, Copy, PartialEq, Serialize, Deserialize, Debug)]

M server/src/main.rs => server/src/main.rs +20 -1
@@ 35,9 35,11 @@ const SCALE: f32 = 10.0;

const EARTH_SIZE: f32 = 1000.0;
const MOON_SIZE: f32 = EARTH_SIZE / 4.;
const MARS_SIZE: f32 = EARTH_SIZE / 2.;

const EARTH_MASS: f32 = 10000.0;
const MOON_MASS: f32 = EARTH_MASS / 30.;
const MARS_MASS: f32 = EARTH_MASS / 8.;

const GRAVITY: f32 = 0.02;
const PART_HALF_SIZE: f32 = 25.0;


@@ 117,6 119,21 @@ fn spawn_planets(mut commands: Commands) {
                .insert(Sensor);
        })
        .insert(RigidBody::Fixed);
    let mars_pos = Transform::from_xyz(-3000.0 / SCALE, 0.0, 0.0);
    commands
        .spawn(PlanetBundle {
            planet_type: PlanetType::Mars,
            transform: TransformBundle::from(mars_pos),
        })
        .insert(Collider::ball(MARS_SIZE / SCALE))
        .insert(AdditionalMassProperties::Mass(MARS_MASS))
        .insert(ReadMassProperties::default())
        .with_children(|children| {
            children.spawn(Collider::ball((MARS_SIZE + 3.) / SCALE))
                .insert(ActiveEvents::COLLISION_EVENTS)
                .insert(Sensor);
        })
        .insert(RigidBody::Fixed);
}
fn module_spawn(
    mut commands: Commands,


@@ 259,6 276,7 @@ fn on_message(
                                radius: match *planet_type {
                                    PlanetType::Earth => EARTH_SIZE,
                                    PlanetType::Moon => MOON_SIZE,
                                    PlanetType::Mars => MARS_SIZE
                                },
                            },
                        ));


@@ 859,7 877,7 @@ fn convert_modules_recursive(
            let (mut part_type, attach, children) = attached_query.get_mut(child).unwrap();
            if *part_type == PartType::Cargo {
                match planet_type {
                    PlanetType::Moon => {
                    PlanetType::Mars => {
                        *part_type = PartType::Hub;
                        let (mut collider, mut transform, _) = collider_query.get_mut(*children.first().unwrap()).unwrap();
                        *collider = Collider::cuboid(PART_HALF_SIZE / SCALE, PART_HALF_SIZE / SCALE);


@@ 998,6 1016,7 @@ fn on_position_change(
                radius: match *planet_type {
                    PlanetType::Earth => EARTH_SIZE,
                    PlanetType::Moon => MOON_SIZE,
                    PlanetType::Mars => MARS_SIZE,
                },
            },
        ));

M starkingdoms-client/src/protocol.ts => starkingdoms-client/src/protocol.ts +1 -0
@@ 6,6 6,7 @@ export interface ProtoTransform {
export enum PlanetType {
  Earth = "Earth",
  Moon = "Moon",
  Mars = "Mars",
}
export enum PartType {
  Hearty = "Hearty",

M starkingdoms-client/src/textures.ts => starkingdoms-client/src/textures.ts +3 -0
@@ 1,6 1,7 @@
import { PartType, PlanetType } from "./protocol.ts";
import tex_earth from "./assets/earth.svg";
import tex_moon from "./assets/moon.svg";
import tex_mars from "./assets/mars.svg";
import tex_hearty from "./assets/hearty.svg";
import tex_cargo_off from "./assets/cargo_off.svg";
import tex_hub_off from "./assets/hub_off.svg";


@@ 11,6 12,8 @@ export function planet_texture_url(type: PlanetType): string {
    return tex_earth;
  } else if (type == PlanetType.Moon) {
    return tex_moon;
  } else if (type == PlanetType.Mars) {
    return tex_mars;
  }
  return tex_missing;
}