1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00
This commit is contained in:
Daan Vanoverloop
2020-07-06 18:46:38 +02:00
14 changed files with 1116 additions and 52 deletions

View File

@@ -5,8 +5,30 @@
text-align: right;
font-size: 15px;
display: flex;
display: grid;
line-height: 15px;
flex-direction: column;
color: #fff;
grid-gap: 2px;
text-shadow: 1px 1px 3px rgba(#000, 0.4);
font-weight: bold;
&:not([data-mode="detailed"]) {
.mousePosition,
.cameraPosition {
display: none;
}
}
code {
background: #333;
min-width: 30px;
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 14px;
line-height: 15px;
padding: 1px;
font-family: "GameFont";
border-radius: 3px;
}
}

View File

@@ -147,6 +147,7 @@
flex-grow: 1;
align-items: center;
justify-content: center;
flex-direction: column;
@include S(padding-top, 20px);
img {
@@ -160,6 +161,24 @@
background: uiResource("demo_badge.png") center center / contain no-repeat;
display: inline-block;
}
position: relative;
.updateLabel {
position: absolute;
transform: translateX(50%) rotate(-5deg);
color: $colorRedBright;
@include Heading;
text-transform: uppercase;
font-weight: bold;
@include S(right, 40px);
@include S(bottom, 20px);
@include InlineAnimation(1.3s ease-in-out infinite) {
50% {
transform: translateX(50%) rotate(-7deg) scale(1.1);
}
}
}
}
.betaWarning {

View File

@@ -9,11 +9,14 @@ export const CHANGELOG = [
"Allow binding TAB (by swtw7466)",
"Added keybinding to close menus (by isaisstillalive / Sandwichs-del)",
"Fix rare crash regarding the buildings toolbar (by isaisstillalive)",
"Fixed some phrases (By EnderDoom77)",
"Fixed some phrases (by EnderDoom77)",
"Zoom towards mouse cursor (by Dimava)",
"Updated the soundtrack again, it is now 20 minutes in total!",
"Updated and added new translations (Thanks to all contributors!)",
"Show confirmation when cutting area which is too expensive to get pasted again (by isaisstillalive)",
"Show mouse and camera tile on debug overlay (F4) (by dengr)",
"Fix tunnels entrances connecting to exits sometimes when they shouldn't",
"The initial belt planner direction is now based on the cursor movement (by MizardX)",
],
},
{

View File

@@ -92,6 +92,12 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
*/
this.currentDirectionLockSide = 0;
/**
* Whether the side for direction lock has not yet been determined.
* @type {boolean}
*/
this.currentDirectionLockSideIndeterminate = true;
this.initializeBindings();
}
@@ -204,6 +210,17 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
const worldPos = this.root.camera.screenToWorld(mousePosition);
const mouseTile = worldPos.toTileSpace();
// Figure initial direction
const dx = Math.abs(this.lastDragTile.x - mouseTile.x);
const dy = Math.abs(this.lastDragTile.y - mouseTile.y);
if (dx === 0 && dy === 0) {
// Back at the start. Try a new direction.
this.currentDirectionLockSideIndeterminate = true;
} else if (this.currentDirectionLockSideIndeterminate) {
this.currentDirectionLockSideIndeterminate = false;
this.currentDirectionLockSide = dx <= dy ? 0 : 1;
}
if (this.currentDirectionLockSide === 0) {
return new Vector(this.lastDragTile.x, mouseTile.y);
} else {

View File

@@ -2,43 +2,121 @@ import { BaseHUDPart } from "../base_hud_part";
import { makeDiv, round3Digits, round2Digits } from "../../../core/utils";
import { DynamicDomAttach } from "../dynamic_dom_attach";
import { KEYMAPPINGS } from "../../key_action_mapper";
import { Vector } from "../../../core/vector";
import { TrackedState } from "../../../core/tracked_state";
/** @enum {string} */
const enumDebugOverlayMode = { disabled: "disabled", regular: "regular", detailed: "detailed" };
/**
* Specifies which mode follows after which mode
* @enum {enumDebugOverlayMode}
*/
const enumDebugOverlayModeNext = {
[enumDebugOverlayMode.disabled]: enumDebugOverlayMode.regular,
[enumDebugOverlayMode.regular]: enumDebugOverlayMode.detailed,
[enumDebugOverlayMode.detailed]: enumDebugOverlayMode.disabled,
};
const UPDATE_INTERVAL_SECONDS = 0.25;
export class HUDDebugInfo extends BaseHUDPart {
createElements(parent) {
this.element = makeDiv(parent, "ingame_HUD_DebugInfo", []);
this.tickRateElement = makeDiv(this.element, null, ["tickRate"], "Ticks /s: 120");
this.fpsElement = makeDiv(this.element, null, ["fps"], "FPS: 60");
this.tickDurationElement = makeDiv(this.element, null, ["tickDuration"], "Update time: 0.5ms");
const tickRateElement = makeDiv(this.element, null, ["tickRate"]);
this.trackedTickRate = new TrackedState(str => (tickRateElement.innerText = str));
const tickDurationElement = makeDiv(this.element, null, ["tickDuration"]);
this.trackedTickDuration = new TrackedState(str => (tickDurationElement.innerText = str));
const fpsElement = makeDiv(this.element, null, ["fps"]);
this.trackedFPS = new TrackedState(str => (fpsElement.innerText = str));
const mousePositionElement = makeDiv(this.element, null, ["mousePosition"]);
this.trackedMousePosition = new TrackedState(str => (mousePositionElement.innerHTML = str));
const cameraPositionElement = makeDiv(this.element, null, ["cameraPosition"]);
this.trackedCameraPosition = new TrackedState(str => (cameraPositionElement.innerHTML = str));
this.versionElement = makeDiv(this.element, null, ["version"], "version unknown");
}
initialize() {
this.lastTick = 0;
this.visible = false;
this.trackedMode = new TrackedState(this.onModeChanged, this);
this.domAttach = new DynamicDomAttach(this.root, this.element);
this.root.keyMapper.getBinding(KEYMAPPINGS.ingame.toggleFPSInfo).add(() => this.toggle());
this.root.keyMapper.getBinding(KEYMAPPINGS.ingame.toggleFPSInfo).add(() => this.cycleModes());
// Set initial mode
this.trackedMode.set(enumDebugOverlayMode.disabled);
}
toggle() {
this.visible = !this.visible;
this.domAttach.update(this.visible);
/**
* Called when the mode changed
* @param {enumDebugOverlayMode} mode
*/
onModeChanged(mode) {
this.element.setAttribute("data-mode", mode);
this.versionElement.innerText = `${G_BUILD_VERSION} @ ${G_APP_ENVIRONMENT} @ ${G_BUILD_COMMIT_HASH}`;
}
update() {
const now = this.root.time.realtimeNow();
if (now - this.lastTick > 0.25 && this.visible) {
this.lastTick = now;
this.tickRateElement.innerText = "Tickrate: " + this.root.dynamicTickrate.currentTickRate;
this.fpsElement.innerText =
"FPS: " +
/**
* Updates the labels
*/
updateLabels() {
this.trackedTickRate.set("Tickrate: " + this.root.dynamicTickrate.currentTickRate);
this.trackedFPS.set(
"FPS: " +
Math.round(this.root.dynamicTickrate.averageFps) +
" (" +
round2Digits(1000 / this.root.dynamicTickrate.averageFps) +
" ms)";
this.tickDurationElement.innerText =
"Tick Dur: " + round3Digits(this.root.dynamicTickrate.averageTickDuration) + "ms";
" ms)"
);
this.trackedTickDuration.set(
"Tick: " + round3Digits(this.root.dynamicTickrate.averageTickDuration) + "ms"
);
}
/**
* Updates the detailed information
*/
updateDetailedInformation() {
const mousePos = this.root.app.mousePosition || new Vector(0, 0);
const mouseTile = this.root.camera.screenToWorld(mousePos).toTileSpace();
const cameraTile = this.root.camera.center.toTileSpace();
this.trackedMousePosition.set(`Pos: <code>${mouseTile.x}</code> / <code>${mouseTile.y}</code>`);
this.trackedCameraPosition.set(`Center: <code>${cameraTile.x}</code> / <code>${cameraTile.y}</code>`);
}
/**
* Cycles through the different modes
*/
cycleModes() {
this.trackedMode.set(enumDebugOverlayModeNext[this.trackedMode.get()]);
}
update() {
const visible = this.trackedMode.get() !== enumDebugOverlayMode.disabled;
this.domAttach.update(visible);
if (!visible) {
return;
}
// Periodically update the text
const now = this.root.time.realtimeNow();
if (now - this.lastTick > UPDATE_INTERVAL_SECONDS) {
this.lastTick = now;
this.updateLabels();
}
// Also update detailed information if required
if (this.trackedMode.get() === enumDebugOverlayMode.detailed) {
this.updateDetailedInformation();
}
}
}

View File

@@ -35,6 +35,7 @@ export class MapView extends BaseMap {
this.root.signals.entityAdded.add(this.onEntityChanged, this);
this.root.signals.entityDestroyed.add(this.onEntityChanged, this);
this.root.signals.entityChanged.add(this.onEntityChanged, this);
}
cleanup() {
@@ -44,7 +45,7 @@ export class MapView extends BaseMap {
}
/**
* Called when an entity was added or removed
* Called when an entity was added, removed or changed
* @param {Entity} entity
*/
onEntityChanged(entity) {

View File

@@ -141,6 +141,7 @@ export class GameRoot {
// Entities
entityManuallyPlaced: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
entityAdded: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
entityChanged: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
entityGotNewComponent: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
entityComponentRemoved: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
entityQueuedForDestroy: /** @type {TypedSignal<[Entity]>} */ (new Signal()),

View File

@@ -185,6 +185,9 @@ export class BeltSystem extends GameSystemWithFilter {
if (G_IS_DEV && globalConfig.debug.checkBeltPaths) {
this.debug_verifyBeltPaths();
}
// Make sure the chunks know about the update
this.root.signals.entityChanged.dispatch(targetEntity);
}
}
}

View File

@@ -309,17 +309,17 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
continue;
}
if (receiverUndergroundComp.mode !== enumUndergroundBeltMode.receiver) {
// Not a receiver
continue;
}
const receiverStaticComp = potentialReceiver.components.StaticMapEntity;
if (receiverStaticComp.rotation !== targetRotation) {
// Wrong rotation
continue;
}
if (receiverUndergroundComp.mode !== enumUndergroundBeltMode.receiver) {
// Not a receiver, but a sender -> Abort to make sure we don't deliver double
break;
}
return { entity: potentialReceiver, distance: searchOffset };
}

View File

@@ -46,18 +46,15 @@ export class MainMenuState extends GameState {
: ""
}
</div>
${
G_IS_STANDALONE
? ""
: `<video autoplay muted loop class="fullscreenBackgroundVideo">
<video autoplay muted loop class="fullscreenBackgroundVideo">
<source src="${cachebust("res/bg_render.webm")}" type="video/webm">
</video>`
}
</video>
<div class="logo">
<img src="${cachebust("res/logo.png")}" alt="shapez.io Logo">
<span class="updateLabel">Wires update!</span>
</div>
@@ -208,14 +205,12 @@ export class MainMenuState extends GameState {
// Initialize video
this.videoElement = this.htmlElement.querySelector("video");
if (this.videoElement) {
this.videoElement.playbackRate = 0.9;
this.videoElement.addEventListener("canplay", () => {
if (this.videoElement) {
this.videoElement.classList.add("loaded");
}
});
}
this.videoElement.playbackRate = 0.9;
this.videoElement.addEventListener("canplay", () => {
if (this.videoElement) {
this.videoElement.classList.add("loaded");
}
});
this.trackClicks(qs(".settingsButton"), this.onSettingsButtonClicked);
this.trackClicks(qs(".changelog"), this.onChangelogClicked);