Skip to content

Commit

Permalink
Merge branch 'CursedSliver:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
hellopir2 authored Sep 21, 2024
2 parents 4db5949 + 4196b57 commit bf5dc5e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
33 changes: 28 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let plantsById = {};

var maxX = 6; var maxY = 6; var cdim = [6, 6]; var useLev = true; var ageSelected = 3; var importStr = ''; var target = document.styleSheets.length - 1; //target is for fonts dying, usually 1
var tl = {0:'=',1:'a',2:'b',3:'c',4:'d',5:'e',6:'f',7:'g',8:'h',9:'i',10:'j',11:'k',12:'l',13:'m',14:'n',15:'o',16:'p',17:'q',18:'r',19:'s',20:'t',21:'u',22:'v',23:'w',24:'x',25:'y',26:'z',27:'!',28:'@',29:'#',30:'$',31:'%',32:'^',33:'&',34:'*',undefined:';',null:';'};
var rtl = Object.fromEntries(Object.entries(tl).map(([key, value]) => [value, key])); var ag = {undefined:'3',0:'0',1:'1',2:'2',3:'3',4:'4'};
var rtl = Object.fromEntries(Object.entries(tl).map(([key, value]) => [value, key])); var ag = {undefined:'3',0:'0',1:'1',2:'2',3:'3',4:'4',100:'5',101:'6',102:'7',103:'8',104:'9'};
var strIdToIndex = {}; var altLims = [0,[3,3],[3,4],[2,4],[2,5],[1,5],[1,6]]; var plotCSS = 28;
for (let i in document.styleSheets[target].cssRules) { if (document.styleSheets[target].cssRules[i].selectorText == '#gardenPlot') { plotCSS = i; } }

Expand Down Expand Up @@ -412,7 +412,7 @@ function updateStats() {

for (let y=0; y<maxY; y++) {
for (let x=0; x<maxX; x++) {
if (getTile(x, y) !== null) {
if (getTile(x, y) !== null || plot[y * maxX + x].isNull) {
continue;
}

Expand Down Expand Up @@ -536,6 +536,7 @@ class Tile {
this.x = x;
this.y = y;
this.age = 3;
this.isNull = false;

this.plant = null;

Expand All @@ -546,7 +547,12 @@ class Tile {
this.icon.classList.add("tile-icon");
this.icon.style.display = "none";
this.element.appendChild(this.icon);
this.element.addEventListener("click", () => {
this.element.addEventListener("click", e => {
if (e.shiftKey) {
this.setNull(!this.isNull);
return;
}

if (this.plant !== null) {
this.setPlant(null);
return;
Expand Down Expand Up @@ -585,6 +591,18 @@ class Tile {
}
}

setNull(bool) {
this.isNull = bool;
this.element.classList.remove('tile');
this.element.classList.remove('invisTile');
if (this.isNull) {
this.element.classList.add('invisTile');
} else {
this.element.classList.add('tile');
}
updateStats();
}

activeStatus() {
if (this.element.classList.value.includes('disabled')) {
return false;
Expand Down Expand Up @@ -911,7 +929,7 @@ function getAge(x,y) {if (x < 0 || y < 0 || x >= maxX || y >= maxY || (plot[y*ma
function updateEffects() { for (let i in plot) { plot[i].suppress = checkSup(plot[i].x,plot[i].y); } }
function checkSup(x,y) { for (let yy = -2; yy <= 2; yy++) { for (let xx = -2; xx <= 2; xx++) { let t = getTile(x+xx,y+yy);if (xx==0&&yy==0) { continue; } if (t===31) { return 1; } if (t==32) { if (xx != 2 && xx != -2 && yy != 2 && yy != -2) { return 1; } } } } return 0; }
function parseP(input) { if (input === 'null') { return null; } return parseInt(input); }
function save() { var strr = ''; if (useLev) { strr = level+'/'; } else { strr = cdim[0]+'/'+cdim[1]+'/'; } for (let i in plot) { strr+=tl[plot[i].plant]+ag[plot[i].age];} return strr; }
function save() { var strr = ''; if (useLev) { strr = level+'/'; } else { strr = cdim[0]+'/'+cdim[1]+'/'; } for (let i in plot) { strr+=tl[plot[i].plant]+ag[(plot[i].age??3)+(plot[i].isNull?100:0)];} return strr; }
function load(str, noResize) {
if (typeof noResize === 'undefined') { noResize = false; }
let skip = false;
Expand Down Expand Up @@ -947,7 +965,12 @@ function load(str, noResize) {
uplim();
if (!skip) { str = str[str.length-1]; }
for (let i = 0; i < str.length; i+=2) {
plot[i/2].setPlant(parseP(rtl[str[i]]), true, parseP(str[i+1]));
let agePlusNull = parseP(str[i+1]);
if (agePlusNull > 4) {
agePlusNull -= 5;
plot[i/2].setNull(true);
}
plot[i/2].setPlant(parseP(rtl[str[i]]), true, agePlusNull);
}
updateStats();
}
Expand Down
9 changes: 9 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,14 @@ input[type="text"] {
transition: opacity 0.2s;
}

.invisTile {
position: relative;
display: inline-block;
width: 40px;
height: 40px;
vertical-align: top;
}

.tile:nth-child(4n+1)::before {
background-position:40px 0px;
}
Expand All @@ -326,6 +334,7 @@ input[type="text"] {
top: -12px;
left: -4px;
background-image: url(images/gardenPlants.png);
visibility: visible;

pointer-events: none;
}
Expand Down

0 comments on commit bf5dc5e

Please sign in to comment.