diff --git a/twitch/chatguessr.js b/twitch/chatguessr.js index dbf57a7..6ac7ebf 100644 --- a/twitch/chatguessr.js +++ b/twitch/chatguessr.js @@ -85,8 +85,8 @@ return countryCodesNames.find((country) => country.code === normalized || GameHelper.isMatch(normalized, country.names.toLowerCase())); }; - var isOpen = $.getSetIniDbBoolean('chatguessr', 'isOpen', false), - seed = {}, + $.getSetIniDbBoolean('chatguessr', 'isOpen', false); + var seed = {}, scale, guesses = {}; @@ -126,13 +126,12 @@ action = args[0]; if (command.equalsIgnoreCase('g')) { - if(isOpen) addGuess(sender,args); + if($.getIniDbBoolean('chatguessr', 'isOpen')) addGuess(sender,args); }else if (command.equalsIgnoreCase('cg')) { //send url //$.say($.whisperPrefix(sender) + $.lang.get('chatguessr.help', ' Use "!cg [open | close | ...]" to open/close the feature.')); }else if(command.equalsIgnoreCase('cga')){ if(action.equalsIgnoreCase('open')){ - isOpen = true; $.setIniDbBoolean('cgstatus', 'isOpen', true); }else if(action.equalsIgnoreCase('close')){ $.setIniDbBoolean('cgstatus', 'isOpen', false) @@ -140,18 +139,26 @@ seed = fetchSeed(args[1]); scale = calculateScale(seed.bounds) }else if(action.equalsIgnoreCase('end')){ - isOpen = false; $.setIniDbBoolean('cgstatus', 'isOpen', false) guesses = {}; seed = {}; sendData('guesses',JSON.stringify(guesses)); }else if(action.equalsIgnoreCase('refresh')){ var newseed = fetchSeed(args[1]); - if(newseed.state=="finished"){ - //FINISHED - }else if(newseed.player.guesses.length() > seed.player.guesses.length()){ - //NEW ROUND ! + if(newseed.player.guesses.length() > seed.player.guesses.length()){ + $.setIniDbBoolean('chatguessr', 'isOpen',false) + //NEW ROUND /Score + var gp = newseed.player.guesses[seed.round - 1].lat+","+newseed.player.guesses[seed.round - 1].lng + addGuess($.channelName,gp); + }else{ + if(newseed.state=="finished"){ + $.setIniDbBoolean('chatguessr', 'isOpen',false) //FINISHED + //Compute total scores + give reward + }else{ + $.setIniDbBoolean('chatguessr', 'isOpen',true) //NEW ROUD /Guess + } } + seed = newseed; guesses.round = seed.round - 1; }else if(action.equalsIgnoreCase('gg')){ sendData('guesses',JSON.stringify(guesses));