UNPKG

@moderrkowo/jsgl

Version:

Client-side JavaScript library for creating web 2D games. Focusing at objective game.

49 lines (48 loc) 2.01 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExampleHTML = void 0; var ExampleHTMLProperties_1 = require("../structs/ExampleHTMLProperties"); /** * Helps with creating game page. * @group Tools */ var ExampleHTML = /** @class */ (function () { function ExampleHTML() { } /** * Creates HTML game page with given properties. * Page is sized to viewport and canvas is centered. * @param props The properties. */ ExampleHTML.Render = function (props) { props = __assign(__assign({}, ExampleHTMLProperties_1.exampleHTMLDefaultProperties), props); if (!(props.document instanceof Document)) { if (document instanceof Document) { props.document = document; } else { throw new Error("Default DOM cannot be assigned! Please assign document to 'document' property"); } } // eslint-disable-next-line max-len props.document.write('<div style="width: 100%;height: 100%;display: flex;align-items: center;justify-content: center;flex-direction: column;"><canvas id="gameCanvas">Your browser does not support the HTML 5 canvas.</canvas></div>'); props.document.body.style.height = '100vh'; props.document.body.style.width = '100vw'; props.document.body.style.margin = '0'; if (props.backgroundColor !== undefined) props.document.body.style.backgroundColor = props.backgroundColor; }; return ExampleHTML; }()); exports.ExampleHTML = ExampleHTML;