Update survival.js

This commit is contained in:
slweeb 2024-02-11 13:05:26 -05:00
parent dc0e58f946
commit 9b27bd9e0e
1 changed files with 130 additions and 13 deletions

View File

@ -4,7 +4,7 @@ if (!settings.survival) {
"dirt": 999,
"sapling": 1,
"seeds": 5,
"water": 25,
"ice": 25,
"cloner": 1,
}
}
@ -40,6 +40,7 @@ function survivalRemove(element,amount,skipSave) {
delete settings.survival[element];
var btn = document.getElementById("elementButton-"+element);
if (btn) { btn.remove(); }
selectElement("unknown");
}
if (!skipSave) {survivalSave()}
}
@ -47,6 +48,13 @@ function survivalCount(element) {
return settings.survival[element] || 0;
}
function survivalUpdate(element) {
if (element === "gold_coin") {
// if it is not an integer, round it to 0.1
if (settings.survival.gold_coin % 1 !== 0) {
settings.survival.gold_coin = Math.round(settings.survival.gold_coin*10)/10;
}
document.getElementById("coinCount").innerHTML = settings.survival.gold_coin||0;
}
var btn = document.getElementById("elementButton-"+element);
if (elements[element] && elements[element].category === "tools") { return }
if (btn) {
@ -67,7 +75,7 @@ runAfterAutogen(function(){
for (var element in elements) {
if (elements[element].category !== "tools") {
elements[element].hidden = true;
elements[element].category = "survival";
elements[element].category = "inventory";
}
}
for (var element in settings.survival) {
@ -78,11 +86,6 @@ runAfterAutogen(function(){
}
});
/*
Cloner
Sell
*/
delete elements.cloner.behavior;
elements.cloner.tick = function(pixel) {
if (settings.survivalClone) {
@ -112,6 +115,7 @@ elements.cloner.tick = function(pixel) {
}
};
elements.cloner.ignore = elements.cloner.ignore.concat(["gold","gold_coin","molten_gold"]);
elements.cloner.desc = "You can only clone one element at a time!"
elements.smash.tool = function(pixel) {
if (elements[pixel.element].seed === true) { return }
@ -148,13 +152,38 @@ elements.smash.tool = function(pixel) {
elementWorth = {
"gold_coin": 1,
"diamond": 100,
"ketchup": 15,
"jelly": 10,
"soda": 10,
"toast": 10,
"bread": 3,
"glass": 5,
"rad_glass": 6,
"glass_shard": 2,
"rad_shard": 3,
"paper": 5,
"broth": 5,
"sap": 5,
"caramel": 5,
"candy": 5,
"popcorn": 2,
"flour": 2,
"lettuce": 2,
"sauce": 2,
"wood": 0.2,
"tree_branch": 0.1,
"plant": 0.1,
"mushroom_cap": 0.1,
"mushroom_gill": 0.3,
"vine": 0.1,
"cloner": 0,
"wall": 0,
"fire": 0,
"smoke": 0,
"plasma": 0,
"petal": -1,
"cell": -1,
"cancer": -1,
}
elements.sell = {
color: ["#fff0b5","#ffe680","#c48821","#986a1a","#eca832","#f0bb62"],
@ -165,6 +194,59 @@ elements.sell = {
survivalAdd("gold_coin",elementWorth[pixel.element]||1);
},
category: "tools",
desc: "Exchanges pixels for their market value in Gold Coins"
}
elements.seeds.name = "seed";
/*
~Cloner
~Sell
Shop
Cloner Reset
~Ammonia
~Dirt
~Water
~Seeds
~Sapling
~Pinecone
~Primordial Soup
~Worm
~Bee
~Human
~TNT
Seller (Runs Sell tool on pixels that touch it)
Buyer (Cloner but uses store price every time, prompt to select item on select)
Prices tab
*/
survivalShop = {
"dirt*25": 25,
"water*25": 250,
"ammonia*25": 500,
"seeds*1": 500,
"sapling*1": 500,
"pinecone*1": 500,
"tnt*25": 1000,
"worm*1": 1000,
"bee*1": 5000,
"primordial_soup*5": 10000,
"human*1": 50000,
"sun*25": 500000,
}
function survivalBuy(element) {
var price = survivalShop[element];
if (!price) { alert("The shop isn't selling "+element+"!"); return }
if (settings.survival.gold_coin < price) { alert("You can't afford that!"); return }
survivalRemove("gold_coin",price);
var amount = 1;
if (element.indexOf("*") !== -1) { amount = parseInt(element.split("*")[1]); element = element.split("*")[0]; }
survivalAdd(element,amount);
selectElement(element);
}
function survivalResetCloner() {
if (settings.survival.gold_coin < 1000) { alert("You can't afford that!"); return }
survivalRemove("gold_coin",1000);
settings.survivalClone = null;
survivalSave();
}
window.addEventListener("load",function(){
@ -186,6 +268,46 @@ window.addEventListener("load",function(){
placeImage = function() {}
chooseElementPrompt = function() {}
document.getElementById("toolControls").insertAdjacentHTML("beforeend",`<button class="controlButton" title="Erases all survival.js data" onclick="if (confirm('THIS WILL ERASE ALL survival.js DATA!!! ARE YOU SURE?')) {settings.survivalClone=null; settings.survival = null; saveSettings(); location.reload()}">StartOver</button>`);
createCategoryDiv("shop");
var shopDiv = document.getElementById("category-shop");
shopDiv.style.display = "none";
shopDiv.insertAdjacentHTML("beforeend",`<p>You have $<span id="coinCount">${settings.survival.gold_coin||0}</span></p>`);
for (var element in survivalShop) {
var price = survivalShop[element];
var button = document.createElement("button");
var name = element;
var amount = 1;
if (element.indexOf("*") !== -1) { amount = parseInt(element.split("*")[1]); name = element.split("*")[0]; }
var elemname = name;
name = (elements[elemname].name||name).replace(/_/g, " ").replace("."," ").replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}).replace(" ",".").replace(/ /g, "");
button.classList.add("elementButton");
button.setAttribute("element",element);
button.setAttribute("category","shop");
button.setAttribute("title",amount+" "+name+" for $"+price);
button.innerHTML = name+"<span style='font-family:Arial;font-size:1.15em'> ("+amount+" for $"+price+")</span>";
if (elements[elemname]) {
if (elements[elemname].color instanceof Array) {
button.style.backgroundImage = "linear-gradient(to bottom right, "+elements[elemname].color.join(", ")+")";
// choose the middlemost item in array
var colorObject = elements[elemname].colorObject[Math.floor(elements[elemname].colorObject.length/2)];
if (elements[elemname].darkText !== false && (elements[elemname].darkText || (colorObject.r+colorObject.g+colorObject.b)/3 > 200)) {
button.className += " bright"
}
}
else {
button.style.background = elements[elemname].color;
var colorObject = elements[elemname].colorObject;
if (elements[elemname].darkText !== false && (elements[elemname].darkText || (colorObject.r+colorObject.g+colorObject.b)/3 > 200)) {
button.className += " bright"
}
}
}
button.addEventListener("click",function(){
survivalBuy(this.getAttribute("element"));
});
shopDiv.appendChild(button);
}
shopDiv.insertAdjacentHTML("beforeend",`<p><button style="background-color:#dddd00" class="elementButton bright" title="Resets the cloner" onclick="survivalResetCloner()">ResetCloner<span style='font-family:Arial;font-size:1.15em'> ($1000)</span></button></p>`);
});
runAfterLoad(function(){
checkUnlock = function(element) {
@ -287,16 +409,11 @@ runAfterLoad(function(){
if (survivalCount(currentElement) < 1 && elements[currentElement].category !== "tools") {
return;
}
if (elements[currentElement].category !== "tools") { survivalRemove(currentElement,1); }
currentPixels.push(new Pixel(x, y, currentElement));
if (elements[currentElement].customColor || elements[currentElement].singleColor) {
pixelMap[x][y].color = pixelColorPick(currentElement,currentColor);
}
if (currentElementProp) {
for (var key in currentElementProp) {
pixelMap[x][y][key] = currentElementProp[key]
}
}
if (elements[currentElement].category !== "tools") { survivalRemove(currentElement,1); }
}
}
if (currentElement == "mix") {