Path: blob/main/projects/HexGL/libs/Editor_files/Iterator.js
4627 views
var pgli = pgli || {};1pgli.lang = pgli.lang || {};23pgli.lang.Iterator = gamecore.Base.extend('Iterator',4// Static5{6MAX_ITERATIONS: 1000,78COMPARATORS: {9"<": 0,10">": 1,11"<=": 2,12">=": 313},1415genComparatorMethod: function(type)16{17switch(type)18{19case 0:20return function(a, b){ return a < b };21case 1:22return function(a, b){ return a > b };23case 2:24return function(a, b){ return a <= b };25case 3:26return function(a, b){ return a >= b };27default:28return function(a, b){ return false };29}30},3132genStepMethod: function(type, scope, attr)33{34switch(type)35{36case 1:37case 3:38return function(){ return --scope[attr] };39case 0:40case 2:41default:42return function(){ return ++scope[attr] };43}44}45},46// Instance47{48varname: "i",49start: 0,50end: 1,51comparator: 0,52compMethod: null,53stepMethod: null,54step: 0,55iter: 0,5657init: function(name, start, comparator, end)58{59var static = pgli.lang.Iterator;6061if(comparator in static.COMPARATORS)62this.comparator = static.COMPARATORS[comparator];63else64this.comparator = static.COMPARATORS["<"];6566this.start = start;67this.end = end;68this.step = start;6970this.varname = name;71this.compMethod = static.genComparatorMethod(this.comparator);72this.stepMethod = static.genStepMethod(this.comparator, this, "step");73},7475loop: function()76{77return (this.iter < pgli.lang.Iterator.MAX_ITERATIONS && this.compMethod(this.step, this.end));78},7980next: function()81{82++this.iter;83return this.stepMethod();84},8586toString: function()87{88return "Iterator("+this.varname+") "+this.start+" - "+this.step+" - "+this.end;89}9091});9293