Spaces:
Sleeping
Sleeping
File size: 4,394 Bytes
90cbf22 8cbe088 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
import * as PIXI from 'pixi.js'
import { g_ctx } from './lecontext.js' // global context
import * as CONFIG from './leconfig.js'
// --
// Set sizes and limits for HTML in main UI
// --
export function initMainHTMLWindow() {
document.getElementById("layer0pane").style.maxWidth = ""+CONFIG.htmlLayerPaneW+"px";
document.getElementById("layer0pane").style.maxHeight = ""+CONFIG.htmlLayerPaneH+"px";
document.getElementById("layer1pane").style.maxWidth = ""+CONFIG.htmlLayerPaneW+"px";
document.getElementById("layer1pane").style.maxHeight = ""+CONFIG.htmlLayerPaneH+"px";
document.getElementById("layer2pane").style.maxWidth = ""+CONFIG.htmlLayerPaneW+"px";
document.getElementById("layer2pane").style.maxHeight = ""+CONFIG.htmlLayerPaneH+"px";
document.getElementById("layer3pane").style.maxWidth = ""+CONFIG.htmlLayerPaneW+"px";
document.getElementById("layer3pane").style.maxHeight = ""+CONFIG.htmlLayerPaneH+"px";
document.getElementById("tilesetpane").style.maxWidth = ""+CONFIG.htmlTilesetPaneW+"px";
document.getElementById("tilesetpane").style.maxHeight = ""+CONFIG.htmlTilesetPaneH+"px";
document.getElementById("compositepane").style.maxWidth = ""+CONFIG.htmlCompositePaneW+"px";
document.getElementById("compositepane").style.maxHeight = ""+CONFIG.htmlCompositePaneH+"px";
// hide map tab
let mappane = document.getElementById("map");
mappane.style.display = "none";
}
// --
// Initialize handlers for file loading
// --
// --
// Initialize handlers loading a PNG file into the composite window
// --
export function initCompositePNGLoader() {
const fileInput = document.getElementById('compositepng');
fileInput.onchange = (evt) => {
if (!window.FileReader) return; // Browser is not compatible
if (g_ctx.debug_flag) {
console.log("compositepng ", fileInput.files[0].name);
}
let bgname = fileInput.files[0].name;
const texture = PIXI.Texture.from("./tilesets/"+bgname);
const bg = new PIXI.Sprite(texture);
bg.zIndex = 0;
g_ctx.composite.container.addChild(bg);
}
}
// --
// initailized handler to load a spriteSheet into current working tile
// --
export function initSpriteSheetLoader() {
const fileInput = document.getElementById('spritesheet');
fileInput.onchange = async (evt) => {
if (!window.FileReader) return; // Browser is not compatible
if (g_ctx.debug_flag) {
console.log("spritesheet ", fileInput.files[0].name);
}
let ssname = fileInput.files[0].name;
let sheet = await PIXI.Assets.load("./"+ssname);
console.log(sheet);
g_ctx.tileset.addTileSheet(ssname, sheet);
g_ctx.selected_tiles = [];
}
}
// --
// initailized handler to load a new tileset
// --
export function initTilesetLoader(callme) {
const fileInput = document.getElementById('tilesetfile');
fileInput.onchange = async (evt) => {
if (!window.FileReader) return; // Browser is not compatible
if (g_ctx.debug_flag) {
console.log("tilesetfile ", fileInput.files[0].name);
}
g_ctx.tilesetpath = "./tilesets/"+fileInput.files[0].name;
callme();
}
}
// --
// initailized handler to load a level from a file
// --
function doimport (str) {
if (globalThis.URL.createObjectURL) {
const blob = new Blob([str], { type: 'text/javascript' })
const url = URL.createObjectURL(blob)
const module = import(url)
URL.revokeObjectURL(url) // GC objectURLs
return module
}
const url = "data:text/javascript;base64," + btoa(moduleData)
return import(url)
}
export function initLevelLoader(callme) {
let filecontent = "";
const fileInput = document.getElementById('levelfile');
fileInput.onchange = (evt) => {
if (!window.FileReader) return; // Browser is not compatible
var reader = new FileReader();
reader.onload = function (evt) {
if (evt.target.readyState != 2) return;
if (evt.target.error) {
alert('Error while reading file');
return;
}
filecontent = evt.target.result;
doimport(filecontent).then(mod => callme(mod));
};
reader.readAsText(evt.target.files[0]);
}
} |