Skip to content

Commit

Permalink
Log replay data on game win and lose
Browse files Browse the repository at this point in the history
  • Loading branch information
TwoTau committed May 26, 2022
1 parent f60162b commit 1cfb2f5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
26 changes: 24 additions & 2 deletions export/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ function serialize(b) {
return [b.id, b.pos.x, b.pos.y, b.rot, b.flip ? 1 : 0].join(",");
}

function handleBuildingsData(details) {
function handleBuildingsData(details, changeCurrentBuildings=true) {
let currentBuildingsCopy;
let currentGridSizeCopy;
if (!changeCurrentBuildings) {
currentGridSizeCopy = currentGridSize;
currentBuildingsCopy = [...currentBuildings]
}

const buildings = details.game.buildings.map((b) => serialize({
id: b.id,
pos: b.current_pos,
Expand Down Expand Up @@ -36,6 +43,14 @@ function handleBuildingsData(details) {
}
}
turns.push(res.join("|"));

if (!changeCurrentBuildings) {
currentBuildings = currentBuildingsCopy;
currentGridSize = currentGridSizeCopy;
const ret = getReplayData();
turns.pop();
return ret;
}
}

function getReplayData() {
Expand Down Expand Up @@ -389,7 +404,7 @@ class CapstoneLogger {
details = this.parseArgs(details);
// console.log("[LOG LEVEL END]", details);
handleBuildingsData(details);
details.replay = getReplayData();
details.game.buildings = getReplayData();

try {
this.flushBufferedLevelActions();
Expand Down Expand Up @@ -421,6 +436,13 @@ class CapstoneLogger {
details = this.parseArgs(details);
// console.log("[LOG LEVEL ACTION]", actionId, details);

if (actionId === 666 || actionId === 777) {
// win or lose
let replay = handleBuildingsData(details, false);
details.game.buildings = replay;
console.log(replay);
}

// Per action, figure out the time since the start of the level
const timestampOfAction = Date.now();
const relativeTime = timestampOfAction - this.timestampOfPrevLevelStart;
Expand Down
1 change: 1 addition & 0 deletions source/scripts/Logger.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ enum Actions {
BuildingRotated = 70,
BuildingFlipped = 71,

# if you change these, remember to change them in logging.js too:
Lose = 666,
Win = 777,
}
Expand Down

0 comments on commit 1cfb2f5

Please sign in to comment.