Skip to content

Commit

Permalink
[Picross] Add old 3DS support
Browse files Browse the repository at this point in the history
  • Loading branch information
magiczocker10 authored Jul 13, 2024
1 parent 595fa5e commit 8977d68
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 deletions games/picross/picross.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
window.addEventListener('load', function() {
var currentNews, buttonSelectX, buttonSelectY;
Element.prototype.appendNew = function(tagname, attributes1, attributes2) {
/* Examples:
/* Examples:
myElem.appendNew("div") -> myElem.innerHTML == "<div></div>"
myElem.appendNew("div", "Hello, world!") -> myElem.innerHTML == "<div>Hello, world!</div>"
myElem.appendNew("div", {id: "foo"}) -> myElem.innerHTML == "<div id='foo'></div>"
Expand All @@ -9,15 +10,15 @@ window.addEventListener('load', function() {
attributes1 = attributes1 || "";
attributes2 = attributes2 || "";
var content,
attributes;
attributes;
if(typeof attributes1 === "object") {
attributes = attributes1;
content = attributes2;
attributes = attributes1;
content = attributes2;
} else {
attributes = {};
content = attributes1;
attributes = {};
content = attributes1;
}

var elem = document.createElement(tagname);
if (tagname !== 'input') elem.innerHTML = content;
for (var attribute in attributes) {
Expand Down Expand Up @@ -58,19 +59,20 @@ window.addEventListener('load', function() {
};

Element.prototype.getChildByClassName = function(name) {
var children = this.childNodes;
for(var i = 0; i < children.length; i++) {
if(children[i].class == name) {
var children = this.childNodes;
for(var i = 0; i < children.length; i++) {
console.log(children[i].className);
if(children[i].className == name) {
return children[i];
}
}
}
};

Element.prototype.makeLastChild = function () {
tempDiv = this.parentNode.appendNew("div");
var tempDiv = this.parentNode.appendNew("div");
this.parentNode.insertBefore(this, tempDiv);
this.parentNode.removeChild(tempDiv);
}
};

function boardClick(event, buttons, non) {
if (event.target.getAttribute("data-state") != "flagged" && document.getElementById("flag").checked) {
Expand All @@ -96,7 +98,7 @@ window.addEventListener('load', function() {
}

if (non.tutorial !== null) {
title.appendNew("div", { "id": "tutorial" }, non.tutorial)
title.appendNew("div", { "id": "tutorial" }, non.tutorial);
}

const board = document.getElementById("board"),
Expand All @@ -107,10 +109,10 @@ window.addEventListener('load', function() {
tool.appendNew("input", {"type": "checkbox", "id": "flag"});
tool.appendNew("lable", {"for": "flag"}, "Flag");
const hb = home.appendNew("button", {"id": "homeButton"}, "Home");
hb.addEventListener("click", doFadeToLS);
hb.addEventListener("click", doFadeToLS, false);

fadeDiv.makeLastChild();


var tr = table.appendNew("thead").appendNew("tr");
tr.appendNew("th");
Expand Down Expand Up @@ -249,7 +251,7 @@ window.addEventListener('load', function() {

document.getElementById("winMessage").innerHTML = "You win!";
}

function doFadeAndStart(lt) {
const ls = document.getElementById("levelSelect") || document.getElementById("bottom-screen").appendNew("div", {"id": "levelSelect"});
const fadeDiv = ls.parentNode.appendNew("div", {"id": "LevelFadeTransition", "style": "display: none;"});
Expand Down Expand Up @@ -298,24 +300,24 @@ window.addEventListener('load', function() {
clearInterval(fadeTimeout);
fadeDiv.parentNode.removeChild(fadeDiv);
}

fadeTimer++;
}, 10);
}

function showLevelSelect() {
document.getElementById("title").innerHTML = currentNews;
document.getElementById("board").innerHTML = "";
document.getElementById("winMessage").innerHTML = "";
tool = document.getElementById("tool");
home = document.getElementById("home");
var tool = document.getElementById("tool"),
home = document.getElementById("home");
if(tool) {
tool.parentNode.removeChild(tool);
}
if(home) {
home.parentNode.removeChild(home);
}

buttonSelectX = 0;
buttonSelectY = 0;
const ls = document.getElementById("levelSelect") || document.getElementById("bottom-screen").appendNew("div", {"id": "levelSelect"}),
Expand Down Expand Up @@ -360,16 +362,16 @@ window.addEventListener('load', function() {
if(!oldSelectedLevel) {
return;
}

if(button == "A") {
const selectedLevel = document.getElementById("lt_" + buttonSelectX + "," + buttonSelectY);
selectedLevel.startIconAnim();
doFadeAndStart(selectedLevel);
return;
}

oldSelectedLevel.stopIconAnim();

if(button == "Up") {
buttonSelectY -= 1;
}
Expand All @@ -395,15 +397,15 @@ window.addEventListener('load', function() {
if(buttonSelectY < 0) {
buttonSelectY = 0;
}

const newSelectedLevel = document.getElementById("lt_" + buttonSelectX + "," + buttonSelectY);
newSelectedLevel.startIconAnim();
}
currentNews = document.getElementById("title").innerHTML;
onBtnJustPressed("A", function() {levelSelectButton("A")});
onBtnJustPressed("Up", function() {levelSelectButton("Up")});
onBtnJustPressed("Down", function() {levelSelectButton("Down")});
onBtnJustPressed("Left", function() {levelSelectButton("Left")});
onBtnJustPressed("Right", function() {levelSelectButton("Right")});
currentNews = document.getElementById("title").innerHTML;
onBtnJustPressed("A", function() {levelSelectButton("A");});
onBtnJustPressed("Up", function() {levelSelectButton("Up");});
onBtnJustPressed("Down", function() {levelSelectButton("Down");});
onBtnJustPressed("Left", function() {levelSelectButton("Left");});
onBtnJustPressed("Right", function() {levelSelectButton("Right");});
showLevelSelect();
}, false);

0 comments on commit 8977d68

Please sign in to comment.