Skip to content

Commit

Permalink
added leaderboard functionality and local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
f00d4tehg0dz committed Aug 13, 2022
1 parent ff7495c commit b6cd020
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 59 deletions.
Binary file modified Release/com.f00d4tehg0dz.cookieclicker.streamDeckPlugin
Binary file not shown.
80 changes: 53 additions & 27 deletions com.f00d4tehg0dz.cookieclicker.sdPlugin/cookieclicker.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,80 @@
<head>
<meta charset="utf-8"/>
<title>com.f00d4tehg0dz.cookieclicker</title>
<link rel="stylesheet" href="css/sdpi.css">
<script src="js/jquery-3.3.1.js"></script>
<script src="js/common.js"></script>
<link rel="stylesheet" href="./css/sdpi.css">
<script src="./js/jquery-3.3.1.js"></script>
<script src="./js/common.js"></script>
</head>

<body>
<div class="sdpi-wrapper">
<div class="sdpi-item">
<div class="sdpi-item-label">Enter Name for LeaderBoard</div>
<input class="sdpi-item-value" id="nameKey" required>

</div>
<div class="sdpi-item">
<div class="sdpi-item-label">LeaderBoard</div>
<button onclick="openLeaderBoard()">View</button >
</div>
<div class="sdpi-item">
<div class="sdpi-item-label">Instructions</div>
<details class="sdpi-item-value">
<p>Click the cookie to make more cookies<br>
Cookie Title upgrades as you reach cookie clicker milestones <br></p>
<p>You can learn more about this plugin by visiting its Github
page by <a
href="#"
onclick="openGithub()">clicking here.</a>
Cookie Title upgrades and inserts multiplier as you reach cookie clicker milestones
<br>You can learn more about this plugin by visiting its <button onclick="openGithub()">Github
page</button></p>
</details>
</div>
<div class="sdpi-item">
<button class="sdpi-item-value" id="updateButton">Submit to LeaderBoard</button>
</div>
</div>
<script src="js/jquery-3.3.1.js"></script>


<script>
let uuid = "",
actionName = "";
actionName = "";

if ($SD) {
$SD.on('connected', function (jsonObj) {
uuid = jsonObj['uuid'];
if (jsonObj.hasOwnProperty('actionInfo')) {
actionName = jsonObj.actionInfo.action;
if ($SD) {
$SD.on('connected', function (jsonObj) {
uuid = jsonObj['uuid'];
if (jsonObj.hasOwnProperty('actionInfo')) {
actionName = jsonObj.actionInfo.action;
}
if (settings.nameKey) {
$("#nameKey").val(settings.nameKey);
}

let settings = $SD.actionInfo.payload.settings;
});
}
function openGithub() {
console.log("hel")
$SD.api.openUrl($SD.actionInfo.context,
"https://github.com/f00d4tehg0dz/elgato-streamdeck-cookie-clicker")
}

function openLeaderBoard() {
$SD.api.openUrl($SD.actionInfo.context,
"https://cookie-clicker-leader-board-react.vercel.app/")
}
let settings = $SD.actionInfo.payload.settings;
});
}

$(document).ready(function () {


$("#updateButton").click(function () {
let nameKey = $("#nameKey").val();

if ($SD && $SD.connection) {

$SD.api.sendToPlugin(uuid, actionName, payload);
}
if (!$("#nameKey").val()) {
return;
}
if ($SD && $SD.connection) {
let payload = {};
payload.nameKey = nameKey;
$SD.api.sendToPlugin(uuid, actionName, payload);
}
});
function openGithub() {
$SD.api.openUrl($SD.actionInfo.context, "https://github.com/f00d4tehg0dz/Doge-Coin-Plugin-for-Eglato-Streamdeck")
}
});

</script>

</body>
Expand Down
10 changes: 5 additions & 5 deletions com.f00d4tehg0dz.cookieclicker.sdPlugin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

<body>
<img id="bg" width="144" height="144" src="icon.gif" alt="bg image">
<script src="js/common.js"></script>
<script src="js/moment.js"></script>
<script src="js/jquery-3.3.1.js"></script>
<script src="action/js/status.js"></script>
<script src="js/app.js"></script>
<script src="./js/common.js"></script>
<script src="./js/moment.js"></script>
<script src="./js/jquery-3.3.1.js"></script>
<script src="./action/js/status.js"></script>
<script src="./js/app.js"></script>
</body>

</html>
110 changes: 91 additions & 19 deletions com.f00d4tehg0dz.cookieclicker.sdPlugin/js/app.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
if ($SD) {
const actionName = "com.f00d4tehg0dz.cookieclicker.action";
var num = 0;
if (localStorage.getItem("score") === null) {
var scores = 0;
localStorage.setItem("score", scores.toString());
localStorage.score = 0
}
else {
num = localStorage.score
}

$SD.on("connected", function(jsonObj) {
console.log("Connected!");

});

$SD.on(actionName + ".willAppear", function(jsonObj) {
let settings = jsonObj.payload.settings;

if (settings.automaticRefresh) {
initiateStatus(jsonObj.context, jsonObj.payload.settings);
}

});

$SD.on(actionName + ".sendToPlugin", function(jsonObj) {
$SD.api.setSettings(jsonObj.context, jsonObj.payload);
initiateStatus(jsonObj.context, jsonObj.payload);
let uuid = jsonObj.context;
let settings = jsonObj.payload;
setLeaderBoardScore(settings, uuid);
//$SD.api.setSettings(jsonObj.context, jsonObj.payload);
//initiateStatus(jsonObj.context, jsonObj.payload);
});

// When pressed, Cookie Clicker Activates!
Expand All @@ -24,6 +38,8 @@ if ($SD) {
console.log();
});



function initiateStatus(context, settings) {

// Initial call for the first time
Expand All @@ -48,7 +64,6 @@ if ($SD) {
$SD.api.setTitle(context, "Updating");
getResults(result => resultCallback(result, context, settings));
}


function numbersBoard(result) {
var resultString = result.number;
Expand All @@ -60,6 +75,58 @@ if ($SD) {
// ctx.fillText(resultString , (canvas.width/2) - (textWidth / 2), 80);
}

function setLeaderBoardScore(settings,uuid) {
// Set up our HTTP request
var xhr = new XMLHttpRequest();

// Setup our listener to process completed requests
xhr.onload = function () {

// Process our return data
if (xhr.status >= 200 && xhr.status < 300) {
// Runs when the request is successful
xhr.open("PUT", `https://f00d.me/api/leaderboard/${uuid}`);

xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");

xhr.onload = () => console.log(xhr.responseText);
const name = settings.nameKey;
let data = `{
"_id": "${uuid}",
"name": "${name}",
"score": ${localStorage.score}
}`;

xhr.send(data);
console.log(xhr.responseText);
} else {
// Runs when it's not
xhr.open("POST", "https://f00d.me/api/leaderboard");

xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
const name = settings.nameKey;
xhr.onload = () => console.log(xhr.responseText);
let data = `{
"_id": "${uuid}",
"name": "${name}",
"score": ${localStorage.score}
}`;

xhr.send(data);
console.log(xhr.responseText);
}

};

// Create and send a GET request
// The first argument is the post type (GET, POST, PUT, DELETE, etc.)
// The second argument is the endpoint URL
xhr.open('GET', `https://f00d.me/api/leaderboard/${uuid}`);
xhr.send();
}

function titleBoard(result) {
var resultString = result.title;
ctx.font = 'bold 30px Arial';
Expand Down Expand Up @@ -121,49 +188,54 @@ if ($SD) {
function getResults(updateTitleFn) {

// 1x
if (num >= 0) {
num += 1;
if (localStorage.score >= 0) {
var scores = (parseInt(localStorage.getItem("score"))+1);
localStorage.setItem("score", scores.toString());
updateTitleFn(JSON.parse(JSON.stringify({
"number": num,
"number": localStorage.score,
"title": "Grandma",
})));
}

// 2x
if (num >= 30) {
num += 2;
if (localStorage.score >= 30) {
var scores = (parseInt(localStorage.getItem("score"))+2);
localStorage.setItem("score", scores.toString());
updateTitleFn(JSON.parse(JSON.stringify({
"number": num,
"number": localStorage.score,
"title": "Baker",
})));
}

// 10x
if (num >= 500) {
num += 10;
if (localStorage.score >= 500) {
var scores = (parseInt(localStorage.getItem("score"))+10);
localStorage.setItem("score", scores.toString());
updateTitleFn(JSON.parse(JSON.stringify({
"number": num,
"number": localStorage.score,
"title": "Factory",
})));
}

// 30x
if (num >= 1000) {
num += 30;
if (localStorage.score >= 1000) {
var scores = (parseInt(localStorage.getItem("score"))+50);
localStorage.setItem("score", scores.toString());
updateTitleFn(JSON.parse(JSON.stringify({
"number": num,
"number": localStorage.score,
"title": "Plant",
})));
}

// 1000x
if (num >= 100000) {
num += 1000;
if (localStorage.score >= 100000) {
var scores = (parseInt(localStorage.getItem("score"))+1000);
localStorage.setItem("score", scores.toString());
updateTitleFn(JSON.parse(JSON.stringify({
"number": num,
"number": localStorage.score,
"title": "S. Plant",
})));
}
}

}
}
2 changes: 1 addition & 1 deletion com.f00d4tehg0dz.cookieclicker.sdPlugin/js/jquery-3.3.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -10361,4 +10361,4 @@ if ( !noGlobal ) {


return jQuery;
} );
} );
2 changes: 1 addition & 1 deletion com.f00d4tehg0dz.cookieclicker.sdPlugin/js/moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4599,4 +4599,4 @@

return hooks;

})));
})));
13 changes: 7 additions & 6 deletions com.f00d4tehg0dz.cookieclicker.sdPlugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"Name": "CookieClicker",
"States": [
{
"Image": "icon"
"Image": "icon",
"TitleAlignment": "middle",
"FontSize": "9",
"ShowTitle": true
}
],
"SupportedInMultiActions": false,
Expand All @@ -15,15 +18,13 @@
],
"SDKVersion": 2,
"Author": "Adrian Chrysanthou",
"Category": "Cookie Clicker [f00d4tehg0dz]",
"CategoryIcon": "icons/category-icon",
"CodePath": "index.html",
"Description": "A CookieClicker Status plugin developed by Adrian Chrysanthou. You can find more information about this plugin at https://github.com/f00d4tehg0dz/Doge-Coin-Plugin-for-Eglato-Streamdeck. Please report any issues you see on the project's Github page. I welcome any feedback.",
"Description": "A CookieClicker Status plugin developed by Adrian Chrysanthou. You can find more information about this plugin at https://github.com/f00d4tehg0dz/elgato-streamdeck-cookie-clicker. Please report any issues you see on the project's Github page. I welcome any feedback.",
"Name": "CookieClicker Status",
"Icon": "icon",
"URL": "https://github.com/f00d4tehg0dz/Cookie-Clicker-Plugin-for-Eglato-Streamdeck",
"URL": "https://github.com/f00d4tehg0dz/elgato-streamdeck-cookie-clicker",
"PropertyInspectorPath": "cookieclicker.html",
"Version": "2.3",
"Version": "3.1",
"OS": [
{
"Platform": "mac",
Expand Down
Binary file modified elgatogif_AME/elgatogif.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed elgatogif_AME/elgatogif.mp4
Binary file not shown.
Binary file added elgatogif_AME/elgatomp4.mp4
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit b6cd020

Please sign in to comment.