#TouhouDanmakufu[Stage]
#Title[Ikareimu]
#Player[player\Ikareimu\Ikareimu.dnh]
#ScriptVersion[2]

script_stage_main
{
  #include_function "script\Ikareimu\MainMenu.dnh"
  #include_function "script\Ikareimu\Stage1.dnh"
  #include_function "script\Ikareimu\Stage2.dnh"
  #include_function "script\Ikareimu\Stage3.dnh"
  #include_function "script\Ikareimu\Stage4.dnh"
  #include_function "script\Ikareimu\Stage5.dnh"
  #include_function "script\Ikareimu\Stage6.dnh"
  #include_function "script\Ikareimu\Credits.dnh"
  #include_function "script\Ikareimu\Extra.dnh"
  
  task GameManager {
    MainMenu;
    SetCommonData("gameevent", "wait");
    SetCommonData("gamestate", "mainMenu");
    loop {
      while(GetCommonData("gameevent") == "wait"){
        yield ;
      }
      if(GetCommonData("gameevent") == "stage1"){
        SetCommonData("gameevent", "wait");
        SetCommonData("gamestate", "stage1");
        Stage1;
      }
      if(GetCommonData("gameevent") == "stage2"){
        SetCommonData("gameevent", "wait");
        SetCommonData("gamestate", "stage2");
        Stage2;
      }
      if(GetCommonData("gameevent") == "stage3"){
        SetCommonData("gameevent", "wait");
        SetCommonData("gamestate", "stage3");
        Stage3;
      }
      if(GetCommonData("gameevent") == "stage4"){
        SetCommonData("gameevent", "wait");
        SetCommonData("gamestate", "stage4");
        Stage4;
      }
      if(GetCommonData("gameevent") == "stage5"){
        SetCommonData("gameevent", "wait");
        SetCommonData("gamestate", "stage5");
        Stage5;
      }
      if(GetCommonData("gameevent") == "stage6"){
        SetCommonData("gameevent", "wait");
        SetCommonData("gamestate", "stage6");
        Stage6;
      }
      if(GetCommonData("gameevent") == "credits"){
        SetCommonData("gameevent", "wait");
        SetCommonData("gamestate", "credits");
        Credits;
      }
      if(GetCommonData("gameevent") == "stageExtra"){
        SetCommonData("gameevent", "wait");
        SetCommonData("gamestate", "extra");
        Extra;
      }
      if(GetCommonData("gameevent") == "clear"){
        Clear;
        return ;
      }
    }
  }
  
  @Initialize	{
    if(IsReplay){
      LoadCommonDataFromReplayFile;
      CreateCommonDataArea("options");
      CreateCommonDataArea("unlockables");
    }
    else {
      LoadCommonData;
      CreateCommonDataArea("options");
      CreateCommonDataArea("unlockables");
      if(GetCommonDataDefault("played", 0)==0){
        SaveCommonDataEx("options", "script\Ikareimu\data\options.dat");
        SaveCommonDataEx("unlockables", "script\Ikareimu\data\unlockables.dat");
      }
      else {
        LoadCommonDataEx("options", "script\Ikareimu\data\options.dat");
        LoadCommonDataEx("unlockables", "script\Ikareimu\data\unlockables.dat");
      }
      SetCommonData("played", GetCommonDataDefault("played", 0)+1);
      SaveCommonData;
    }
    SetClearFrameEffectEnable(false);
    GameManager;
  }
  
  @MainLoop {
    bgcounter-=bgspeed;
    yield;
  }
  
  @Finalize {
    
  }

  @BackGround {
    Stage1BG;
    Stage2BG;
    Stage3BG;
    Stage4BG;
    Stage5BG;
    Stage6BG;
    ExtraBG;
    DrawCredits;
  }
}