scoreboard players set @a inputCooldown 20

setblock 2 4 18 stone

kill @e[type=minecart]
execute as @a[tag=inControl] run tp @s 37 82 30 90 15

execute as @a[tag=inControl] run clear @s
execute as @a[tag=inControl] run effect clear @s

execute as @a at @s run playsound minecraft:ui.toast.challenge_complete master @s ~ 1000000 ~ 1000000

#record win
execute if score #tutorial bestTime matches -1 run scoreboard players operation #tutorial bestTime = #tutorial gameTime
execute if score #tutorial gameTime < #tutorial bestTime run scoreboard players operation #tutorial bestTime = #tutorial gameTime
execute if score #tutorial bestMoves matches -1 run scoreboard players operation #tutorial bestMoves = #tutorial gameMoves
execute if score #tutorial gameMoves < #tutorial bestMoves run scoreboard players operation #tutorial bestMoves = #tutorial gameMoves
scoreboard players operation global gameTime = #tutorial bestTime
function bd:game/convert_raw_time/start
setblock 48 88 4 redstone_block

#write sign based on what rank we got
execute if score #tutorial bestMoves matches ..430 run data merge block 48 89 5 {GlowingText:1b,Text1:'{"text":"TUTORIAL","bold":true,"clickEvent":{"action":"run_command","value":"/function bd:game/rank_info/tutorial"}}',Text2:'[{"text":" Rank: "},{"text":"S","color":"gold","bold":true}]',Text3:'[{"score":{"name":"#tutorial","objective":"bestMoves"},"color":"black"},{"text":" moves","color":"black"}]',Text4:'[{"score":{"name":"global","objective":"timeHr"}},{"text":"h "},{"score":{"name":"global","objective":"timeMin2"}},{"score":{"name":"global","objective":"timeMin"}},{"text":"m "},{"score":{"name":"global","objective":"timeSec2"}},{"score":{"name":"global","objective":"timeSec"}},{"text":"s"}]'}
execute if score #tutorial bestMoves matches 431..860 run data merge block 48 89 5 {GlowingText:1b,Text1:'{"text":"TUTORIAL","bold":true,"clickEvent":{"action":"run_command","value":"/function bd:game/rank_info/tutorial"}}',Text2:'[{"text":" Rank: "},{"text":"A","color":"blue","bold":true}]',Text3:'[{"score":{"name":"#tutorial","objective":"bestMoves"},"color":"black"},{"text":" moves","color":"black"}]',Text4:'[{"score":{"name":"global","objective":"timeHr"}},{"text":"h "},{"score":{"name":"global","objective":"timeMin2"}},{"score":{"name":"global","objective":"timeMin"}},{"text":"m "},{"score":{"name":"global","objective":"timeSec2"}},{"score":{"name":"global","objective":"timeSec"}},{"text":"s"}]'}
execute if score #tutorial bestMoves matches 861..1720 run data merge block 48 89 5 {GlowingText:1b,Text1:'{"text":"TUTORIAL","bold":true,"clickEvent":{"action":"run_command","value":"/function bd:game/rank_info/tutorial"}}',Text2:'[{"text":" Rank: "},{"text":"B","color":"dark_green","bold":true}]',Text3:'[{"score":{"name":"#tutorial","objective":"bestMoves"},"color":"black"},{"text":" moves","color":"black"}]',Text4:'[{"score":{"name":"global","objective":"timeHr"}},{"text":"h "},{"score":{"name":"global","objective":"timeMin2"}},{"score":{"name":"global","objective":"timeMin"}},{"text":"m "},{"score":{"name":"global","objective":"timeSec2"}},{"score":{"name":"global","objective":"timeSec"}},{"text":"s"}]'}
execute if score #tutorial bestMoves matches 1721..3440 run data merge block 48 89 5 {GlowingText:1b,Text1:'{"text":"TUTORIAL","bold":true,"clickEvent":{"action":"run_command","value":"/function bd:game/rank_info/tutorial"}}',Text2:'[{"text":" Rank: "},{"text":"C","color":"dark_purple","bold":true}]',Text3:'[{"score":{"name":"#tutorial","objective":"bestMoves"},"color":"black"},{"text":" moves","color":"black"}]',Text4:'[{"score":{"name":"global","objective":"timeHr"}},{"text":"h "},{"score":{"name":"global","objective":"timeMin2"}},{"score":{"name":"global","objective":"timeMin"}},{"text":"m "},{"score":{"name":"global","objective":"timeSec2"}},{"score":{"name":"global","objective":"timeSec"}},{"text":"s"}]'}
execute if score #tutorial bestMoves matches 3441.. run data merge block 48 89 5 {GlowingText:1b,Text1:'{"text":"TUTORIAL","bold":true,"clickEvent":{"action":"run_command","value":"/function bd:game/rank_info/tutorial"}}',Text2:'[{"text":" Rank: "},{"text":"D","color":"dark_gray","bold":true}]',Text3:'[{"score":{"name":"#tutorial","objective":"bestMoves"},"color":"black"},{"text":" moves","color":"black"}]',Text4:'[{"score":{"name":"global","objective":"timeHr"}},{"text":"h "},{"score":{"name":"global","objective":"timeMin2"}},{"score":{"name":"global","objective":"timeMin"}},{"text":"m "},{"score":{"name":"global","objective":"timeSec2"}},{"score":{"name":"global","objective":"timeSec"}},{"text":"s"}]'}

#summon trophy thing
kill @e[type=armor_stand,tag=trophy,tag=tutorial]
summon armor_stand 48 89 4 {Tags:["nokill","trophy","tutorial"],DisabledSlots:4144959,CustomNameVisible:0b,NoGravity:1b,Silent:1b,Invulnerable:1b,Invisible:1b,NoBasePlate:1b,ArmorItems:[{},{},{},{id:"minecraft:lectern",Count:1b}],CustomName:'{"text":"Trophy","color":"#FFAA00","bold":true}'}
execute as @e[type=armor_stand,tag=trophy,tag=tutorial] at @s run tp @s ~ ~-.25 ~

execute as @a[tag=inControl] run function bd:game/check_for_advancements
tag @a[tag=inControl] remove inControl

tellraw @a ["",{"text":"You've completed the tutorial!","color":"aqua"}]
tellraw @a ["",{"text":"Now try a new puzzle set! Click on `NEW GAME` to get started.","color":"white","italic":"true"}]