--------------------------------------------------------------------
-- s_init_destpos_normal.lua
-- カーソル移動先ポイント初期化（通常時）
--
-- author IZUMI STUDIO
-- date
--------------------------------------------------------------------
require(".\\scripts\\game\\s_common")


BASE_RESOLUTION_WIDTH  = 800
BASE_RESOLUTION_HEIGHT = 600
resolutionWidth  = Scene.GetEnvParameterInt("ResolutionWidth")
resolutionHeight = Scene.GetEnvParameterInt("ResolutionHeight")
aspectRatio      = Scene.GetEnvParameterFloat("AspectRatio")

-- 「1.333 部分と、その外側」と考える
margin    = ( (aspectRatio-1.333) / (aspectRatio) ) * resolutionWidth / 2.0
mainWidth = resolutionWidth * 1.333 / aspectRatio

button_ReturnPos = {
	margin + 190.0 / BASE_RESOLUTION_WIDTH * mainWidth,
	560.5 / BASE_RESOLUTION_HEIGHT * resolutionHeight }

chips_width    = 8
chips_height   = 8
chips_centerX  = margin + 400.0 / BASE_RESOLUTION_WIDTH * mainWidth
chips_centerY  = 310.0 / BASE_RESOLUTION_HEIGHT * resolutionHeight
chips_spacingX = 48.0 / BASE_RESOLUTION_WIDTH * mainWidth
chips_spacingY = 48.0 / BASE_RESOLUTION_HEIGHT * resolutionHeight

chips_first_posX = chips_centerX - chips_spacingX * chips_width / 2.0 + chips_spacingX / 2.0
chips_first_posY = chips_centerY - chips_spacingY * chips_height / 2.0 + chips_spacingY / 2.0

chips_poses = {}
for y=1, chips_height, 1 do
	chips_poses[y] = {}
	
	for x=1, chips_width, 1 do
		chips_poses[y][x] = {}
		chips_poses[y][x][1] = chips_first_posX + chips_spacingX * (x-1)
		chips_poses[y][x][2] = chips_first_posY + chips_spacingY * (y-1)
	end
end


-- 全てクリアする
Scene.ClearCursorDestPoints(0)

-- ボタン（Quit）
Scene.AddCursorDestPoint( 0, 
	button_ReturnPos[1], button_ReturnPos[2], -- dest
	chips_poses[8][1][1], chips_poses[8][1][2],  -- up
	chips_poses[1][1][1], chips_poses[1][1][2],  -- down
	chips_poses[8][8][1], chips_poses[8][8][2],  -- left
	chips_poses[8][1][1], chips_poses[8][1][2] ) -- right

-- チップ
for y=1, chips_height, 1 do
	for x=1, chips_width, 1 do
		keyUp_x    = x
		keyUp_y    = ( y - 1 + chips_height -1 ) % chips_height + 1
		keyDown_x  = x
		keyDown_y  = ( y + 1 + chips_height -1 ) % chips_height + 1
		keyLeft_x  = ( x - 1 + chips_width -1 ) % chips_width + 1
		keyLeft_y  = y
		keyRight_x = ( x + 1 + chips_width -1 ) % chips_width + 1
		keyRight_y = y
		
		if (y==8) and (x==1) then
			Scene.AddCursorDestPoint( 0,
				chips_poses[y][x][1], chips_poses[y][x][2],
				chips_poses[keyUp_y][keyUp_x][1], chips_poses[keyUp_y][keyUp_x][2], -- up
				button_ReturnPos[1], button_ReturnPos[2], -- down
				button_ReturnPos[1], button_ReturnPos[2], -- left
				chips_poses[keyRight_y][keyRight_x][1], chips_poses[keyRight_y][keyRight_x][2] ) -- right
		elseif (y==8) and (x==8) then
			Scene.AddCursorDestPoint( 0,
				chips_poses[y][x][1], chips_poses[y][x][2],
				chips_poses[keyUp_y][keyUp_x][1], chips_poses[keyUp_y][keyUp_x][2], -- up
				chips_poses[keyDown_y][keyDown_x][1], chips_poses[keyDown_y][keyDown_x][2], -- down
				chips_poses[keyLeft_y][keyLeft_x][1], chips_poses[keyLeft_y][keyLeft_x][2], -- left
				button_ReturnPos[1], button_ReturnPos[2] ) -- right
		elseif (y==1) and (x==1) then
			Scene.AddCursorDestPoint( 0,
				chips_poses[y][x][1], chips_poses[y][x][2],
				button_ReturnPos[1], button_ReturnPos[2], -- up
				chips_poses[keyDown_y][keyDown_x][1], chips_poses[keyDown_y][keyDown_x][2], -- down
				chips_poses[keyLeft_y][keyLeft_x][1], chips_poses[keyLeft_y][keyLeft_x][2], -- left
				chips_poses[keyRight_y][keyRight_x][1], chips_poses[keyRight_y][keyRight_x][2] ) -- right
		else
			Scene.AddCursorDestPoint( 0,
				chips_poses[y][x][1], chips_poses[y][x][2],
				chips_poses[keyUp_y][keyUp_x][1], chips_poses[keyUp_y][keyUp_x][2],
				chips_poses[keyDown_y][keyDown_x][1], chips_poses[keyDown_y][keyDown_x][2],
				chips_poses[keyLeft_y][keyLeft_x][1], chips_poses[keyLeft_y][keyLeft_x][2],
				chips_poses[keyRight_y][keyRight_x][1], chips_poses[keyRight_y][keyRight_x][2] )
		end
	end
end




