123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- /// <reference path="../Say.ts" />
- /// <reference path="../../../Controls/Modules/KeyHandler.ts" />
- /// <reference path="../../../World/MachineBegins.ts" />
- class SayImage implements PrintableElement {
- public static imageNames : Array<SayImage> = [];
- public static loadTimeCheck : boolean = false;
- public static imageViewer : HTMLElement = <HTMLElement> document.getElementById("imageViewer");
- private imgName : string;
- private isImageDefined () {
- return Elements.getStyle("." + this.imgName) != undefined;
- }
- public constructor (imgName : string) {
- this.imgName = imgName;
- if (!SayImage.loadTimeCheck && SayImage.imageNames.indexOf(this) == -1) {
- SayImage.imageNames.push(this);
- }
- }
- public getImageElement () : Element {
- let img = document.createElement("div");
- if (this.isImageDefined()) {
- img.classList.add(this.imgName);
- img.classList.add("contentImage");
- } else {
- img.classList.add("error");
- img.appendChild(document.createTextNode("Image \"" + this.imgName + "\" not found."));
- }
- img.addEventListener("click", () => {
- SayImage.showInViewer(this);
- });
- Controls.KeyHandler.applyCode(img, Controls.KeyHandler.imageKeyCode.getValue());
- return img;
- }
- public getPrintedElement () {
- return [this.getImageElement()];
- }
- public static doLoadTimeCheck() {
- for (let i = 0; i < SayImage.imageNames.length; i++) {
- let image = SayImage.imageNames[i];
- if (!image.isImageDefined()) {
- if (Settings.hardDebug) {
- Elements.CurrentTurnHandler.printAsError("Image \"" + image.imgName + "\" was not found.");
- }
- console.error("Image \"" + image.imgName + "\" was not found.");
- }
- }
- SayImage.loadTimeCheck = true;
- }
- public static showInViewer (image : SayImage) {
- if (!(SayImage.imageViewer.style.display == 'block')) {
- SayImage.imageViewer.addEventListener("click", () => {
- SayImage.imageViewer.style.display = "none";
- });
- SayImage.imageViewer.className = image.imgName;
- SayImage.imageViewer.style.display = "block";
- } else {
- SayImage.imageViewer.style.display = "none";
- }
- }
- }
- module MachineBegins {
- export let ImageLoadTimeCheck = MachineBegins.rulebook.createAndAddRule({
- firstPriority : Rule.PRIORITY_HIGHEST, // We want this to print to the top of the console
- name : "Check for undefined images",
- code : () => {
- try {
- SayImage.doLoadTimeCheck();
- } catch (e) {
- console.warn("Can't check for undefined images.");
- }
- }
- });
- }
|