I believe I’ve completed mapping the various load/save scenarios to codepaths.  Definitely need to vet this out a bit before coding it up :P.  The following isn’t clearly communicated, but it does convey the scope of the challenge…

Scenario

Code Path

Enter dungeon for first time or re-enter a Dungeon at the first level (e.g. after dying or re-entering old dungeon after exiting or winning it) Dungeon.EnterDungeonForFirstTime() 

  • Call ClearDungeonLevels()
  • Call EnterLevelForFirstTime(1)
Exit (ascend to level 0) or win a dungeon Dungeon.ClearDungeonLevels() 

  • Delete all /<playerguid>/dungeon/* files
Player dies
Ascend or descend to an existing level within a dungeon (but not to the exit) Dungeon.AscendDescendToExistingLevel(int levelNum) 

  • Level.Persist() à /playerguid/dungeon/level-#.data
  • Call EnterExistingLevel(levelNum)
Ascend or Descend to a new level within a Dungeon (normally you just descend, but I may support upward dungeons – e.g. Tower). Dungeon.EnterLevelForFirstTime(int levelNum) 

  • Level.Persist() à /playerguid/dungeon/level-#.data
  • Generate the new level à Level.Generate()
  • Level.Persist() à /<playerguid>/dungeon/newlevel-#.data
  • CurrentPlayerData.Persist() à /<playerguid>/player.data

o    (Updates location to dungeon/level)

WP7: Pause within a dungeon (tombstone)
  • Persist GameState.name (for restoration purposes)
  • Level.Persist() à /playerguid/dungeon/level-#.data
  • CurrentPlayerData.Persist() à /<playerguid>/player.data
WP7: resume a gamed paused while in a Dungeon (detombstone) Dungeon.EnterExistingLevel(int levelNum) 

  • Level.Restore(“/<playerguid>/dungeon/newlevel-#.data”)
  • Fixup Player to Level
  • CurrentPlayerData.Persist() à /<playerguid>/player.data
  • Tbd: player.persist isn’t necessary for wp7 resume, but is for other instnaces of enterexistinglevel…
WP7/Win: launch from scratch (fresh-launch)
  • Goto Main menu state
WP7: Pause outside a dungeon (e.g. on worldmap or mainmenu)
  • Persist GameState.name (for restoration purposes)
  • State-specific persist (e.g. map scrollloc)
  • CurrentPlayerData.Persist() à /<playerguid>/player.data
WP7: Resume after pausing outside a dungeon (e.g. on worldmap or mainmenu)
  • State-specific restore (e.g. map scrollloc)

 

Windows: Exit the game while inside a dungeon
  • Level.Persist() à /playerguid/dungeon/level-#.data
  • CurrentPlayerData.Persist() à /<playerguid>/player.data
Windows: Exit the game while outside a dungeon (worldmap, mainmenu, …)
  • Persist stateenum
  • State-specific persist (e.g. map scrollloc)
Game constructor: Initialize (always run; before activation or Launch code) PlayerData.Initialize() 

  • Loads /players.data and gets the list of valid players and the id of the current (last played) player
  • Load player.data for current player (if any) à /<playerguid>/player.data
MainMenu: On create new player PlayerData.CreateNewPlayer() 

  • Generate Guid for new player
  • Create folder <playerguid>
  • Create folder <playerguid>/dungeon
  • Set currentplayerid to new playerguid
  • AllPlayerData.Persist() à stores current player id
  • CurrentplayerData.Persist() à /<playerguid>/player.data

o    Stores name, race, class, etc

Main Menu: On continue existing player that exited while in dungeon Dungeon.ReenterDungeonAtLevel(dungeonId, levelId) 

  • Currentplayer.EnterDungeon(dungeonId) à doesn’t enter level, just sets dungeon location
  • CurrentPlayer.CurrentDungeon.EnterExistingLevel(leveled);
Main Menu: On continue existing player that exited while out of dungeon
  • Read stateenum from playerdata
  • Do State-specific restore (e.g. map scrollloc)
Main Menu: Continue other existing player that was in dungeon
  • PlayerData.SetCurrentPlayer(playerId)
  • Dungeon.ReenterDungeonAtLevel(dungeonId, levelId);
Advertisements