constructor(props) {
    super(props);
    this.state = {
      spells: [
      ],
    };

    postal.subscribe({
      topic: 'ui.spells.list',
      callback: (spells)=> this.setState({ spells })
    });

    postal.publish({
      topic: 'game.query.spells'
    });
  }
    async function init() {
      await fonts;

      screenStack.bindInputEvents();
      mainMenu.show();
      postal.subscribe({
        topic: 'ui.turn.update',
        callback: (data)=> {
          const turnAt = performance.now();
          if (data.turn === 1)
            this.lastTurnAt = null;
          this.setState({ turn: data.turn });

          let turnsPerSecond;
          if (this.lastTurnAt !== null) {
            const diff = turnAt - this.lastTurnAt;
            const tps = 1000 / diff;
            this.avgTps += (tps - this.avgTps) / (data.turn - 1);
            turnsPerSecond = this.avgTps.toFixed(2);
          }
          this.lastTurnAt = turnAt;
          this.props.updateTPS({ turn: data.turn, turnsPerSecond });
          mainMenu.game.engine.lock();
          window.requestAnimationFrame(function() {
            mainMenu.game.engine.unlock();
          });
        }
      });
    }
 init() {
   if (this._isInitialized)
     return;
   postal.subscribe({
     channel: 'ui',
     topic: 'vision.update',
     callback: (data)=> {
       this.renderTile(data.tile);
     }
   });
   postal.subscribe({
     channel: 'ui',
     topic: 'vision.reset',
     callback: (data)=> {
       this.renderFov(data.fov);
     }
   });
   this._isInitialized = true;
 }
 constructor() {
   super();
   postal.subscribe({
     topic: 'ui.mainMenu',
     callback: (data) => {
       this.options = data.options;
       this.numberOfLevels = data.numberOfLevels;
     }
   });
 }
Exemple #5
0
 updateMainMenuOptions() {
   postal.publish({
     topic: 'ui.mainMenu',
     data: {
       options: {
         numberOfCreatures: parseInt(this.getNumberOfCreatures()),
         width: parseInt(this.state.width),
         height: parseInt(this.state.height),
       },
       numberOfLevels: parseInt(this.state.numberOfLevels),
     }
   });
 }
Exemple #6
0
 async onRendered(){
   await fonts;
   //setTimeout(()=>{
   screenStack.bindInputEvents();
   screenStack.container = this.container;
   mainMenu.show();
   //}, 250)
   postal.subscribe({
     channel: 'ui',
     topic: 'turn.update',
     callback: (data)=> {
       const turnAt = performance.now();
       if (data.turn === 1)
         lastTurnAt = null;
       this.turn(data.turn);
       if (lastTurnAt !== null) {
         const diff = turnAt - lastTurnAt;
         const tps = 1000 / diff;
         avgTps += (tps - avgTps) / (data.turn - 1);
         this.turnsPerSecond(avgTps.toFixed(2));
       }
       lastTurnAt = turnAt;
     }
   });
 },
 autorun: [
   function () {
     this.numberOfCreatures(this.width() * this.height() / 2);
   },
   function () {
     mainMenu.options = { numberOfCreatures: parseInt(this.numberOfCreatures()), width: parseInt(this.width()), height: parseInt(this.height()) };
Exemple #7
0
import GameGenerator from 'shattered-game/GameGenerator';
import events from 'shattered-game/events';
import { postal } from 'shattered-game/global';

let game;
let firstTurnAt = 0;
postal.subscribe({
  channel: 'ui',
  topic: 'turn.update',
  callback: (data)=> {
    if (data.turn === 1) {
      firstTurnAt = process.hrtime();
    }

    if (data.turn === 500) {
      let end = process.hrtime(firstTurnAt);
      let diff = (end[0] * 1000) + (end[1] / 1000000);
      console.log(`Game Complete. Avg TPS: ${calculateTPS(diff, data.turn)}`);
      game.engine.lock();
    }

  }
});

game = newGameCommand();


function calculateTPS(diff, turns) {
  const tps = 1000 / (diff / turns);
  let turnsPerSecond = tps.toFixed(2);
  return turnsPerSecond;