anodyne/intra/source/global/Registry.hx

795 lines
58 KiB
Haxe
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package global ;
/**
* ...
* @author seaga
*/
import data.SoundData;
import entity.decoration.Map_Preview;
import entity.interactive.npc.Trade_NPC;
import flash.accessibility.AccessibilityImplementation;
import flash.display.BitmapData;
import flash.geom.Point;
import flash.media.Sound;
import flash.utils.ByteArray;
import global.Keys;
import helper.DH;
import helper.Joypad_Config_Group;
import org.flixel.FlxGroup;
import org.flixel.FlxSprite;
import states.PlayState;
import states.RoamState;
class Registry {
public static var MOBILE_ASK_TO_EXIT_WITH_BACK:Bool=false;
public static var MOBILE_OKAY_TO_EXIT_WITH_BACK:Bool=false;
public static var FUCK_IT_MODE_ON:Bool=false;
/* game constants */
public static inline var MAX_DOOR_PAIRS:Int=95;
public static var DOOR_REFS:Array<Dynamic>=new Array();
public static var DOOR_INFO:Array<Dynamic>=new Array(MAX_DOOR_PAIRS);
public static inline var SCREEN_WIDTH_IN_TILES:Int=10;
public static inline var SCREEN_HEIGHT_IN_TILES:Int=10;
public static inline var TILE_WIDTH:Int=16;
public static inline var TILE_HEIGHT:Int=16;
public static inline var SCREEN_WIDTH_IN_PIXELS:Int=160;
public static inline var SCREEN_HEIGHT_IN_PIXELS:Int=160;
public static inline var HEADER_HEIGHT:Int=20;//Height of header. Needed in screen scrolling
public static var SAVE_NAME:String="ANODYNE_SAVE_123";
public static var DIALOGUE:Dynamic;
public static var DIALOGUE_STATE:Dynamic;
public static inline var DUNGEON_ENTRANCES:Dynamic={ STREET:new Point(232, 737), BEDROOM:new Point(400, 765), REDCAVE:new Point(555, 764), CROWD:new Point(555, 1239), APARTMENT:new Point(391, 911), HOTEL:new Point(394, 440), CIRCUS:new Point(715, 1396), NEXUS:new Point(710,1090)};
/* Global state */
public static var BOI:Bool=false;// BOI Sprites on in easter egg redcave
public static var is_playstate:Bool=true;
public static var volume_scale:Float=1.0;
public static var pillar_switch_state:Bool=false;//Reset when entering a map with differentname
public static var ENTRANCE_GRID_X:Int;
public static var ENTRANCE_GRID_Y:Int;
public static var ENTRANCE_PLAYER_X:Int;
public static var ENTRANCE_PLAYER_Y:Int;
public static var PLAYER_X:Int;
public static var PLAYER_Y:Int;
public static var CURRENT_GRID_X:Int;
public static var CURRENT_GRID_Y:Int;
public static var autosave_on:Bool=true;
public static var checkpoint:Dynamic={ x:0, y:0, area:"" };
public static var cur_dialogue:String;
/**
* Used for disabling the menu during an event because you could potentially break the game otherwise
*/
public static var disable_menu:Bool=false;
/* Grid-local state that needs to be accessed globally for events */
public static var GRID_ENEMIES_DEAD:Int=0;
public static var GRID_PUZZLES_DONE:Int=0;
/* Subgroups, speeds collisions */
public static var subgroup_dust:Array<Dynamic>=new Array();
public static var subgroup_propelled:Array<Dynamic>=new Array();
public static var subgroup_interactives:Array<Dynamic>=new Array();
public static var subgroup_on_off_lasers:Array<Dynamic>=new Array();
public static var subgroup_switch_pillars:Array<Dynamic>=new Array();
public static var subgroup_gates:Array<Dynamic>=new Array();
public static var subgroup_dash_traps:Array<Dynamic>=new Array();
public static var subgroup_gas:Array<Dynamic>=new Array();
public static var subgroup_spike_rollers:Array<Dynamic>=new Array();
public static var subgroup_destroyems:Array<Dynamic>=new Array();
/* Input, sound, state entities */
public static var keywatch:Keys;
public static var sound_data:SoundData=null;
public static var GAMESTATE:Dynamic=null;
public static var PLAYSTATE:PlayState;
//public static var ROAMSTATE:RoamState;
public static var NEXT_MAP_NAME:String="";
/* Sprite hit return values */
public static var HIT_NORMAL:Int=0;
public static var HIT_KEY:Int=1;
/**********************
/* START EVENTS ******
* *******************/
/* Get the broom */
public static var EVENT_OPEN_BROOM:Bool=false;
/* Upgrade health */
public static var EVENT_EXTEND_HEALTH:Bool=false;
public static var EVENT_OSCILLATE_DARKNESS_ALPHA:Bool=false;
/* If set in a grid, alpha is changed to target value and then these values are set to 0 */
public static var EVENT_CHANGE_DARKNESS_ALPHA:Bool=false;
public static var EVENT_CHANGE_DARKNESS_ALPHA_TARGET:Float=0;
public static var EVENT_CHANGE_VOLUME_SCALE:Bool=false;
public static var EVENT_CHANGE_VOLUME_SCALE_TARGET:Float=1.0;
public static var E_FADE_AND_SWITCH:Bool=false;
public static var E_FADE_AND_SWITCH_SONG:String=" ";
public static var E_FADED:Bool=false;
public static var E_NEXT_MAP_DARKNESS_8:Bool=false;
public static var E_NEXT_MAP_NO_STATIC:Bool=false;
public static var E_NEXT_MAP_TURN_ON_LIGHT:Bool=false;
public static var EVENT_LEARN_TO_EQUIP:Bool=false;
public static var EVENT_TELEPORT_DOWN_SOUND:Bool=false;
public static var E_Enter_Whirlpool_Down:Bool=false;
public static var E_Enter_Fall_Down:Bool=false;
public static var E_Blank_Fade:Bool=false;
public static var E_Transformer_On:Bool=false;
public static var E_Transformer_Off:Bool=false;
public static var E_Dialogue_Just_Finished:Bool=false;
public static var E_DESTROY_PLAYSTATE:Bool=false;
/**
* The next map load will play the roof song
*/
public static var E_PLAY_ROOF:Bool=false;
/**
* If the cur and next map are the same, then restart the song anyways
*/
public static var E_OVERRIDE_SAME_MAP_SONG:Bool=false;
/* Elevator in HOTEL */
public static var E_From_Elevator:Bool=false;
public static var GFX_WAVE_EFFECT_ON:Bool=false;
public static var GFX_WAVE_EFFECT_START:Float=0;
public static var GFX_WAVE_TABLE:Array<Dynamic>=new Array(-3,-2,-1,0,1,2,3,2,1,0,-1,-2);
public static var GFX_WAVE_TABLE_INDEX:Int=0;
public static var GFX_WAVE_EFFECT_FREQ:Int=0;
public static var GFX_WAVE_TABLE_ROLLOVER:Int=0;
public static var GFX_BUFFER:BitmapData=new BitmapData(160, 180, true);
public static var EVENT_FADE_BEGUN:Bool=false;
public static var EVENT_FADE_OVER:Bool=false;
public static var CURRENT_CUTSCENE:Int;
public static var E_Load_Cutscene:Bool=false;
/**********************
/* END EVENTS ******
* *******************/
/* font */
//[Embed(source="../res/font/font-black.png")] public static var C_FONT_BLACK:Class;
//[Embed(source="../res/font/font-black-apple-7x8.png")] public static var C_FONT_APPLE_BLACK:Class;
//[Embed(source="../res/font/font-white-apple-7x8.png")] public static var C_FONT_APPLE_WHITE:Class;
//[Embed(source="../res/font/jp_white.png")] public static var C_FONT_JP_WHITE:Class;
//[Embed(source="../res/font/kr_white.png")] public static var C_FONT_KO_WHITE:Class;
//[Embed(source="../res/font/11x12_ZHS.png")] public static var C_FONT_ZHS_WHITE:Class;
//[Embed(source="../res/font/es_white.png")] public static var C_FONT_ES_WHITE:Class;// also for pt-br
////[Embed(source="../res/font/jp_white_test.png")] public static var C_FONT_JP_WHITE:Class;
public static var C_FONT_BLACK_STRING:String="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890.:,;'\"(!?)+-*/=[]";
public static var C_FONT_APPLE_BLACK_STRING:String="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.:,;\'\"(!?)+-*/=$]";
public static var C_FONT_APPLE_WHITE_STRING:String="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.:,;\'\"(!?)+-*/=$]";
public static var FONT_cpl:Int=27;
public static var FONT_w:Int=8;
public static var FONT_h:Int=8;
public static var APPLE_FONT_w:Int=7;
/* base xml of the game */
//[Embed(source='../xml/Intra.xml', mimeType="application/octet-stream")] private static inline var EmbedXML:Class;
public static var embedXML:XML;
/* These refer to the serialized inventory array which stores the state of having an item */
public static inline var IDX_BROOM:Int=0;
public static inline var IDX_JUMP:Int=1;
public static inline var IDX_TRANSFORMER:Int=2;
public static inline var IDX_WIDEN:Int=4;
public static inline var IDX_LENGTHEN:Int=5;
public static inline var IDX_GREEN_KEY:Int=6;
public static inline var IDX_RED_KEY:Int=7;
public static inline var IDX_BLUE_KEY:Int=8;
public static inline var IDX_BOX:Int=9;
public static inline var IDX_BIKE_SHOES:Int=10;
public static inline var IDX_POO:Int=11;
public static inline var IDX_SPAM:Int=12;
public static inline var IDX_MISSINGNO:Int=13;
public static inline var IDX_AUS_HEART:Int=14;
public static inline var IDX_ELECTRIC:Int=15;
public static inline var IDX_KITTY:Int=16;
public static inline var IDX_MELOS:Int=17;
public static inline var IDX_MARINA:Int=18;
public static inline var IDX_BLACK:Int=19;
public static inline var IDX_RED:Int=20;
public static inline var IDX_GREEN:Int=21;
public static inline var IDX_BLUE:Int=22;
public static inline var IDX_WHITE:Int=23;
public static inline var item_names:Array<Dynamic>=new Array("BROOM","JUMP","TRANSFORMER","BAR","WIDEN","LENGTHEN","keyg","keyr","keyb","box","bikeshoes","poo","spam","missingno","ausheart","electric","kitty");
public static inline var default_controls:Array<Dynamic>=new Array("UP", "DOWN", "LEFT", "RIGHT", "C", "X", "Z", "ENTER");
private static var RAW_STATEFUL:XML;
private static var RAW_STATELESS:XML;
/** BEGIN SERIALIZED **/
public static var statefulXML:XML;// Represents things that need to keep state - bosses, etc
public static var statelessXML:XML;// Things that don't need state - breakables, torches, blah blah blah
public static var controls:Array<Dynamic>=new Array("UP", "DOWN", "LEFT", "RIGHT", "C", "X", "Z", "ENTER");// Array of control bindings
//public static var controls=new Array("UP","DOWN","LEFT","RIGHT","ENTER","OUYA_A","Z","OUYA_START");
public static var joybinds:Array<Dynamic>=new Array(0,0,0,0,0,0,0,0);
public static var inventory:Array<Dynamic>=new Array(
false, false, false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false, false, false);
public static var achivement_state:Array<Dynamic>=new Array(
false, false, false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false, false, false
);
public static var modified_mobile_landscape:Bool=false;
public static var modified_mobile_portrait:Bool=false;
public static var death_count:Int=0;
public static var nr_growths:Int;
public static inline var CARD_GOLDMAN_IDX:Int=43;
public static var card_states:Array<Dynamic>=new Array(
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0);
public static var CURRENT_MAP_NAME:String="";
public static var bound_item_1:String;
public static var bound_item_2:String;
public static var bound_effect:String;
public static var playtime:Int=0;
public static var nr_keys:Array<Dynamic>=new Array(0, 0, 0, 0, 0, 0, 0, 0);//keys in get_nr_keys
public static var CUR_HEALTH:Int;
public static var MAX_HEALTH:Int;
//indexed by constants in Cutscene.as
public static var CUTSCENES_PLAYED:Array<Dynamic>=new Array(0, 0, 0, 0, 0, 0,0,0,0,0,0);
// Whether or not this big door has been opened. Keys stored in BIG_DOOR.
public static var Big_Door_State:Array<Dynamic>=new Array(false, false, false, false);
// Whether or not this nexus door is open on the nexus side. Keys in Door.as
// Street vlaue always true
public static var Nexus_Door_State:Array<Dynamic>=new Array(false, true, false, false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false);
public static var Big_Door_Reqs:Array<Dynamic>=new Array(1, 3,10,15,20,25,32);
public static var Event_Nr_Red_Pillars_Broken:Int=0;
public static var Event_Biofilm_Broken:Bool=false;
public static var Event_Nr_Suburb_Killed:Int=0;
/*
* An array holding state of events in the game - boss deaths, cutscenes(if any)
* */
public static var GE_States:Array<Dynamic>=new Array(
false, false, false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false, false, false,
false, false, false, false, false);//45
public static inline var GE_Bedroom_Boss_Dead_Idx:Int=0;
public static inline var GE_Redcave_Boss_Dead_Idx:Int=1;
public static inline var GE_Crowd_Boss_Dead_Idx:Int=2;
public static inline var GE_Apartment_Boss_Dead_Idx:Int=3;
public static inline var GE_Hotel_Boss_Dead_Idx:Int=4;
public static inline var GE_Circus_Boss_Dead_Idx:Int=5;
public static inline var GE_Bedroom_Visited:Int=6;
public static inline var GE_Did_A_Checkpoint:Int=7;
public static inline var GE_Swept_Dust:Int=8;
public static inline var GE_Left_BDR_After_Boss_Dead:Int=9;
public static inline var GE_ent_str:Int=10;// entered street
public static inline var GE_Sage_Dead_Idx:Int=11;
public static inline var GE_Happy_Started:Int=12;
public static inline var GE_Left_RDC_After_Boss_Dead:Int=13;
public static inline var GE_Left_CRD_After_Boss_Dead:Int=14;
public static inline var GE_Finished_Game:Int=15;
public static inline var GE_Briar_Happy_Done:Int=16;
public static inline var GE_Briar_Blue_Done:Int=17;
public static inline var GE_MOBILE_IS_RHAND:Int=18;
public static inline var GE_MOBILE_IS_XC:Int=19;
public static inline var GE_BRIAR_BOSS_DEAD:Int=20;
// Whehter these NPCs have been talked to for the quest that
// gives the clue to the NW overworld room.
public static inline var GE_QUEST_MITRA:Int=21;
public static inline var GE_QUEST_CLIFF:Int=22;
public static inline var GE_QUEST_BEACH:Int=23;
public static inline var GE_QUEST_FOREST:Int=24;
public static inline var GE_QUEST_FIELDS:Int=25;
public static inline var GE_QUEST_CELL:Int=26;
public static inline var GE_QUEST_SUBURB:Int=27;
public static inline var GE_QUEST_SPACE:Int=28;
public static inline var GE_QUEST_GO:Int=29;
//
public static inline var GE_tradequestspookedmonster:Int=30;
public static inline var GE_tradequesthelpedmonster:Int=31;
public static inline var GE_tradequesthelpedshopkeeper:Int=32;
//
public static inline var GE_ENTERED_NEXUS_ONCE:Int=33;
public static inline var GE_go_mitra:Int=34;
public static inline var GE_got_all_cards_inanarea:Int=35;
public static inline var GE_ENTERED_BLUE_ONCE:Int=36;
public static inline var GE_HAVE_A_SECRET:Int=37;
public static inline var GE_DID_JOYPAD_CONFIG_ONCE:Int=38;
public static var joy_grp:Joypad_Config_Group;
/** END SERIALIZED **/
//1, 2, 3...
// Some XML that holds other data, but for now:
/** BEGIN HELPER FUNCTIONS **/
public static function all_bosses_dead():Bool {
var indices:Array<Dynamic>=new Array(GE_Apartment_Boss_Dead_Idx, GE_Bedroom_Boss_Dead_Idx, GE_Circus_Boss_Dead_Idx, GE_Crowd_Boss_Dead_Idx, GE_Hotel_Boss_Dead_Idx, GE_Redcave_Boss_Dead_Idx);
for(i in 0...6){
if(!GE_States[indices[i]])return false;
}
return true;
}
public static function set_all_bosses_dead():Void {
trace("Registry.as:set_all_bosses_dead");
var indices:Array<Dynamic>=new Array(GE_Apartment_Boss_Dead_Idx, GE_Bedroom_Boss_Dead_Idx, GE_Circus_Boss_Dead_Idx, GE_Crowd_Boss_Dead_Idx, GE_Hotel_Boss_Dead_Idx, GE_Redcave_Boss_Dead_Idx);
for(i in 0...6){
GE_States[indices[i]]=true;
}
}
public static function get_nr_keys():Int {
if(nr_keys==null)return 0;
if(CURRENT_MAP_NAME=="BEDROOM"){
return nr_keys[0];
} else if(CURRENT_MAP_NAME=="STREET"){
return nr_keys[1];
} else if(CURRENT_MAP_NAME=="REDCAVE"){
return nr_keys[2];
} else if(CURRENT_MAP_NAME=="CROWD"){
return nr_keys[3];
} else if(CURRENT_MAP_NAME=="APARTMENT"){
return nr_keys[4];
} else if(CURRENT_MAP_NAME=="HOTEL"){
return nr_keys[5];
} else if(CURRENT_MAP_NAME=="CIRCUS"){
return nr_keys[6];
} else {
return 0;
}
}
public static function change_nr_keys(amount:Int):Void {
if(CURRENT_MAP_NAME=="BEDROOM"){
nr_keys[0] +=amount;
} else if(CURRENT_MAP_NAME=="STREET"){
nr_keys[1] +=amount;
} else if(CURRENT_MAP_NAME=="REDCAVE"){
nr_keys[2] +=amount;
} else if(CURRENT_MAP_NAME=="CROWD"){
nr_keys[3] +=amount;
}else if(CURRENT_MAP_NAME=="APARTMENT"){
nr_keys[4] +=amount;
} else if(CURRENT_MAP_NAME=="HOTEL"){
nr_keys[5] +=amount;
} else if(CURRENT_MAP_NAME=="CIRCUS"){
nr_keys[6] +=amount;
}
}
public static function reset_events():Void {
EVENT_OPEN_BROOM=false;
EVENT_CHANGE_DARKNESS_ALPHA=false;
EVENT_OSCILLATE_DARKNESS_ALPHA=false;
EVENT_CHANGE_VOLUME_SCALE=false;
volume_scale=1;
E_Enter_Whirlpool_Down=false;
}
/**
* Clear out any groups of specific objects used to
* speed up collisions(e.g., subgroup of dusts)
*/
public static function reset_subgroups():Void {
var ctr:Int;
while(subgroup_dust.length>0){
subgroup_dust.pop();
}
while(subgroup_propelled.length>0){
subgroup_propelled.pop();
}
while(subgroup_interactives.length>0){
subgroup_interactives.pop();
}
while(subgroup_on_off_lasers.length>0){
subgroup_on_off_lasers.pop();
}
while(subgroup_switch_pillars.length>0){
subgroup_switch_pillars.pop();
}
while(subgroup_spike_rollers.length>0){
subgroup_spike_rollers.pop();
}
subgroup_spike_rollers=null;
subgroup_spike_rollers=new Array();
subgroup_gates=null;
subgroup_gates=new Array();
subgroup_dash_traps=null;
subgroup_dash_traps=new Array();
subgroup_gas=null;
subgroup_gas=new Array();
// SHOULD ALL BE ZEROS
trace(subgroup_dust.length, subgroup_propelled.length, subgroup_interactives.length, subgroup_on_off_lasers.length, subgroup_switch_pillars.length, subgroup_spike_rollers.length, subgroup_gates.length, subgroup_dash_traps.length, subgroup_gas.length);
}
public static function checkDoorInfo():Void {
var door_debug:Bool=false;
for(i in 0...DOOR_INFO.length){
if(DOOR_INFO[i].length !=0){
if(door_debug){
trace("DOOR PAIR ", i , ":");
trace(DOOR_INFO[i][0]);
if(DOOR_INFO[i][1] !=null){
trace(DOOR_INFO[i][1]);
}
}
}
}
}
// Changes the DAME-exported XML Into
// Something grid-related for our game.
public static function embed2saveXML():Void {
var newMap:XML;//Will be a map node for our stateless/ful XML tree.
var o:XML;//Generic object XML
var map:XML;//For each "level"(house/dungeon/whatever)
var grid:XML;//Represents a "grid"
var grid_exists:Bool;// Set to true when an existing grid is found
// while iterating through some level's grids
var name:String;
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());
RAW_STATEFUL=<root></root>;
RAW_STATELESS=<root></root>;
statelessXML=<root></root>;
statefulXML=<root></root>;
//Every level corresponds to a floor of a dungeon,
//a house, the world map, etc.
for(map in embedXML.map){
newMap=<map/>;
newMap.name=map.name;
newMap.type=map.type;
// These are all the DAME objects.
for(o in map){
//convert XY Into Grid X,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));
}
// 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()){
grid.appendChild(o);
grid_exists=true;
break;
}
}
// 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.appendChild(o);
newMap.appendChild(grid);
}
}
//Finally, append the transformed level node to the serialized XML.
// it's okay to just append references,
// because a save file will change the statelessXML ref
// This way we have a copy of what was in the game swf
ba.clear();
ba.writeObject(newMap);
ba.position=0;
if(newMap.type=="Stateless"){
RAW_STATELESS.appendChild(ba.readObject());
statelessXML.appendChild(newMap);
} else {
RAW_STATEFUL.appendChild(ba.readObject());
statefulXML.appendChild(newMap);
}
}
}
// Reads the embedded xml, compares it against the save file one.
public static function patch_xml(load:Dynamic):Void {
// First convert it Into a tree... poop!
if(RAW_STATEFUL !=null && RAW_STATELESS !=null){
patch_some_tree(RAW_STATEFUL, load.data.stateful);
patch_some_tree(RAW_STATELESS, load.data.stateless);
}
RAW_STATEFUL=null;
RAW_STATELESS=null;
}
private static function patch_some_tree(disk:XML,save:XML):Void {
// For each area
// For each grid:
// If SAVE has something but DISK doesn't, remove it from save.
// If DISK has something but SAVE doesn't, add to SAVE.
// Update SAVE's x,y to be DISK's x,y(I don't think I modify any object's x,y permanently? I hope o__o)
var map:XML;// Iterators for the children of root and maps
var s_map:XML;
var grid:XML;
var s_grid:XML;
var o:XML;//
var found_map_match:Bool=false;
var found_obj_match:Bool=false;
var guid:String;// A guid for a dame object
var debug:Bool=false;
var i:Int;// Iterators for objects in the grid xmls
var j:Int;
var ba:ByteArray<Dynamic>=new ByteArray();// resuable byte array for hard copying xml
var foundgridmatch:Bool=false;
if(debug)trace("Patching Stateful XML");
for(map in disk.map){
for(s_map in save.map){
if(s_map.name.toXMLString()==map.name.toXMLString()){
found_map_match=true;
break;
}
}
// If we don't have this map from disk in the save,
// then add it to the save and continue.
if(false==found_map_match){
save.appendChild(map);
if(debug)trace("added new map !**!*!*!*");
continue;
}
// Otherwise we do have it, so let's check its grids.
// 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()){
foundgridmatch=true;
break;
}
}
if(foundgridmatch==false){
s_grid=<grid />;
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();
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()){
found_obj_match=true;
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;
if(debug)trace("WHOA SHIT. CHANGING X AND Y:" + s_grid.child("*")[j].toXMLString());
}
break;
}
}
// If not found in SAVE, add to SAVE.
if(false==found_obj_match){
ba.clear();
ba.position=0;
ba.writeObject(o);
ba.position=0;
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"){
var a:Int=3;
if(s_grid.grid_x.toXMLString()=="8" && s_grid.grid_y.toXMLString()=="3"){
}
a +=2;
}
// look for SAVE objs not in DISK
for(i in 0...s_grid.child("*").length()){
o=s_grid.child("*")[i];
guid=o.guid.toXMLString();
for(j in 0...grid.child("*").length()){
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");
//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;
}
if(foundgridmatch==false){
ba.clear();
ba.position=0;
ba.writeObject(s_grid);
ba.position=0;
s_map.appendChild(ba.readObject());
}
foundgridmatch=false;
}
found_map_match=false;
}
// In case we have objects in a grid in the save
// that aren't in a grid in the disk(and thus weren't caught earlier)
// we remove them from the save here.
for(s_map in save.map){
for(map in disk.map){
if(s_map.name.toXMLString()==map.name.toXMLString()){
found_map_match=true;
break;
}
}
if(found_map_match==false){
continue;
}
found_map_match=false;
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()){
foundgridmatch=true;
break;
}
}
// DELETE ERRTHANG
if(foundgridmatch==false){
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;
}
}
}
/**
* sets is_playstate param based on the next map to be loaded.
* distinguishes between dungeon and free-roaming areas
* @param next_map_name
*/
public static function set_is_playstate(next_map_name:String):Void {
switch(next_map_name){
/*case "FIELDS":case "NEXUS":case "REDSEA":case "BEACH":
case "CLIFF":case "FOREST":case "CELL":case "TERMINAL":case "WINDMILL":
case "GO":case "HAPPY":case "BLUE":case "SUBURB":case "SPACE":
is_playstate=false;
trace("Loading map ", next_map_name, " it's a RoamState");
break;*/
default:
is_playstate=true;
break;
}
}
public static function destroy_destroyems():Void {
while(subgroup_destroyems.length>0){
var p:Dynamic=subgroup_destroyems.pop();
if(p !=null){
p.destroy();
}
}
}
public static function is_dungeon(n:String):Bool {
switch(n){
case "BEDROOM":
case "STREET":
case "REDCAVE":
case "CROWD":
case "APARTMENT":
case "HOTEL":
case "CIRCUS":
return true;
break;
default:
return false;
break;
}
}
public static function cleanup_on_map_change():Void
{
if(Trade_NPC.cat_ref !=null){
Registry.GAMESTATE.sortables.remove(Trade_NPC.cat_ref, true);
Registry.GAMESTATE.sortables.remove(Trade_NPC.cat_dust_ref, true);
Trade_NPC.cat_ref.destroy();
Trade_NPC.cat_ref=null;
Trade_NPC.cat_dust_ref.destroy();
Trade_NPC.cat_dust_ref=null;
}
Registry.volume_scale=1;
Registry.reset_events();
Registry.reset_subgroups();
//Event_Nr_Suburb_Killed=0;
// Reset other things?
DH.reset_scenes_on_map_change();
}
public static var es_string:String="ªÂâàÀáÁãÃçÇéÉêÊÍíóôÓÔõúÚüÜÑñabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.:,;\' \"(!?)+- */=$]¡¿ŒœËëÈèÎîÏïùÙìò";
public static var zhs_string:String="#=ENGLISHDAOU-CTRby./Jzfoucldmenthgisvrwa!\"'PKYWB:(k,)pM[]F4\\jq^_*?0123 456789xXV%>;+Q$使西殿穿便屿沿·退绿访湿线仿怀广";
public static var ko_string:String="굿귿꼿뀀릿믿퀀 !#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRS TUVWXYZ[ ]^_`abcdefghijklmnopqrstuvwxyz{|}~'\"";
//public static var jp_string:String="abcdefghijklmnopqrstuvwxyzぁ.......................";
// Note that the first line has whitespace - the ' ' one and the ' ' one
public static var jp_string:String="  丿使便姿婿宿寿尿广廿彿忿椿榿槿橿歿殿沿湿滿漿祿禿稿穿窿竿簿紿綿繿耀西覿調谿貿跿輿辿退駿鴿鹿麿!#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[ ]^_`abcdefghijklmnopqrstuvwxyz{|}~'\"";
}