0

I'm guessing that the best way to do this is by using XML. Here's the issue, tho:

    Hero hero;
    PictureBox heroPB;
    Dictionary <string,Point> pokedex;
    Boss boss;
    PictureBox bossPB;
    Attack attack;
    PictureBox attackPB;
    HPMeter bossHP;
    PictureBox bossHPPB;
    PPMeter heroPP;
    PictureBox heroPPPB;

    System.Timers.Timer animateAttack;
    System.Timers.Timer animateBoss;
    System.Timers.Timer checkHit;
    System.Timers.Timer winFade;
    Thread tr;
    Rectangle bossRect;
    Rectangle attackRect;
    Panel whiteout;

    int heroState = 2;
    int stepRate = 5;
    int attackDirection;
    int attackLoop = 0;
    int contadorPaso = 0;
    int contadorPasoBoss = 0;
    int bossTop, bossLeft;
    int bossState = 6;
    int bossHealth = 0;
    int bossHPCap = 0;
    int opa = 0;
    int battlesWon = 0;
    int mainBossCounter = 0;
    int ppleft = 0;
    bool paso = false;
    bool inStadium = false;
    bool fading = true;
    bool fightingMainBoss = false;
    bool fainted;
    string currentPokemon = "";

    Rectangle[] frames;
    Rectangle[] entrances;
    PictureBox[] boundaries;
    Random r;
    Random eth;

    public delegate void BeginFade();
    BeginFade fade;

I have more than a few objects/primitives which are constantly changing. Is there an efficient way to serialize the whole thing and load it the next time the program runs?

OFRBG
  • 1,653
  • 14
  • 28
  • 2
    Why do you want to serialize the actual form? As long as you store all your data you shouldn't need the form. – Mike Parkhill Dec 14 '12 at 00:26
  • @MikeParkhill Because it would be the safest way to store data. I don't want to miss out anything during save AND load. – OFRBG Dec 14 '12 at 00:28
  • My two cents would be to refactor all your data into a master view model object which you could then save and load. As long as all your form elements bind to that object you'll be safe. – Mike Parkhill Dec 14 '12 at 00:31
  • I concur with @MikeParkhill, you will be much better served in the long run to store these values in a model object which can easily be persisted and rehydrated rather than storing the values in the form. That will be particularly apparent the first time you need to version the data to handle an update to the app. – hemp Dec 14 '12 at 00:33

1 Answers1

1

There's really no simple method to save this data. I personally don't think XML is the best route. It would be nice for the objects and bad for everything else. I'd be more inclined to write it as JSON with a "misc" object that has all the lone primitives. I'd actually be most inclined to make my own config file reader/writer and write something more like a csv. Most of the config files at my place of work have at least that much data. We use key=value for all the primitives. Each object would have it's own section where their primitives are listed in the key=value format and the lists would be key=value1,value2,value3. I personally think this is a fairly simple way to do things and writing the reader/writer class does not take very long. In fact, making a simple reader/writer from scratch would probably be faster than building one on top of a JSON or XML serialization class. I don't really see either of those formats benefiting you much here.

evanmcdonnal
  • 46,131
  • 16
  • 104
  • 115