#TouhouDanmakufu[Stage]
#Title[Touhou Bunkachou ~ Shoot the Bullet]
#Text[An easily customizable StB stage select menu engine.]
#Player[.\player\Aya\Aya.dnh]
#ScriptVersion[2]

script_stage_main {
  #include_function ".\menus.dnh"

  @Initialize {
    LoadImages;
    CreateMenus;
    SetClearFrameEffectEnable(false);
    if(!IsCommonDataAreaExists("temp")){
      CreateCommonDataArea("temp");
    }
  }

  @MainLoop {
    yield;
  }

  @BackGround {
    SetTexture(imgBlack);
    SetGraphicRect(0, 0, GetClipMaxX-GetClipMinX+2, GetClipMaxY-GetClipMinY+2);
    DrawGraphic(GetCenterX, GetCenterY);
  }

  @Finalize {
    DeleteImages;
  }

  sub LoadImages {
    ascent(i in 0..length(Images)){
      LoadGraphic(Images[i]);
    }
    LoadGraphic(GetCurrentScriptDirectory ~ "lib\DrawTextNew\text.png");
  }

  sub DeleteImages {
    ascent(i in 0..length(Images)){
      DeleteGraphic(Images[i]);
    }
    DeleteGraphic(GetCurrentScriptDirectory ~ "lib\DrawTextNew\text.png");
  }
  
  sub CheckConfigFiles {
    if(length(LevelsStringArray) != length(LevelsNumberArray)){
      RaiseError("The LevelsStringArray and LevelsNumberArray are not the same length.", "Config Error");
    }
    ascent(i in 0..length(LevelsStringArray)){
      if(length(LevelsStringArray[i]) != length(LevelsNumberArray[i])){
        RaiseError("One or more of your levels do not have matching length String and Number arrays.", "Config Error");
      }
      if(length(LevelsStringArray[i]) > 9){
        RaiseError("One or more of your levels have over 9 scenes in them. The maximum number of scenes per level is 9.", "Config Error");
      }
      if(length(LevelsStringArray[i]) == 0){
        RaiseError("One or more of your levels have no scenes in them. The minimum number of scenes per level is 1.", "Config Error");
      }
      ascent(j in 0..length(LevelsStringArray[i])){
        if(length(LevelsStringArray[i][j]) != 5){
          RaiseError("One or more of your scenes in the LevelsStringArray do not have the proper amount of elements.", "Config Error");
        }
        if(length(LevelsNumberArray[i][j]) != 3){
          RaiseError("One or more of your scenes in the LevelsNumberArray do not have the proper amount of elements.", "Config Error");
        }
      }
    }
  }

}