use new haxe for-in syntax

This commit is contained in:
lif 2020-04-17 21:48:02 -07:00
parent 4db2b31176
commit 04f4fa3ef1
15 changed files with 70 additions and 68 deletions

2
intra/new-for-syntax.sh Normal file
View File

@ -0,0 +1,2 @@
grep -Plr 'for\(([^= ]*)=([^;]*);\1<([^=;]*);\1\+\+\)' source/ | xargs sed -i 's#for(\([^= ]*\)=\([^;]*\);\1<\([^=;]*\);\1++)#for(\1 in \2...\3)#'
grep -Plr 'for\(var ([^=:]*):Int=([^;]*);\1<([^=;]*);\1\+\+\)' source/ | xargs sed -i 's#for(var \([^=:]*\):Int=\([^;]*\);\1<\([^=;]*\);\1++)#for(\1 in \2...\3)#'

View File

@ -1194,7 +1194,7 @@ class Intra extends FlxGame {
*/
if(FlxG.keys.justPressed("R")){
for(var y:Int=36;y<48;y++){
for(y in 36...48){
Registry.card_states[y]=1;
Registry.nr_growths++;
}
@ -1219,7 +1219,7 @@ class Intra extends FlxGame {
}
if(FlxG.keys.justPressed("S")){
for(var i:Int=11;i<=Registry.IDX_WHITE;i++){
for(i in 11...Registry.IDX_WHITE+1){
Registry.inventory[i]=true;
}
}

View File

@ -189,7 +189,7 @@ class Save {
if(ref[0]===false){
if(old.length<ref.length){
trace("Array with falses in save was shorter than in disk");
for(var j:Int=old.length;j<ref.length;j++){
for(j in old.length...ref.length){
old.push(false);
}
}

View File

@ -1,5 +1,5 @@
package data
{
package data ;
import helper.Cutscene;
import org.flixel.FlxG;
import org.flixel.FlxGroup;
@ -531,7 +531,7 @@ class SoundData
teleguy_down.loadEmbedded(embed_teleguy_down);
teleguy_up.loadEmbedded(embed_teleguy_up);
gasguy_shoot.loadEmbedded(embed_gasguy_shoot);
init_sound_group(gasguy_move, embed_gasguy_move)
init_sound_group(gasguy_move, embed_gasguy_move);
init_sound_group(rat_move, embed_rat_move);
sb_split.loadEmbedded(embed_sb_split);
@ -608,7 +608,7 @@ class SoundData
}
public function init_multi_sound_group(g:FlxGroup, sounds:Array, looped:Bool=false, volume:Float=1):Void {
for(var sound:Class in sounds){
for(sound in sounds){
var s:FlxSound=new FlxSound;
s.loadEmbedded(sound, looped, volume);
g.add(s);

View File

@ -733,7 +733,7 @@ class TileData
curMapBuf.setTileProperties(20, FlxObject.NONE, TileData.conveyer);
curMapBuf.setTileProperties(21, FlxObject.ANY, null, null, 3);
curMapBuf.setTileProperties(32, FlxObject.NONE, TileData.spike, Player);
for(j in 36...=48){
for(j in 36...49){
curMapBuf.setTileProperties(j, FlxObject.NONE);
}
HOLE_INDICES.push(9);
@ -1141,7 +1141,7 @@ class TileData
} else if(p.cid==CLASS_ID.SILVERFISH){
if((p.y<ty + 4)&&(p.y + p.height>ty)&&
(p.x<tx + 6)&&(p.x + p.width>tx)){
p.xml.@alive="false";
p.xml.alive="false";
Registry.GRID_ENEMIES_DEAD++;
p.exists=false;
}
@ -1149,7 +1149,7 @@ class TileData
if((p.y<ty + 11)&&(p.y + p.height>ty)&&
(p.x<tx + 8)&&(p.x + p.width>tx)){
p.xml.@alive="false";
p.xml.alive="false";
Registry.GRID_ENEMIES_DEAD++;
p.exists=false;
}
@ -1161,7 +1161,7 @@ class TileData
p.velocity.y *=0.25;
if((p.y<ty + 4)&&(p.y + p.height>ty)&&
(p.x<tx + 6)&&(p.x + p.width>tx)){
p.xml.@alive="false";
p.xml.alive="false";
Registry.GRID_ENEMIES_DEAD++;
p.exists=false;
}

View File

@ -1,5 +1,5 @@
package global
{
package global ;
/**
* ...
* @author seaga
@ -11,7 +11,7 @@ import flash.accessibility.AccessibilityImplementation;
import flash.display.BitmapData;
import flash.geom.Point;
import flash.media.Sound;
import flash.utils.ByteArray<Dynamic>;
import flash.utils.ByteArray;
import global.Keys;
import helper.DH;
import helper.Joypad_Config_Group;
@ -463,7 +463,7 @@ public static function embed2saveXML():Void {
var x:Int;var grid_x:Int;
var y:Int;var grid_y:Int;
var ba:ByteArray<Dynamic>=new ByteArray();
embedXML=new XML(new EmbedXML);
embedXML=new XML(new EmbedXML());
RAW_STATEFUL=<root></root>;
RAW_STATELESS=<root></root>;
statelessXML=<root></root>;
@ -473,23 +473,23 @@ public static function embed2saveXML():Void {
for(map in embedXML.map){
newMap=<map/>;
newMap.@name=map.@name;
newMap.@type=map.@type;
newMap.name=map.name;
newMap.type=map.type;
// These are all the DAME objects.
for(o in map.*){
for(o in map){
//convert XY Into Grid X,Y.
x=parseInt(o.@x);
y=parseInt(o.@y);
x=parseInt(o.x);
y=parseInt(o.y);
grid_x=x / Registry.SCREEN_WIDTH_IN_PIXELS;
grid_y=y / Registry.SCREEN_HEIGHT_IN_PIXELS;
y +=Registry.HEADER_HEIGHT;
if(o.name()=="Door"){
Registry.DOOR_INFO[parseInt(o.@frame)].push(new Array(x, y, newMap.@name));
Registry.DOOR_INFO[parseInt(o.frame)].push(new Array(x, y, newMap.name));
}
// Append the object "o" to the grid node if it already exists.
grid_exists=false;
for(grid in newMap.grid){
if(grid.@grid_x==grid_x.toString()&& grid.@grid_y==grid_y.toString()){
if(grid.grid_x==grid_x.toString()&& grid.grid_y==grid_y.toString()){
grid.appendChild(o);
grid_exists=true;
break;
@ -498,8 +498,8 @@ public static function embed2saveXML():Void {
// Otherwise, create a new grid node and append "o" to it.
if(!grid_exists){
grid=<grid/>;
grid.@grid_x=grid_x.toString();
grid.@grid_y=grid_y.toString();
grid.grid_x=grid_x.toString();
grid.grid_y=grid_y.toString();
grid.appendChild(o);
newMap.appendChild(grid);
}
@ -511,11 +511,11 @@ public static function embed2saveXML():Void {
ba.clear();
ba.writeObject(newMap);
ba.position=0;
if(newMap.@type=="Stateless"){
RAW_STATELESS.appendChild(ba.readObject()as XML);
if(newMap.type=="Stateless"){
RAW_STATELESS.appendChild(ba.readObject());
statelessXML.appendChild(newMap);
} else {
RAW_STATEFUL.appendChild(ba.readObject()as XML);
RAW_STATEFUL.appendChild(ba.readObject());
statefulXML.appendChild(newMap);
}
@ -567,7 +567,7 @@ private static function patch_some_tree(disk:XML,save:XML):Void {
for(map in disk.map){
for(s_map in save.map){
if(s_map.@name.toXMLString()==map.@name.toXMLString()){
if(s_map.name.toXMLString()==map.name.toXMLString()){
found_map_match=true;
break;
}
@ -584,8 +584,8 @@ private static function patch_some_tree(disk:XML,save:XML):Void {
// We assume maps won't change size(God help us)
for(grid in map.grid){
for(s_grid in s_map.grid){
if(s_grid.@grid_x.toXMLString()==grid.@grid_x.toXMLString()&&
s_grid.@grid_y.toXMLString()==grid.@grid_y.toXMLString()){
if(s_grid.grid_x.toXMLString()==grid.grid_x.toXMLString()&&
s_grid.grid_y.toXMLString()==grid.grid_y.toXMLString()){
foundgridmatch=true;
break;
}
@ -593,24 +593,24 @@ private static function patch_some_tree(disk:XML,save:XML):Void {
if(foundgridmatch==false){
s_grid=<grid />;
s_grid.@grid_x=grid.@grid_x.toXMLString();
s_grid.@grid_y=grid.@grid_y.toXMLString();
s_grid.grid_x=grid.grid_x.toXMLString();
s_grid.grid_y=grid.grid_y.toXMLString();
}
// Look for DISK objs not in SAVE.
for(i in 0...grid.child("*").length()){
o=grid.child("*")[i];
guid=o.@guid.toXMLString();
guid=o.guid.toXMLString();
for(j in 0...s_grid.child("*").length()){
// If we find a match, then the SAVE obj should have its
// xy-coords the same as the DISK obj
if(guid==s_grid.child("*")[j].@guid.toXMLString()){
if(guid==s_grid.child("*")[j].guid.toXMLString()){
found_obj_match=true;
if(s_grid.child("*")[j].@x !=o.@x || s_grid.child("*")[j].@y !=o.@y){
if(s_grid.child("*")[j].x !=o.x || s_grid.child("*")[j].y !=o.y){
if(debug)trace("_----------------");
if(debug)trace("OLD " + s_grid.child("*")[j].toXMLString());
s_grid.child("*")[j].@x=o.@x;
s_grid.child("*")[j].@y=o.@y;
s_grid.child("*")[j].x=o.x;
s_grid.child("*")[j].y=o.y;
if(debug)trace("WHOA SHIT. CHANGING X AND Y:" + s_grid.child("*")[j].toXMLString());
}
break;
@ -623,16 +623,16 @@ private static function patch_some_tree(disk:XML,save:XML):Void {
ba.position=0;
ba.writeObject(o);
ba.position=0;
s_grid.appendChild(ba.readObject()as XML);
s_grid.appendChild(ba.readObject());
if(debug)trace("ADDING OBJ "+o.toXMLString()+"TO SAVE STATEFUL");
if(debug)trace(s_grid.toXMLString());
}
found_obj_match=false;
}
if(s_map.@name.toXMLString()=="BEACH"){
if(s_map.name.toXMLString()=="BEACH"){
var a:Int=3;
if(s_grid.@grid_x.toXMLString()=="8" && s_grid.@grid_y.toXMLString()=="3"){
if(s_grid.grid_x.toXMLString()=="8" && s_grid.grid_y.toXMLString()=="3"){
}
a +=2;
@ -641,16 +641,16 @@ private static function patch_some_tree(disk:XML,save:XML):Void {
// look for SAVE objs not in DISK
for(i in 0...s_grid.child("*").length()){
o=s_grid.child("*")[i];
guid=o.@guid.toXMLString();
guid=o.guid.toXMLString();
for(j in 0...grid.child("*").length()){
if(guid==grid.child("*")[j].@guid.toXMLString()){
if(guid==grid.child("*")[j].guid.toXMLString()){
found_obj_match=true;
}
}
// If no match found in DISK, remove from SAVE
if(false==found_obj_match){
if(debug)trace("REMOVING OBJ"+o.toXMLString()+"FROM SAVE STATEFUL");
delete s_grid.child("*").(@guid==guid)[0];//fuck there is no way this works
//FIXME(haxe) delete s_grid.child("*").(guid==guid)[0];//fuck there is no way this works
if(debug)trace(s_grid.toXMLString());
}
found_obj_match=false;
@ -661,7 +661,7 @@ private static function patch_some_tree(disk:XML,save:XML):Void {
ba.position=0;
ba.writeObject(s_grid);
ba.position=0;
s_map.appendChild(ba.readObject()as XML);
s_map.appendChild(ba.readObject());
}
foundgridmatch=false;
}
@ -674,7 +674,7 @@ private static function patch_some_tree(disk:XML,save:XML):Void {
for(s_map in save.map){
for(map in disk.map){
if(s_map.@name.toXMLString()==map.@name.toXMLString()){
if(s_map.name.toXMLString()==map.name.toXMLString()){
found_map_match=true;
break;
}
@ -686,16 +686,16 @@ private static function patch_some_tree(disk:XML,save:XML):Void {
for(s_grid in s_map.grid){
for(grid in map.grid){
if(s_grid.@grid_x.toXMLString()==grid.@grid_x.toXMLString()&&
s_grid.@grid_y.toXMLString()==grid.@grid_y.toXMLString()){
if(s_grid.grid_x.toXMLString()==grid.grid_x.toXMLString()&&
s_grid.grid_y.toXMLString()==grid.grid_y.toXMLString()){
foundgridmatch=true;
break;
}
}
// DELETE ERRTHANG
if(foundgridmatch==false){
if(debug)trace("ALLEGEDLY DELETING GHOST GRID",s_map.@name.toXMLString(), s_grid);
delete s_map.child("*").(@grid_x==s_grid.@grid_x && @grid_y==s_grid.@grid_y)[0];
if(debug)trace("ALLEGEDLY DELETING GHOST GRID",s_map.name.toXMLString(), s_grid);
//FIXME(haxe)delete s_map.child("*").(grid_x==s_grid.grid_x && grid_y==s_grid.grid_y)[0];
}
foundgridmatch=false;
}

View File

@ -122,7 +122,7 @@ class Achievements
if(Registry.inventory[Registry.IDX_JUMP])rate +=2;
for(i in 11...=Registry.IDX_WHITE){
for(i in 11...Registry.IDX_WHITE+1){
if(Registry.inventory[i]){
rate +=4;
}

View File

@ -350,7 +350,7 @@ class Cutscene extends PushableFlxState
var tilemap:FlxTilemap=new FlxTilemap();
tilemap.loadMap(CSV, tileset, 16, 16);
var submap_data:Array<Dynamic>=new Array();
for(var i:Int=0;i<w*h;i++){
for(i in 0...w*h){
submap_data.push(tilemap.getTile(gx * 10 +(i % w), gy * 10 +(i / h)));
}
tilemap.destroy();

View File

@ -104,7 +104,7 @@ class ScreenFade
private function fx_rect(rate:Int):Int {
for(var i:Int=offset;i<offset + rate;i++){
for(i in offset...offset + rate){
for(j in 0...base.width){
base.setPixel32(j, i, 0xff000000);
}
@ -125,8 +125,8 @@ class ScreenFade
for(y in 0...height +=stride){
for(x in 0...width +=stride){
next_color=thing_to_draw.bitmapData.getPixel32(x,y);
for(var _x:Int=x;_x<x + stride;_x++){
for(var _y:Int=y;_y<y + stride;_y++){
for(_x in x...x + stride){
for(_y in y...y + stride){
thing_to_draw.bitmapData.setPixel32(_x, _y, next_color);
}
}
@ -152,8 +152,8 @@ class ScreenFade
for(y in 0...buf.height +=stride){
for(x in 0...buf.width +=stride){
next_color=buf.getPixel32(x,y);
for(var _x:Int=x;_x<x + stride;_x++){
for(var _y:Int=y;_y<y + stride;_y++){
for(_x in x...x + stride){
for(_y in y...y + stride){
buf.setPixel32(_x, _y, next_color);
}
}

View File

@ -153,7 +153,7 @@ class Save {
if(ref[0]===false){
if(old.length<ref.length){
trace("Array with falses in save was shorter than in disk");
for(var j:Int=old.length;j<ref.length;j++){
for(j in old.length...ref.length){
old.push(false);
}
}

View File

@ -1,5 +1,5 @@
package org.flixel
{
package org.flixel ;
import entity.player.Player;
import flash.geom.Point;
import global.Registry;

View File

@ -76,7 +76,7 @@ class FlxGradient
ratio.push(0);
for(var ri:Int=1;ri<colors.length - 1;ri++)
for(ri in 1...colors.length - 1)
{
ratio.push(ri * spread);
}

View File

@ -128,7 +128,7 @@ class PNGEncoder
var e:Int=png.position;
png.position=p;
c=0xffffffff;
for(var i:Int=0;i<(e-p);i++){
for(i in 0...(e-p)){
c=uint(crcTable[
(c ^ png.readUnsignedByte())&
uint(0xff)] ^ Int(c>>>8));

View File

@ -217,7 +217,7 @@ class MinimapState extends PushableFlxState
private function update_map():Void
{
for(var i:Int=0;i<minimap.widthInTiles * minimap.heightInTiles;i++){
for(i in 0...minimap.widthInTiles * minimap.heightInTiles){
if(1 !=visited[Registry.CURRENT_MAP_NAME][i]){
minimap.setTileByIndex(i, blank_tile_index, true);
}

View File

@ -520,7 +520,7 @@ class RoamState extends FlxState
var prev_len:Int=entities.length;
for(var grid:XML in xml){
if(load_all ||(parseInt(grid.@grid_x)==gx && parseInt(grid.@grid_y)==gy)){
for(var i:Int=0;i<grid.child("*").length();i++){
for(i in 0...grid.child("*").length()){
SpriteFactory.makeSprite(grid.child("*")[i], i, entities, entities, player, this, darkness);
if(entities.length !=prev_len){
while(prev_len<entities.length){