Skip to content

Commit

Permalink
Merge pull request #44 from BarthPaleologue/NextRelease
Browse files Browse the repository at this point in the history
1.7.0 - Improved flight experience
  • Loading branch information
BarthPaleologue committed Feb 24, 2024
2 parents f07a349 + 74a20e0 commit 19e48c5
Show file tree
Hide file tree
Showing 32 changed files with 496 additions and 292 deletions.
55 changes: 52 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,59 @@
"plugins": ["@typescript-eslint"],
"rules": {
"import/no-cycle": "error",
"import/no-unresolved": "off",
"import/no-unresolved": "warn",
"@typescript-eslint/switch-exhaustiveness-check": "error",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-inferrable-types": "warn",
"eqeqeq": "error",
"camelcase": "warn"
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "enumMember",
"format": ["UPPER_CASE"]
},
{
"selector": "memberLike",
"modifiers": ["public", "static"],
"format": ["PascalCase", "UPPER_CASE"],
"leadingUnderscore": "forbid"
},
{
"selector": "memberLike",
"modifiers": ["private", "static"],
"format": ["PascalCase", "UPPER_CASE"],
"leadingUnderscore": "forbid"
},
{
"selector": "typeLike",
"format": ["PascalCase"]
},
{
"selector": "variable",
"modifiers": ["exported", "const", "global"],
"format": ["PascalCase"],
"leadingUnderscore": "forbid"
},
{
"selector": "function",
"format": ["camelCase", "snake_case"],
"leadingUnderscore": "forbid"
},
{
"selector": "function",
"modifiers": ["exported", "global"],
"format": ["camelCase"],
"leadingUnderscore": "forbid"
},
{
"selector": "interface",
"format": ["PascalCase"],
"leadingUnderscore": "forbid"
},
{
"selector": "class",
"format": ["PascalCase"],
"leadingUnderscore": "forbid"
}
]
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
},
"version": "1.6.4",
"version": "1.7.0",
"description": "CosmosJourneyer",
"name": "cosmos-journeyer",
"scripts": {
Expand Down
Binary file not shown.
Binary file added src/asset/spaceship/wanderer.glb
Binary file not shown.
4 changes: 3 additions & 1 deletion src/html/mainMenu.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="mainMenu" xmlns:>
<h1>Cosmos Journeyer</h1>

<p id="version"></p>
<p id="version"><a target="_blank" href="https://github.com/BarthPaleologue/CosmosJourneyer/releases"></a></p>

<ul id="menuItems" class="leftSideMenu">
<li id="startButton">New Journey</li>
Expand Down Expand Up @@ -88,6 +88,8 @@ <h3>Sound effects</h3>
<p><a href="https://freesound.org/people/MATRIXXX_/sounds/702805/">Futuristic Inspect Sound, UI, or In-Game Notification</a> by MATRIXXX_</p>

<p><a href="https://freesound.org/people/Timbre/sounds/539503/">endless acceleration</a> by Timbre</p>

<p><a href="https://freesound.org/people/LimitSnap_Creations/sounds/318688/">Rocket Thrust effect</a> by LimitSnap_Creations</p>
</div>

<div id="about" class="rightPanel">
Expand Down
2 changes: 1 addition & 1 deletion src/shaders/starfieldFragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void main() {
vec2 starfieldUV = vec2(0.0);

// if the pixel is at the far plane
if (depth == 1.0) {
if (screenColor == vec4(0.0) && depth == 1.0) {
// get the starfield color
// get spherical coordinates uv for the starfield texture
starfieldUV = vec2(
Expand Down
10 changes: 10 additions & 0 deletions src/styles/mainMenu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
font-size: 1.5em;
padding: 10px;
transition: 0.2s ease-in-out;

a {
color: white;
transition: 0.1s;
text-decoration: underline solid rgba(255, 255, 255, 0.5);

&:hover {
text-decoration: underline solid white;
}
}
}

.rightPanel {
Expand Down
34 changes: 33 additions & 1 deletion src/ts/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import spaceship from "../asset/spaceship/spaceship2.glb";
import shipCarrier from "../asset/spacestation/shipcarrier.glb";
import banana from "../asset/banana/banana.glb";
import endeavorSpaceship from "../asset/spaceship/endeavour.glb";
import wanderer from "../asset/spaceship/wanderer.glb";
import character from "../asset/character/character.glb";
import rock from "../asset/rock.glb";
import landingPad from "../asset/landingpad.glb";
Expand All @@ -65,6 +66,8 @@ import disableWarpDriveSound from "../asset/sound/204418__nhumphrey__large-engin
import acceleratingWarpDriveSound from "../asset/sound/539503__timbre__endless-acceleration.mp3";
import deceleratingWarpDriveSound from "../asset/sound/539503__timbre_endless-deceleration.mp3";

import thrusterSound from "../asset/sound/318688__limitsnap_creations__rocket-thrust-effect.mp3";

import starMapBackgroundMusic from "../asset/sound/455855__andrewkn__wandering.mp3";

import { Texture } from "@babylonjs/core/Materials/Textures/texture";
Expand All @@ -84,7 +87,6 @@ import { createButterfly } from "./proceduralAssets/butterfly/butterfly";
import { createGrassBlade } from "./proceduralAssets/grass/grassBlade";
import { ButterflyMaterial } from "./proceduralAssets/butterfly/butterflyMaterial";
import { GrassMaterial } from "./proceduralAssets/grass/grassMaterial";
import { Observable } from "@babylonjs/core/Misc/observable";

export class Assets {
static IS_READY = false;
Expand Down Expand Up @@ -115,6 +117,7 @@ export class Assets {

private static SPACESHIP: Mesh;
private static ENDEAVOR_SPACESHIP: Mesh;
private static WANDERER: Mesh;
private static SPACE_STATION: Mesh;
private static BANANA: Mesh;
private static CHARACTER: Mesh;
Expand Down Expand Up @@ -149,6 +152,8 @@ export class Assets {
public static ACCELERATING_WARP_DRIVE_SOUND: Sound;
public static DECELERATING_WARP_DRIVE_SOUND: Sound;

public static THRUSTER_SOUND: Sound;

public static STAR_MAP_BACKGROUND_MUSIC: Sound;
public static MAIN_MENU_BACKGROUND_MUSIC: Sound;

Expand Down Expand Up @@ -205,6 +210,17 @@ export class Assets {
console.log("Endeavor Spaceship loaded");
};

const wandererTask = Assets.MANAGER.addMeshTask("wandererTask", "", "", wanderer);
wandererTask.onSuccess = function (task: MeshAssetTask) {
Assets.WANDERER = task.loadedMeshes[0] as Mesh;

for (const mesh of Assets.WANDERER.getChildMeshes()) {
mesh.isVisible = false;
}

console.log("Wanderer loaded");
};

const spacestationTask = Assets.MANAGER.addMeshTask("spacestationTask", "", "", shipCarrier);
spacestationTask.onSuccess = function (task: MeshAssetTask) {
Assets.SPACE_STATION = task.loadedMeshes[0] as Mesh;
Expand Down Expand Up @@ -401,6 +417,18 @@ export class Assets {
console.log("Decelerating warp drive sound loaded");
};

const thrusterSoundTask = Assets.MANAGER.addBinaryFileTask("thrusterSoundTask", thrusterSound);
thrusterSoundTask.onSuccess = function (task) {
Assets.THRUSTER_SOUND = new Sound("ThrusterSound", task.data, scene);
Assets.THRUSTER_SOUND.updateOptions({
playbackRate: 1.0,
volume: 0.5,
loop: true
});

console.log("Thruster sound loaded");
};

const starMapBackgroundMusicTask = Assets.MANAGER.addBinaryFileTask("starMapBackgroundMusicTask", starMapBackgroundMusic);
starMapBackgroundMusicTask.onSuccess = function (task) {
Assets.STAR_MAP_BACKGROUND_MUSIC = new Sound("StarMapBackgroundMusic", task.data, scene, null, {
Expand Down Expand Up @@ -454,6 +482,10 @@ export class Assets {
return instance;
}

static CreateWandererInstance(): InstancedMesh {
return Assets.WANDERER.instantiateHierarchy(null, { doNotInstantiate: false }) as InstancedMesh;
}

static CreateSpaceStationInstance(): InstancedMesh {
return Assets.SPACE_STATION.instantiateHierarchy(null, { doNotInstantiate: false }) as InstancedMesh;
}
Expand Down
24 changes: 24 additions & 0 deletions src/ts/audio/audioManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { AudioInstance } from "../utils/audioInstance";


export class AudioManager {
private static ENABLED_MASK = 0b1111;

private static readonly SOUNDS: AudioInstance[] = [];

public static RegisterSound(sound: AudioInstance) {
this.SOUNDS.push(sound);
}

public static SetMask(mask: number) {
this.ENABLED_MASK = mask;
}

public static Update(deltaSeconds: number) {
this.SOUNDS.forEach(sound => {
const isSoundEnabled = (sound.mask & this.ENABLED_MASK) !== 0;
sound.setMaskFactor(isSoundEnabled ? 1 : 0);
sound.update(deltaSeconds);
});
}
}
4 changes: 4 additions & 0 deletions src/ts/audio/audioMasks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const AudioMasks = {
STAR_SYSTEM_VIEW: 0b0001,
STAR_MAP_VIEW: 0b0010,
}
20 changes: 12 additions & 8 deletions src/ts/cosmosJourneyer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { Tools } from "@babylonjs/core/Misc/tools";
import { VideoRecorder } from "@babylonjs/core/Misc/videoRecorder";
import "@babylonjs/core/Misc/screenshotTools";
import { StarMap } from "./starmap/starMap";
import { Scene } from "@babylonjs/core/scene";

import "@babylonjs/core/Physics/physicsEngineComponent";
import HavokPhysics from "@babylonjs/havok";
Expand All @@ -44,6 +43,8 @@ import { UniverseCoordinates } from "./saveFile/universeCoordinates";
import { View } from "./utils/view";
import { updateInputDevices } from "./inputs/devices";
import { Assets } from "./assets";
import { AudioManager } from "./audio/audioManager";
import { AudioMasks } from "./audio/audioMasks";

enum EngineState {
UNINITIALIZED,
Expand Down Expand Up @@ -84,14 +85,15 @@ export class CosmosJourneyer {
const activeControls = this.starSystemView.scene.getActiveController();
if (activeControls instanceof ShipControls) {
activeControls.spaceship.enableWarpDrive();
activeControls.thirdPersonCamera.radius = 30;
activeControls.thirdPersonCamera.radius = ShipControls.BASE_CAMERA_RADIUS;
}
});

// Init the active scene
this.starMap.detachControl();
this.starSystemView.attachControl();
this.activeView = this.starSystemView;
AudioManager.SetMask(AudioMasks.STAR_SYSTEM_VIEW);

this.mainMenu = new MainMenu(starSystemView);
this.mainMenu.onStartObservable.add(() => {
Expand All @@ -100,6 +102,7 @@ export class CosmosJourneyer {
this.starSystemView.getSpaceshipControls().spaceship.enableWarpDrive();
this.starSystemView.showUI();
this.starSystemView.ui.setEnabled(true);
this.starSystemView.ui.setTarget(this.starSystemView.getStarSystem().getClosestToScreenCenterOrbitalObject());
});

this.mainMenu.onLoadSaveObservable.add((saveData: SaveFileData) => {
Expand Down Expand Up @@ -178,14 +181,14 @@ export class CosmosJourneyer {
const havokInstance = await HavokPhysics();
console.log(`Havok initialized`);

// Init starmap view
const starMap = new StarMap(engine);

// Init star system view
const starSystemView = new StarSystemView(engine, havokInstance);

await starSystemView.initAssets();

// Init starmap view
const starMap = new StarMap(engine);

return new CosmosJourneyer(engine, starSystemView, starMap);
}

Expand Down Expand Up @@ -218,6 +221,7 @@ export class CosmosJourneyer {

this.engine.runRenderLoop(() => {
updateInputDevices();
AudioManager.Update(this.engine.getDeltaTime() / 1000);

if (this.isPaused()) return;
this.activeView.render();
Expand All @@ -231,8 +235,7 @@ export class CosmosJourneyer {
public toggleStarMap(): void {
if (this.activeView === this.starSystemView) {
this.starSystemView.unZoom(() => {
this.starSystemView.stopBackgroundSounds();
this.starMap.startBackgroundMusic();
AudioManager.SetMask(AudioMasks.STAR_MAP_VIEW);

this.activeView.detachControl();
this.starMap.attachControl();
Expand All @@ -242,9 +245,10 @@ export class CosmosJourneyer {
starMap.focusOnCurrentSystem();
});
} else {
this.starMap.stopBackgroundMusic();
this.activeView.detachControl();
this.starSystemView.attachControl();

AudioManager.SetMask(AudioMasks.STAR_SYSTEM_VIEW);
this.activeView = this.starSystemView;
this.starSystemView.showUI();
}
Expand Down
5 changes: 4 additions & 1 deletion src/ts/mainMenu/mainMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ Math.trunc((Math.random() * 2 - 1) * 1000),

const version = document.getElementById("version");
if (version === null) throw new Error("#version does not exist!");
version.textContent = `Alpha ${packageInfo.version}`;
// children a elements has the version number as textContent
const childLink = version.querySelector("a");
if (childLink === null) throw new Error("version link does not exist!");
childLink.textContent = `Alpha ${packageInfo.version}`;
this.version = version;

document.querySelectorAll("#menuItems li").forEach((li) => {
Expand Down
Loading

0 comments on commit 19e48c5

Please sign in to comment.