Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help reading the save file #20

Open
tox2ik opened this issue Jun 10, 2023 · 0 comments
Open

Help reading the save file #20

tox2ik opened this issue Jun 10, 2023 · 0 comments

Comments

@tox2ik
Copy link

tox2ik commented Jun 10, 2023

Hi, I'm trying to find all farm tiles or planterboxes in a save file that contain mealwood. It's not super obvious to me how to traverse the game objects to find what im looking for.

I've tried this:


const { readFileSync } = require("fs");
const {
    parseSaveGame,
    writeSaveGame,
		getBehavior,
    AIAttributeLevelsBehavior
} = require("oni-save-parser");

const fs = require('fs');

function loadFile(fileName) {
  const fileData = readFileSync(fileName); //`./test-data/${fileName}.sav`
  return parseSaveGame(fileData.buffer);
}

function saveFile(fileName, save) {
  const fileData = writeSaveGame(save);
  fs.writeFileSync(fileName, new Uint8Array(fileData)); // ./test-data/${fileName}.sav
}


let fileName = 'aa';

if (process.argv[2]) {
	fileName = process.argv[2];
}

const saveData = loadFile(fileName);
const stuff = saveData.gameObjects.find(e => e.name === "BasicPlantFood")


const farmTile = saveData.gameObjects.find(e => e.name === "FarmTile")

let ftn = 0 ;
for (ft of farmTile.gameObjects) {
  ftn++
  console.log("FarmTile:", ft)
  for (be of ft.behaviors) {
    console.log(ft.name, be.name)
    if (be.name === "Storage") {
      console.log("FarmTile.behaviors[~Storage]:", be)
    }
  }

  break
}


console.log( JSON.stringify(farmTile))

Can you provide any guidance here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant