Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/R74nCom/sandboxels
Browse files Browse the repository at this point in the history
  • Loading branch information
slweeb committed Dec 29, 2023
2 parents 2b2faab + d01f88f commit 5c5d3a1
Show file tree
Hide file tree
Showing 9 changed files with 394 additions and 9 deletions.
30 changes: 27 additions & 3 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,35 @@ message: >-
metadata from this file.
type: software
authors:
- given-names: R74n
email: [email protected]
affiliation: R74n
- name: R74n
email: [email protected]
date-start: '2017-05-02'
website: 'https://r74n.com/'
identifiers:
- type: doi
value: 10.17605/OSF.IO/H7TDY
- type: swh
value: 'swh:1:rev:5a5813a8f4f418540f1bdb765d293735541bf7fd'
- type: url
value: 'https://sandboxels.r74n.com/'
- type: doi
value: 10.5281/zenodo.10044909
- type: other
value: /g/11spmybz10
description: KGMID
- type: url
value: 'https://purl.org/r74n/sandboxels'
description: PURL
- type: url
value: 'https://w3id.org/r74n/sandboxels'
description: W3ID
repository-code: 'https://github.com/R74nCom/sandboxels'
url: 'https://sandboxels.r74n.com'
abstract: >-
Sandboxels is a free falling-sand simulator that can be
played in your browser. It features heat simulation,
electricity, density, chemical reactions, cooking, and
fire spread.
keywords:
- R74n
- Sandboxels
3 changes: 2 additions & 1 deletion mod-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ <h2>Sandboxels Mod List</h2>

<!----><tr><td class="modCat" colspan="3">Tools & Settings</td></tr><!---->
<tr><td>adjustablepixelsize.js</td><td>Allows you to set the pixelSize with a URL parameter</td><td>Alice</td></tr>
<tr><td>betaworldgen.js</td><td>adds a more advanced world generation to the game</td><td>Alex</td></tr>
<tr><td>betterModManager.js</td><td>Improvements to the Mod Manager</td><td>ggod</td></tr>
<tr><td>betterSettings.js</td><td>Adds additional settings and functionality</td><td>ggod</td></tr>
<tr><td>betterStats.js</td><td>Separate “real” and “set” TPS, meaning you can see what the TPS actually is, instead of only seeing what it’s set to</td><td>mollthecoder</td></tr>
<tr><td>change.js</td><td>Adds a tool that only replaces existing pixels</td><td>Alice</td></tr>
<tr><td>color_tools.js</td><td>Adds tools that manipulate colors</td><td>Alice</td></tr>
<tr><td>controllable_pixel_test.js</td><td>Adds a pixel that can be controlled with the keyboard keys. <a href="https://github.com/R74nCom/sandboxels/commit/58dfa9477f2ed7ec9c44b00a35162e7c63bc129c">Read the commit description for more info.</a> [PC ONLY]</td><td>Alice</td></tr>
<tr><td>customexplosion.js</td><td>Added a custom explosion element and interface for it. check out its <a href="https://sandboxels-mods.the-enchanteden.repl.co/Mods/customexplosion.js">source code</a> for how modders can use it.</td><td>Alex</td></tr>
<tr><td>cpt_alt.js</td><td>Adds a more destructive variant of the controllable pixel</td><td>Alice</td></tr>
<tr><td>debugRework.js</td><td>Revamps the Debug tool</td><td>Fioushemastor</td></tr>
<tr><td>delete_all_of_element.js</td><td>Adds a tool that deletes every pixel of the element(s) the user clicks on</td><td>Alice</td></tr>
Expand Down Expand Up @@ -261,6 +261,7 @@ <h2>Sandboxels Mod List</h2>
<tr><td>changeTempReactionParameter.js</td><td>Adds the changeTemp property to modded reactions</td><td>Alice</td></tr>
<tr><td>code_library.js</td><td>Adds functions and variables common to some other mods</td><td>Alice</td></tr>
<tr><td>CrashTestDummy.js</td><td>Originally a test to see if certain code broke the game, but now just adds a tool that turns things into sand</td><td>StellarX20</td></tr>
<tr><td>customexplosion.js</td><td>Added a custom explosion element and interface for it. check out its <a href="https://sandboxels-mods.the-enchanteden.repl.co/Mods/customexplosion.js">source code</a> for how modders can use it.</td><td>Alex</td></tr>
<tr><td>date_test.js</td><td>K-pop idol birthday testing stuff</td><td>Alice</td></tr>
<tr><td>drawPixels_change_test.js</td><td>A test of altering drawPixels(). Gives burning pixels a red overlay similar to the yellow overlay for charged pixels</td><td>Alice</td></tr>
<tr><td>example_mod.js</td><td>An example mod for new modders</td><td><a href="https://R74n.com" class="R74nLink">R74n</a></td></tr>
Expand Down
128 changes: 128 additions & 0 deletions mods/betaworldgen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
//This mod was made by Alex the transfem, https://discord.com/users/778753696804765696 on discord and https://www.tiktok.com/@alextheagenenby?_t=8hoCVI3NRhu&_r=1 on tiktok.
function randomAlter(num, list){
let r = Math.floor(Math.random() * list.length);
return (num + list[r]);
}
let avgheight = 0;
let seed = "";
function getSeed(type = "plains", thickness = 15){
seed = "";
console.log(thickness)
if(thickness == 15){
avgheight = Math.floor(Math.random() * (18 - 12 + 1)) + 12;
} else{
avgheight = thickness;
}
console.log(avgheight)

if(type == "plains"){
let location = Math.floor(Math.random(0, pixelMap.length) * 100);
let i = 0;
while (i < pixelMap.length){
if (i !== location){
seed += `${randomAlter(avgheight, [0, 1, 1, 2, 0, 0])}|`;
i += 1;
} else if (i == location){
let height = `${Math.floor(Math.random(40, pixelMap[i].length) * 10)}`;
let prevH = randomAlter(avgheight, [1, 1, 1, 2, 0, 0]);
while (height > prevH){
prevH = randomAlter(prevH, [0, 1, 1, 2, 0, 0, 0, 1]);
seed += `${prevH}|`;
}

i += 1;

}
}
return seed;
}
if(type == "desert"){
let i = 0;
while (i < pixelMap.length){
seed += `${randomAlter(avgheight, [0, 1, 1, 2, 0, 0])}|`;
i += 1;

}
}
return seed;
}
function spawnElements(seed, list, height2 = 1, condition = [1, 1, 0]){
console.log(list);
let width = pixelMap.length - 1;
let element;
let height = pixelMap[1].length - 1;
console.log(seed);
let seedArray = seed.split("|");
console.log(seedArray);
seedArray.splice(seedArray.indexOf(""), 1);
seedArray.splice(pixelMap.length);
console.log(seedArray);
let i = 0;
while (i < seedArray.length - 1){

let ii = 0;
while (ii < seedArray[i]){
if((Math.floor(Math.random() * (condition[0] - condition[1] + 1))) == condition[2]){
if (height2 != 1){
element = list[Math.floor(Math.random() * list.length)];
createPixel(element, (width - 1) - i, (height - (height2 + 1)) - ii);
} else{
element = list[Math.floor(Math.random() * list.length)];
createPixel(element, (width - 1) - i, (height - 1) - ii);
}
}
ii += 1;
}

i += 1;
}
}

function flat(){
let iii = 0;
let flat = "";
while (iii < pixelMap.length){
flat += "1|";
iii += 1;
}
return flat;
}
function processSeed(seed, type = "plains"){

console.log(flat());
let seedsArray = seed.split(":");
console.log(seedsArray);
if(type == "plains"){
spawnElements(seedsArray[0],["rock","rock","rock","rock","rock","rock","metal_scrap","metal_scrap","metal_scrap","gold_coin","uranium","uranium","diamond","rock","iron","iron","iron","aluminum","aluminum","aluminum","aluminum","copper","copper","copper","zinc","zinc","rock","rock","rock","rock","rock","rock","rock","rock","rock","rock","rock","rock","rock","rock","rock"].sort(() => Math.random() - 0.5));
setTimeout(function(){ spawnElements(seedsArray[1], ["dirt"], 24); }, 200);
setTimeout(function(){ spawnElements(flat(),["grass","grass","grass","sapling","flower_seed","grass","grass","pinecone","grass","grass","grass","grass","grass","grass","grass","grass","grass","grass"], 40); }, 300);
} else if(type == "desert"){
spawnElements(seed, ["sand"]);
setTimeout(function(){ spawnElements(flat(), ["cactus"], 40, [6, 0, 3]); }, 100);
}
}
elements.worldGen = {
color: "#FFFFFF",
behavior: elements.erase.behavior,
temp: 2,
category: "tools",
insulate:true,
canPlace: false,
desc: "Generate worlds with random seeds or your own seeds.",
onSelect: function() {
let Seed = prompt("Enter desert or plains random generation! automatically set to plains.");
let regex = /[a-z]/;
if (regex.test(Seed)){
if(Seed.toLowerCase() == "desert"){
processSeed(getSeed("desert", 30), "desert");
}
} else {
if (Seed == ""){
seed = `${getSeed("plains", 20)}:${getSeed("plains", 8)}`
processSeed(seed);
} else{
processSeed(Seed);
}
}
}
}
66 changes: 65 additions & 1 deletion mods/code_library.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
libraryLoaded = true;
this.libraryLoaded = true;
window.libraryLoaded = true;

//URL

urlParams = new URLSearchParams(window.location.search);

libraryLoaded = true;
this.libraryLoaded = true;
window.libraryLoaded = true;

//Objects

//getKeyByValue code by SO UncleLaz: https://stackoverflow.com/questions/9907419/how-to-get-a-key-in-a-javascript-object-by-its-value
Expand All @@ -10,6 +18,10 @@
return Object.keys(object).find(key => object[key] === value);
};

libraryLoaded = true;
this.libraryLoaded = true;
window.libraryLoaded = true;

//RNG

//Random integer from 0 to n
Expand Down Expand Up @@ -77,6 +89,10 @@
return Math.floor(randomFunction() * (max - min + 1)) + min
};

libraryLoaded = true;
this.libraryLoaded = true;
window.libraryLoaded = true;

//Arrays

//Shallow array comparer by SO Tim Down: https://stackoverflow.com/a/10260204
Expand Down Expand Up @@ -158,6 +174,10 @@
};
};

libraryLoaded = true;
this.libraryLoaded = true;
window.libraryLoaded = true;

//Checks

//Element exists in the elements object
Expand Down Expand Up @@ -260,6 +280,10 @@
return false;
};

libraryLoaded = true;
this.libraryLoaded = true;
window.libraryLoaded = true;

//Math(s)

//Base n logarithm from https://stackoverflow.com/a/3019290
Expand Down Expand Up @@ -305,6 +329,10 @@
return (number - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
}

libraryLoaded = true;
this.libraryLoaded = true;
window.libraryLoaded = true;

//Color

function rgbStringToUnvalidatedObject(string) { //turns rgb() to {r,g,b} with no bounds checking
Expand Down Expand Up @@ -1182,7 +1210,11 @@
//console.log(`Hexed to #${f(0)}${f(8)}${f(4)}`)
return `#${f(0)}${f(8)}${f(4)}`;
};


libraryLoaded = true;
this.libraryLoaded = true;
window.libraryLoaded = true;

//Pixels

function exposedToAir(pixel) {
Expand Down Expand Up @@ -1540,6 +1572,10 @@
return true;
};

libraryLoaded = true;
this.libraryLoaded = true;
window.libraryLoaded = true;

//World

function breakCircle(x,y,radius,respectHardness=false,changeTemp=false,defaultBreakIntoDust=false) {
Expand Down Expand Up @@ -1639,6 +1675,10 @@
return true;
};

libraryLoaded = true;
this.libraryLoaded = true;
window.libraryLoaded = true;

//Logic

function xor(c1,c2) {
Expand All @@ -1651,6 +1691,10 @@
};
};

libraryLoaded = true;
this.libraryLoaded = true;
window.libraryLoaded = true;

//currentPixels operations

function findInCurrentPixels(x,y) {
Expand Down Expand Up @@ -1710,6 +1754,10 @@
};


libraryLoaded = true;
this.libraryLoaded = true;
window.libraryLoaded = true;

//Sugar functions

function newElement(name="element_name",color="#FF00FF",otherProps={}) {
Expand All @@ -1722,6 +1770,10 @@
return elements[name];
};

libraryLoaded = true;
this.libraryLoaded = true;
window.libraryLoaded = true;

//Fixes

//fix -1-caused ghost pixels
Expand All @@ -1747,4 +1799,16 @@
}
}
}*/
};

libraryLoaded = true;
this.libraryLoaded = true;
window.libraryLoaded = true;

runAfterLoad(function() {
if(!libraryLoaded) {
libraryLoaded = true;
this.libraryLoaded = true;
window.libraryLoaded = true
}
})
5 changes: 3 additions & 2 deletions mods/heatglow.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const heatfunc = function(pixel){
if (pixel.ogR == null || pixel.ogG == null || pixel.ogB == null){
if (pixel.ogR == null || pixel.ogG == null || pixel.ogB == null || !(pixel.element == pixel.ogElement)){
pixel.ogR = parseInt(pixel.color.slice(4, pixel.color.indexOf(',')), 10)
pixel.ogG = parseInt(pixel.color.slice(pixel.color.indexOf(',') + 1, pixel.color.lastIndexOf(',')), 10)
pixel.ogB = parseInt(pixel.color.slice(pixel.color.lastIndexOf(',') + 1, -1), 10)
pixel.ogElement = pixel.element
}else{
pixel.gethigh = (elements[pixel.element].tempHigh)
pixel.halftemp = ((20+pixel.gethigh)/2)
Expand All @@ -24,7 +25,7 @@ const heatfunc = function(pixel){
}
};
if (!eLists.metals) { eLists.metals = [] }
eLists.metals = eLists.metals.concat(["iron", "glass", "copper", "gold", "brass","steel","nickel","zinc","silver","aluminum","bronze","metal_scrap","oxidized_copper","tin","lead"])
eLists.metals = eLists.metals.concat(["iron", "glass", "copper", "gold", "brass","steel","nickel","zinc","silver","aluminum","bronze","metal_scrap","oxidized_copper","tin","lead", "rose_gold"])
eLists.metals.forEach(metal => {
const prefunc = elements[metal].tick;
if (!prefunc){
Expand Down
Loading

0 comments on commit 5c5d3a1

Please sign in to comment.