ondras / rot.js

ROguelike Toolkit in JavaScript. Cool dungeon-related stuff, interactive manual, documentation, tests!
https://ondras.github.io/rot.js/hp/
BSD 3-Clause "New" or "Revised" License
2.33k stars 254 forks source link

ROT.Scheduler.Speed not working properly #127

Closed jbrod22 closed 6 years ago

jbrod22 commented 6 years ago

Hi all,

I'm using ROT.Scheduler.Speed in my web game. I'm running into a few problems.

  1. Scheduler.next() is not returning the proper item. It only returns the first object added, in this case the player. I found a fix for this by replacing ROT.Scheduler.prototype.next() with this ROT.Scheduler.prototype.next = function() { this._current = {} Object.assign(this._current, this._queue.get()) return this._current; };
  2. With the above I can move down my scheduler but the actors aren't repeating so it will go down my list of Scheduler actors and then return undefined

Notes: The webapp is built in React. I want to add and remove actors at any point in time. I want to dispatch the this._current actor for all React components to see I only want the Scheduler to know the ActorsID and their speed so I replaced the add function with this ROT.Scheduler.Speed.prototype.add = function(item, repeat, time) { function CreateSchedulerObject(actor) { let speedInt = actor .CharacterSheet .getAttribute('Agility') return { id: actor.getID(), getSpeed: function () { return speedInt } } } let newObj = CreateSchedulerObject(item) console.log(newObj) this._queue.add(newObj, time !== undefined ? time : 1/newObj.getSpeed()); return ROT.Scheduler.prototype.add.call(this, newObj, repeat); };

Thanks

jbrod22 commented 6 years ago

Solved issue!