4 * Copyright 2020 Elias Fleckenstein <eliasfleckenstein@web.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23 dragonblocks.Texture = class{
25 this.name = path.slice(path.lastIndexOf("/") + 1, path.length);
27 dragonblocks.textures[this.name] = this;
30 dragonblocks.textures = {};
31 dragonblocks.loadTexture = function(path){
32 new dragonblocks.Texture(path);
35 let textures = $.getJSON({
38 data: {call: "getTextures"}
40 for(let i in textures)
41 dragonblocks.loadTexture(textures[i]);
43 dragonblocks.getTexture = function(texture){
46 if(dragonblocks.textures[texture])
47 return "url(" + dragonblocks.textures[texture].path + ")";
51 dragonblocks.resolveTextures = function(elem){
52 if(elem.nodeName == "IMG" && elem.attributes["texture"]){
53 let texture = elem.attributes["texture"].nodeValue;
54 elem.src = dragonblocks.textures[texture] ? dragonblocks.textures[texture].path : texture;
56 for(let child of elem.children)
57 dragonblocks.resolveTextures(child);
59 dragonblocks.Sound = class{
61 this.name = path.slice(path.lastIndexOf("/") + 1, path.length);
63 dragonblocks.sounds[this.name] = this;
66 dragonblocks.sounds = {};
67 dragonblocks.loadSound = function(path){
68 new dragonblocks.Sound(path);
70 dragonblocks.getSound = function(sound){
73 if(dragonblocks.sounds[sound])
74 return dragonblocks.sounds[sound].path;
79 let sounds = $.getJSON({
82 data: {call: "getSounds"}
85 dragonblocks.loadSound(sounds[i]);
87 dragonblocks.playSound = function(sound){
88 new Audio(dragonblocks.getSound(sound)).play();