/**
 * プレイデータのコモンデータ作成
 */
function CreatePlayDataArea(){
	let players = [ "Sunny", "Luna", "Star" ];
	let difficults = [ "Easy", "Normal", "Panic" ];
	//EXは4扱い、0はプレイ回数
	let stages = [ "0", "1", "2", "3", "4" ];
	
	//データ作成
	ascent( i in 0..length( players ) ){
		ascent( j in 0..length( difficults ) ){
			ascent( k in 0..length( stages ) ){
				let ns = players[ i ] ~ "PlayNum" ~ difficults[ j ] ~ stages[ k ];
				SetCommonDataEx( "OFT_Save", ns, 0 );
			}
		}
	}
	
	//プレイ時間
	SetCommonDataEx( "OFT_Save", "PlayTime_H", 0 );
	SetCommonDataEx( "OFT_Save", "PlayTime_M", 0 );
	SetCommonDataEx( "OFT_Save", "PlayTime_S", 0 );
	
	//クリア回数
	SetCommonDataEx( "OFT_Save", "SunnyClearNum", 0 );
	SetCommonDataEx( "OFT_Save", "LunaClearNum", 0 );
	SetCommonDataEx( "OFT_Save", "StarClearNum", 0 );
	
	//ノーコンクリア回数
	SetCommonDataEx( "OFT_Save", "SunnyNoContinueClearNum", 0 );
	SetCommonDataEx( "OFT_Save", "LunaNoContinueClearNum", 0 );
	SetCommonDataEx( "OFT_Save", "StarNoContinueClearNum", 0 );
}

/**
 * ステージプレイ回数を追加する
 * 
 * @param {String} player    プレイヤー
 * @param {String} difficult 難易度
 * @param {String} stage     ステージ数(EXは4扱い、0はプレイ回数)
 */
function AddStagePlayNum( player, difficult, stage ){
	let ns = player ~ "PlayNum" ~ difficult ~ stage;
	let num = GetCommonDataDefaultEx( "OFT_Save", ns, 0 );
	num += 1;
	SetCommonDataEx( "OFT_Save", ns, num );
}

/**
 * クリア回数を追加する
 * 
 * @param {String}  player     プレイヤー
 * @param {String}  difficult  難易度
 * @param {Boolean} nocontinue ノーコンかどうか
 */
function AddClearNum( player, difficult, nocontinue ){
	let ns_clear = player ~ "ClearNum";
	let ns_ncclear = player ~ "NoContinueClearNum";
	let num = 0;
	
	//通常クリア
	num = GetCommonDataDefaultEx( "OFT_Save", ns_clear, 0 );
	num += 1;
	SetCommonDataEx( "OFT_Save", ns_clear, num );
	
	if( nocontinue ){
		//ノーコンクリア
		num = GetCommonDataDefaultEx( "OFT_Save", ns_ncclear, 0 );
		num += 1;
		SetCommonDataEx( "OFT_Save", ns_ncclear, num );
	}
}

/**
 * プレイ時間管理タスク
 */
task PlayTimeTask(){
	PlayTime_H = GetCommonDataDefaultEx( "OFT_Save", "PlayTime_H", 0 );
	PlayTime_M = GetCommonDataDefaultEx( "OFT_Save", "PlayTime_M", 0 );
	PlayTime_S = GetCommonDataDefaultEx( "OFT_Save", "PlayTime_S", 0 );
	
	let count = 0;
	let countnext = 60;
	let secondnext = 60;
	let minutenext = 60;
	
	loop{
		yield;
		count += 1;
		if( count >= countnext ){
			count -= countnext;
			PlayTime_S += 1;
			if( PlayTime_S >= secondnext ){
				PlayTime_S -= secondnext;
				PlayTime_M += 1;
				if( PlayTime_M >= minutenext ){
					PlayTime_M -= minutenext;
					PlayTime_H += 1;
				}
			}
		}
	}
}

/**
 * プレイ時間セーブタスク
 */
function SavePlayTime(){
	SetCommonDataEx( "OFT_Save", "PlayTime_H", PlayTime_H );
	SetCommonDataEx( "OFT_Save", "PlayTime_M", PlayTime_M );
	SetCommonDataEx( "OFT_Save", "PlayTime_S", PlayTime_S );
}
