You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.8 KiB

2 years ago
"use strict"
class Message{
constructor(type){
let set = settings.messages[type];
this.getFullHTML(set);
}
static Won(){return "won";}
static Lost(){return "lost";}
static New(){return "newGame";}
static Credits(){return "credits";}
getFullHTML(set){
let self = this;
this.html = set.html;
this.styles = set.styles;
this.buttons = [];
for (let b of set.buttons){
let htmlButton = $("<button></button>");
htmlButton.text(b.text);
htmlButton.css(b.styles);
htmlButton.click(function(){self.buttonClicked(b);});
this.buttons.push(htmlButton);
}
}
buttonClicked(setButton){
eval(setButton.onclick);
this.destroy(this);
}
display(){
let pane = $("<div></div>");
pane.css(this.styles);
pane.append(this.html);
for (let b of this.buttons) pane.append(b);
pane.attr("id", "message");
$("#messageWrapper").append(pane);
$("#messageWrapper").show();
}
destroy(obj){
$("#messageWrapper").hide();
$("#messageWrapper").html("");
obj = null;
}
}
function prepareCredits(){
credits = credits.credits;
let htmlCredits = $("<div></div>");
htmlCredits.attr("id", "creditsTableWrapper");
let table = "<table id=\"creditsTable\" align=\"center\">";
table += "<tr>";
for (let prop in credits[0]){
table += "<th>" + prop.capitalize() + "</th>";
}
table += "</tr>";
for (let c of credits){
let section = "<tr>";
for (let prop in c){
let link = {open: "", close: ""};
if (prop === "link"){
link.open = "<a href=\"" + c[prop] + "\" target=\"_blank\">";
link.close = "</a>";
}
section += "<td>" + link.open + c[prop] + link.close + "</td>";
}
section += "</tr>";
table += section;
}
table += "</table>";
htmlCredits.append($(table));
settings.messages.credits.html = htmlCredits;
}