<commit_before>// Manage the world save and all humanity.

var fs = require('fs');
var Humanity = require('./humanity.js');

function World(worldFile) {
  this.humanity = new Humanity();
  // FIXME: create an instance of terrain.
  this.terrain = this.humanity.terrain;
  this.worldFile = worldFile;

  try {
    var world = require(this.worldFile);
    this.humanity.patch(world);
  } catch(e) {
    this.humanity.setSpawn();
  }
  //for (var i = 0; i < this.humanity.numberOfCamps; i++) {
  //  console.log('camp', i + ':', this.humanity.camps[i].spawn);
  //}
  // Update periodically.
  var periodicity = 10000;  // Every 10s.
  setInterval(this.saveWorld.bind(this), periodicity);
}

World.prototype = {
  humanity: null,
  terrain: null,
  worldFile: 'world.json',

  saveWorld: function saveWorld() {
    // Like a hero.
    if (this.humanity.dirtyWorld) {
      var world = {};
      var humanityData = this.humanity.humanityData;
      for (var tileKey in humanityData) {
        world[tileKey] = humanityData[tileKey];
      }
      world.places = this.humanity.places;
      world.centerTile = this.humanity.centerTile;
      world.campNames = this.humanity.campNames();
      world.resources = this.humanity.getUsedResources();
      fs.writeFile(this.worldFile, JSON.stringify(world));
      this.humanity.dirtyWorld = false;
    }
  },
};

module.exports = World;<commit_msg>Avoid warning about missing file system callback<commit_after>// Manage the world save and all humanity.

var fs = require('fs');
var Humanity = require('./humanity.js');

function World(worldFile) {
  this.humanity = new Humanity();
  // FIXME: create an instance of terrain.
  this.terrain = this.humanity.terrain;
  this.worldFile = worldFile;

  try {
    var world = require(this.worldFile);
    this.humanity.patch(world);
  } catch(e) {
    this.humanity.setSpawn();
  }
  //for (var i = 0; i < this.humanity.numberOfCamps; i++) {
  //  console.log('camp', i + ':', this.humanity.camps[i].spawn);
  //}
  // Update periodically.
  var periodicity = 10000;  // Every 10s.
  setInterval(this.saveWorld.bind(this), periodicity);
}

World.prototype = {
  humanity: null,
  terrain: null,
  worldFile: 'world.json',

  saveWorld: function saveWorld() {
    // Like a hero.
    if (this.humanity.dirtyWorld) {
      var world = {};
      var humanityData = this.humanity.humanityData;
      for (var tileKey in humanityData) {
        world[tileKey] = humanityData[tileKey];
      }
      world.places = this.humanity.places;
      world.centerTile = this.humanity.centerTile;
      world.campNames = this.humanity.campNames();
      world.resources = this.humanity.getUsedResources();
      fs.writeFile(this.worldFile, JSON.stringify(world), function() {});
      this.humanity.dirtyWorld = false;
    }
  },
};

module.exports = World;
{'fraction_non_alphanumeric': 0.14391796322489392, 'fraction_numerical': 0.005657708628005658, 'mean_word_length': 3.1059506531204644, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1721082', 'n_tokens_mistral': 948, 'n_tokens_neox': 922, 'n_words': 198}