1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Preparations for the trailer

This commit is contained in:
tobspr
2020-05-30 17:50:29 +02:00
parent 88a1c733bd
commit ffd011ac45
20 changed files with 320 additions and 26 deletions

View File

@@ -29,6 +29,10 @@ import { HUDModalDialogs } from "./parts/modal_dialogs";
import { HUDPartTutorialHints } from "./parts/tutorial_hints";
import { HUDWaypoints } from "./parts/waypoints";
/* dev:start */
import { TrailerMaker } from "./trailer_maker";
/* dev:end */
export class GameHUD {
/**
* @param {GameRoot} root
@@ -98,6 +102,12 @@ export class GameHUD {
this.internalInitSignalConnections();
this.root.keyMapper.getBinding(KEYMAPPINGS.ingame.toggleHud).add(this.toggleUi, this);
/* dev:start */
if (G_IS_DEV && globalConfig.debug.renderForTrailer) {
this.trailerMaker = new TrailerMaker(this.root);
}
/* dev:end*/
}
/**
@@ -174,6 +184,10 @@ export class GameHUD {
for (const key in this.parts) {
this.parts[key].update();
}
/* dev:start */
this.trailerMaker.update();
/* dev:end*/
}
/**

View File

@@ -7,6 +7,7 @@ import { GameRoot } from "../../root";
import { findNiceIntegerValue } from "../../../core/utils";
import { Math_pow } from "../../../core/builtins";
import { blueprintShape } from "../../upgrades";
import { globalConfig } from "../../../core/config";
const logger = createLogger("blueprint");
@@ -54,6 +55,9 @@ export class Blueprint {
* Returns the cost of this blueprint in shapes
*/
getCost() {
if (G_IS_DEV && globalConfig.debug.blueprintsNoCost) {
return 0;
}
return findNiceIntegerValue(4 * Math_pow(this.entities.length, 1.1));
}

View File

@@ -90,10 +90,15 @@ export class HUDUnlockNotification extends BaseHUDPart {
}
this.element.querySelector("button.close").classList.remove("unlocked");
this.buttonShowTimeout = setTimeout(
() => this.element.querySelector("button.close").classList.add("unlocked"),
G_IS_DEV ? 100 : 10000
);
if (this.root.app.settings.getAllSettings().offerHints) {
this.buttonShowTimeout = setTimeout(
() => this.element.querySelector("button.close").classList.add("unlocked"),
G_IS_DEV ? 100 : 5000
);
} else {
this.element.querySelector("button.close").classList.add("unlocked");
}
}
cleanup() {

View File

@@ -0,0 +1,126 @@
import { GameRoot } from "../root";
import { globalConfig } from "../../core/config";
import { Vector, mixVector } from "../../core/vector";
import { performanceNow } from "../../core/builtins";
import { lerp } from "../../core/utils";
/* dev:start */
import trailerPoints from "./trailer_points";
import { gMetaBuildingRegistry } from "../../core/global_registries";
import { MetaBeltBaseBuilding } from "../buildings/belt_base";
import { MinerComponent } from "../components/miner";
const tickrate = 1 / 165;
export class TrailerMaker {
/**
*
* @param {GameRoot} root
*/
constructor(root) {
this.root = root;
this.markers = [];
this.playbackMarkers = null;
this.currentPlaybackOrigin = new Vector();
this.currentPlaybackZoom = 3;
window.addEventListener("keydown", ev => {
if (ev.key === "j") {
console.log("Record");
this.markers.push({
pos: this.root.camera.center.copy(),
zoom: this.root.camera.zoomLevel,
time: 1,
wait: 0,
});
} else if (ev.key === "k") {
console.log("Export");
const json = JSON.stringify(this.markers);
const handle = window.open("about:blank");
handle.document.write(json);
} else if (ev.key === "u") {
if (this.playbackMarkers && this.playbackMarkers.length > 0) {
this.playbackMarkers = [];
return;
}
console.log("Playback");
this.playbackMarkers = trailerPoints.map(p => Object.assign({}, p));
this.playbackMarkers.unshift(this.playbackMarkers[0]);
this.currentPlaybackOrigin = Vector.fromSerializedObject(this.playbackMarkers[0].pos);
this.currentPlaybackZoom = this.playbackMarkers[0].zoom;
this.root.camera.center = this.currentPlaybackOrigin.copy();
this.root.camera.zoomLevel = this.currentPlaybackZoom;
console.log("STart at", this.currentPlaybackOrigin);
// this.root.entityMgr.getAllWithComponent(MinerComponent).forEach(miner => {
// miner.components.Miner.itemChainBuffer = [];
// miner.components.Miner.lastMiningTime = this.root.time.now() + 5;
// miner.components.ItemEjector.slots.forEach(slot => (slot.item = null));
// });
// this.root.logic.tryPlaceBuilding({
// origin: new Vector(-428, -15),
// building: gMetaBuildingRegistry.findByClass(MetaBeltBaseBuilding),
// originalRotation: 0,
// rotation: 0,
// variant: "default",
// rotationVariant: 0,
// });
// this.root.logic.tryPlaceBuilding({
// origin: new Vector(-427, -15),
// building: gMetaBuildingRegistry.findByClass(MetaBeltBaseBuilding),
// originalRotation: 0,
// rotation: 0,
// variant: "default",
// rotationVariant: 0,
// });
}
});
}
update() {
if (this.playbackMarkers && this.playbackMarkers.length > 0) {
const nextMarker = this.playbackMarkers[0];
if (!nextMarker.startTime) {
console.log("Starting to approach", nextMarker.pos);
nextMarker.startTime = performanceNow() / 1000.0;
}
const speed =
globalConfig.tileSize *
globalConfig.beltSpeedItemsPerSecond *
globalConfig.itemSpacingOnBelts;
// let time =
// this.currentPlaybackOrigin.distance(Vector.fromSerializedObject(nextMarker.pos)) / speed;
const time = nextMarker.time;
const progress = (performanceNow() / 1000.0 - nextMarker.startTime) / time;
if (progress > 1.0) {
if (nextMarker.wait > 0) {
nextMarker.wait -= tickrate;
} else {
console.log("Approached");
this.currentPlaybackOrigin = this.root.camera.center.copy();
this.currentPlaybackZoom = this.root.camera.zoomLevel;
this.playbackMarkers.shift();
}
return;
}
const targetPos = Vector.fromSerializedObject(nextMarker.pos);
const targetZoom = nextMarker.zoom;
const pos = mixVector(this.currentPlaybackOrigin, targetPos, progress);
const zoom = lerp(this.currentPlaybackZoom, targetZoom, progress);
this.root.camera.zoomLevel = zoom;
this.root.camera.center = pos;
}
}
}
/* dev:end */

View File

@@ -0,0 +1,89 @@
export default [
// // initial
// { pos: { x: -13665, y: -434 }, zoom: 6, time: 1, wait: 8 },
// // Go up to first curve
// { pos: { x: -13665, y: -580 }, zoom: 6, time: 1, wait: 0 },
// // To balancers
// { pos: { x: -13450, y: -580 }, zoom: 6, time: 1, wait: 0 },
// // To cutters
// { pos: { x: -13350, y: -580 }, zoom: 3, time: 1, wait: 2 },
// // To initial cutters
// { pos: { x: -12713, y: -580 }, zoom: 3, time: 1, wait: 2.5 },
// // To rotaters 3,2,1,0
// { pos: { x: -12402, y: -580 }, zoom: 3, time: 1, wait: 0 },
// // Zoom in further to stackers
// { pos: { x: -12045, y: -580 }, zoom: 6, time: 1, wait: 4 },
// // Focus on painter
// { pos: { x: -11700, y: -660 }, zoom: 6, time: 1, wait: 3.5 },
// // Zoom in to mixers
// { pos: { x: -11463, y: -520 }, zoom: 6, time: 1, wait: 3.8 },
// // Focus to second painter
// { pos: { x: -11290, y: -610 }, zoom: 6, time: 1, wait: 1 },
// // Second stacker
// { pos: { x: -11022, y: -610 }, zoom: 6, time: 1, wait: 0 },
// // Go right until first curve
// { pos: { x: -10859, y: -650 }, zoom: 6, time: 1, wait: 0 },
// // Go up to stacker
// { pos: { x: -10859, y: -1120 }, zoom: 6, time: 1, wait: 0 },
// // Go further up
// { pos: { x: -10859, y: -1260 }, zoom: 6, time: 1, wait: 0 },
// // Go left
// { pos: { x: -11235, y: -1260 }, zoom: 6, time: 1, wait: 1 },
// OWO Savegames
// { pos: { x: -4939.356940622392, y: 71.76431237675517 }, zoom: 5.06640625, time: 1, wait: 1 },
// { pos: { x: -4275.441641063683, y: 26.3603982512193 }, zoom: 0.45, time: 32, wait: 0 },
// Eve
// { pos: { x: -277.22574043554704, y: 2151.1873666983033 }, zoom: 3.1, time: 0, wait: 2 },
// { pos: { x: -43.64015426578788, y: 1577.5520572108883 }, zoom: 1.4, time: 16, wait: 0 },
// { pos: { x: 133.22735227708466, y: 957.2211413984563 }, zoom: 1.4, time: 8, wait: 0 },
// { pos: { x: 480.20365842184424, y: -313.5485044644265 }, zoom: 1.4, time: 8, wait: 0 },
// {
// pos: { x: 452.56528647804333, y: -1341.6422407571154 },
// zoom: 1.4,
// time: 8,
// wait: 0,
// },
// D
{ pos: { x: -7506.562977380196, y: 1777.6671860680613 }, zoom: 2.3764616075569833, time: 0, wait: 1 },
{ pos: { x: -7506.562977380196, y: 1777.6671860680613 }, zoom: 2.3764616075569833, time: 1, wait: 0 },
{ pos: { x: -6592.471896026158, y: 1841.974816890533 }, zoom: 1.4594444847409322, time: 24, wait: 0 },
{ pos: { x: -7274.384090342281, y: 729.3783696229457 }, zoom: 1.4594444847409322, time: 24, wait: 0 },
{ pos: { x: -6048.006011617565, y: 764.6297752493597 }, zoom: 1.1853320776932916, time: 24, wait: 0 },
{
pos: { x: -3674.7204249483366, y: 658.6366426023269 },
zoom: 0.25332031250000003,
time: 24,
wait: 0,
},
{
pos: { x: -1213.9916574596728, y: -1387.1496772071198 },
zoom: 0.443058809814453,
time: 24,
wait: 0,
},
{
pos: { x: 1722.5210292405573, y: -2457.2072755163636 },
zoom: 0.6313986260996299,
time: 24,
wait: 0,
},
{ pos: { x: 3533.263459106946, y: -1806.6756300805193 }, zoom: 1.551908182277415, time: 24, wait: 0 },
];