Chovin / Litghtsaber

little PICO-8 game made for a couple events
MIT License
1 stars 2 forks source link

leaderboard #13

Open Chovin opened 4 years ago

Chovin commented 4 years ago

I think we can do a local leaderboard (per-browser) and a global one via some free json store service - I want to make the deploy as simple to understand and as free as possible. We can also use that json store service to store user settings, logins, and such. Should probably store personal bests and award players when they beat it. Pretty sure we can't lock the leaderboard down, so we may have to add a message in the store.. let’s keep this honest and fun. please don't artificially add/alter scores directly in this json store <3 or something

Chovin commented 4 years ago

little snippet from probably some stackoverflow answer (sorry don't have the source) about cookies.. for local leaderboard and/or queued players in case the browser refreshes?

function setCookie(name,value,days) {
    var expires = "";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days*24*60*60*1000));
        expires = "; expires=" + date.toUTCString();
    }
    document.cookie = name + "=" + (value || "")  + expires + "; path=/";
}
function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
function eraseCookie(name) {   
    document.cookie = name+'=; Max-Age=-99999999;';  
}