123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- /// <reference path="../World/MachineBegins.ts" />
- /// <reference path="../World/TurnSequence.ts" />
- module Elements {
- export var animationTime = 1000;
- export var isMobile = /Mobi/i.test(navigator.userAgent); // This correctly lets Mobile users who requested the Desktop app or are on a sufficiently big tablet to get the right desktop version
- export var screenWidth = document.body.clientWidth;
- export var screenHeight = document.body.clientHeight;
- export function getLinkElements (image? : boolean) {
- if (CurrentTurnHandler == undefined) return [];
- if (CurrentTurnHandler.isTurn() || image) {
- return [CurrentTurnHandler.currentTurnTab];
- } else {
- return [HyperlinkHandler.linkedActionsTab, RoomHandler.currentRoomTab, HyperlinkHandler.commonActionsTab, CurrentTurnHandler.currentTurnTab, RoomHandler.currentRoomExits];
- }
- }
- export function updateScreenSize () {
- screenWidth = document.body.clientWidth;
- screenHeight = document.body.clientHeight;
- }
- export var mainPage = document.getElementById("mainPage");
- /**
- * Adds the blur effect to the screen
- */
- export function startTurn () {
- mainPage.classList.add("turn");
- }
- /**
- * Remove the blur effect from the screen
- */
- export function endTurn () {
- mainPage.classList.remove("turn");
- }
- /**
- * Are we currently in a turn?
- * @returns {boolean}
- */
- export function isInTurn () {
- return mainPage.classList.contains("turn");
- }
- let menuOutsideofTurn = false;
- let menus = 0;
- export function startMenu () {
- if (!isInTurn()) {
- menuOutsideofTurn = true;
- startTurn();
- }
- mainPage.classList.add("mainmenu");
- menus++;
- Elements.CurrentTurnHandler.clear();
- Controls.KeyHandler.reset();
- }
- export function endMenu () {
- Elements.CurrentTurnHandler.clear();
- if (--menus == 0) {
- if (menuOutsideofTurn) {
- endTurn();
- }
- resetMenus();
- }
- }
- export function resetMenus () {
- if (menus != 0) {
- console.error("A menu wasn't finished properly. Please correct the dialogue.");
- }
- menus = 0;
- menuOutsideofTurn = false;
- mainPage.classList.remove("mainmenu");
- }
- export function clearMainScreen () {
- Elements.CurrentTurnHandler.clear();
- }
- let loadingScreen = document.getElementById("loadingScreen");
- export function stopLoading () {
- document.body.removeChild(loadingScreen);
- }
- export async function waitForAnyKey () {
- let say = new Say(Say.CENTERED, new SayBold("Press any key to continue."));
- let elements = await say.getHTML("p", ["content"]);
- Elements.CurrentTurnHandler.print(...elements);
- await Controls.KeyHandler.getNextKey();
- Elements.CurrentTurnHandler.unprint(...elements);
- }
- export async function waitForSpaceKey () {
- let say = new Say(Say.CENTERED, new SayBold("Press Space to continue."));
- let elements = await say.getHTML("p", ["content"]);
- Elements.CurrentTurnHandler.print(...elements);
- let lastKey = "notSpace";
- while (lastKey != "Space" && lastKey != "Click") {
- lastKey = (await Controls.KeyHandler.getNextKey()).evCode;
- }
- Elements.CurrentTurnHandler.unprint(...elements);
- }
- export function printObeliskLogo () {
- let say = new Say(Say.CENTERED, new SayImage("introLogo"), Say.LINE_BREAK, new SayItalic("The Obelisk is a pornographic interactive fiction game set in a post-apocalyptic world ravaged by a magical structure."));
- Elements.CurrentTurnHandler.printAsContent(say);
- }
- export function getStyle (name : string) {
- try {
- for (var i = 0; i < document.styleSheets.length; i++) {
- var rules = document.styleSheets[i]['rules'] || document.styleSheets[i]['cssRules'];
- for (var x in rules) {
- if (typeof rules[x].selectorText == 'string' && rules[x].selectorText == name) {
- return rules[x].style;
- }
- }
- }
- } catch (e) {
- console.warn("Can't read CSS styles", e);
- return {};
- }
- }
- }
- if (Elements.isMobile) {
- Elements.mainPage.classList.add("mobile");
- }
- window.addEventListener("resize", function () {
- Elements.updateScreenSize();
- });
- module MachineBegins {
- export let HideLoadingDivRule = MachineBegins.rulebook.createAndAddRule({
- name : "Hide loading div",
- code : runner => {
- Elements.stopLoading();
- }
- });
- }
- module TurnSequence {
- export let LazilyFixMenus = TurnSequence.rulebook.createAndAddRule({
- name : "Fix menus that were never closed because the dev is stupid",
- firstPriority : Rule.PRIORITY_LOWEST,
- priority : Rule.PRIORITY_LOWEST,
- code : () => {
- Elements.resetMenus();
- }
- })
- }
|