Actions

Fabled and MediaWiki:Common.js: Difference between pages

From Blood on the Clocktower Wiki

(Difference between pages)
No edit summary
 
No edit summary
 
Line 1: Line 1:
<div class="row">
$("li:contains('Toolbox')").hide();


<div class="small-12 large-12 columns">
$("img").contextmenu(function () {
    return false;
});


Fabled characters are for the Storyteller. They each alter the conditions of the game somewhat and are usually included at the beginning of the game.
$(document).ready(function () {
    handleAudioElements();
    replaceRolesWithAbilities();
});


The purpose of a Fabled character is to allow players to join in a game of Clocktower when they would otherwise not be able to, or to allow a game to run smoothly when there would otherwise be a real-world issue. Fabled characters fix problems that are outside the usual game parameters.
function replaceRolesWithAbilities()
{
    fetch("https://wiki.bloodontheclocktower.com/roles.json").then(function(resp)
    {
        if (resp.ok)
        {
            resp.json().then(function(roles)
            {
                console.log(roles);


For example, if a player has a mental disability that would normally mean that they are unable to understand the game rules or communicate with the group, a Fabled character can allow them to join in. If a player is new to the game, and fearful that they will die early, a Fabled character can protect them. If there are too many players wanting to play all at once, a Fabled character can make the game run more quickly. If one of the group is shy or softly spoken, and has trouble getting the groups attention, a Fabled character can give them the powers to do so. If the game needs to end unexpectedly early, a Fabled character can decide a winner. If you have made your own character list using the Script character list generator, a Fabled character can help it be more fun.
                document.querySelectorAll("[data-role]").forEach(function(e)
                {
                    let filtered = roles
                        .filter(function(r) {
                            return r.name === e.dataset.role;
                        })


__TOC__
                    if (filtered > 0) {
                        e.dataset.role = filtered[0].ability
                    }
                    else {
                        delete e.dataset.role;
                    }
                });
            })
        }
        else
        {
            console.log("clearing")
            document.querySelectorAll("[data-role]").forEach(function(e)
            {
                delete e.dataset.role;
            });
        }
    });
}


== Any Game ==
function handleAudioElements()
{
    document.querySelectorAll('.html5audio:not(.loaded)').forEach(function (div) {
        var data = div.dataset;
        var file = data.file;
        if (!file) {
            return;
        }
        var format = file.split('.').pop();
        var preload = data.preload;
        var download = data.download;
        var options = data.options;
        var opts = { controls: '' };
        var volume = Number(Number(data.volume).toFixed(1));


<div class="row">
        if (format === 'mp3') {
<div class="small-6 medium-6 large-2 columns">
            format = 'mpeg';
[[File:icon_doomsayer.png|250px|thumb|center|link=Doomsayer]]
        }
<p style="text-align: center; font-family: Trade Gothic LT Std; font-size: 18px;">{{Fabled|Doomsayer}}</p>
</div>
<div class="small-6 medium-6 large-2 columns">
[[File:icon_angel.png|250px|thumb|center|link=Angel]]
<p style="text-align: center; font-family: Trade Gothic LT Std; font-size: 18px;">{{Fabled|Angel}}</p>
</div>
<div class="small-6 medium-6 large-2 columns">
[[File:icon_buddhist.png|250px|thumb|center|link=Buddhist]]
<p style="text-align: center; font-family: Trade Gothic LT Std; font-size: 18px;">{{Fabled|Buddhist}}</p>
</div>
<div class="small-6 medium-6 large-2 columns">
[[File:icon_hellslibrarian.png|250px|thumb|center|link=Hell's Librarian]]
<p style="text-align: center; font-family: Trade Gothic LT Std; font-size: 18px;">{{Fabled|Hell's Librarian}}</p>
</div>
<div class="small-6 medium-6 large-2 columns">
[[File:icon_revolutionary.png|250px|thumb|center|link=Revolutionary]]
<p style="text-align: center; font-family: Trade Gothic LT Std; font-size: 18px;">{{Fabled|Revolutionary}}</p>
</div>
<div class="small-6 medium-6 large-2 columns">
[[File:icon_fiddler.png|250px|thumb|center|link=Fiddler]]
<p style="text-align: center; font-family: Trade Gothic LT Std; font-size: 18px;">{{Fabled|Fiddler}}</p>
</div>
</div>


<div class="row">
        if (format === 'm4a') {
<div class="small-6 medium-6 large-2 columns">
            format = 'mp4';
[[File:icon_toymaker.png|250px|thumb|center|link=Toymaker]]
        }
<p style="text-align: center; font-family: Trade Gothic LT Std; font-size: 18px;">{{Fabled|Toymaker}}</p>
</div>
</div>


== Custom Games ==
        if (preload !== 'auto' || preload !== 'metadata') {
            preload = 'none';
        }
        opts.preload = preload;


<div class="row">
        if (download === 'false') {
<div class="small-6 medium-6 large-2 columns">
            opts.controlsList = 'nodownload';
[[File:icon_fibbin.png|250px|thumb|center|link=Fibbin]]
        }
<p style="text-align: center; font-family: Trade Gothic LT Std; font-size: 18px;">{{Fabled|Fibbin}}</p>
</div>
<div class="small-6 medium-6 large-2 columns">
[[File:icon_duchess.png|250px|thumb|center|link=Duchess]]
<p style="text-align: center; font-family: Trade Gothic LT Std; font-size: 18px;">{{Fabled|Duchess}}</p>
</div>
<div class="small-6 medium-6 large-2 columns">
[[File:icon_sentinel.png|250px|thumb|center|link=Sentinel]]
<p style="text-align: center; font-family: Trade Gothic LT Std; font-size: 18px;">{{Fabled|Sentinel}}</p>
</div>
<div class="small-6 medium-6 large-2 columns">
[[File:icon_spiritofivory.png|250px|thumb|center|link=Spirit of Ivory]]
<p style="text-align: center; font-family: Trade Gothic LT Std; font-size: 18px;">{{Fabled|Spirit of Ivory}}</p>
</div>
<div class="small-6 medium-6 large-2 end columns">
[[File:icon_djinn.png|250px|thumb|center|link=Djinn]]
<p style="text-align: center; font-family: Trade Gothic LT Std; font-size: 18px;">{{Fabled|Djinn}}</p>
</div>
</div>


== Experimental ==
        if (options) {
            var valid = ['autoplay', 'loop', 'muted'];
            options.split(',').forEach(function (el) {
                el = el.trim();
                if (valid.indexOf(el) !== -1) {
                    opts[el] = '';
                }
            });
        }


<div class="row">
        var audio = document.createElement('audio');
<div class="small-12 medium-12 large-2 end columns">
[[File:icon_stormcatcher.png|250px|thumb|center|link=Storm Catcher]]
<p style="text-align: center; font-family: Trade Gothic LT Std; font-size: 18px;">{{Fabled|Storm Catcher}}</p>
</div>
</div>


</div>
        Object.keys(opts).forEach(function (attr) {
</div>
            var value = opts[attr];
            audio.setAttribute(attr, value);
        });
 
        var source = document.createElement('source');
        source.src = file;
        source.type = 'audio/' + format;
 
        audio.append(source);
 
        if (volume >= 0 && volume <= 1) {
            audio.volume = volume;
        }
 
        div.innerHTML = '';
        div.appendChild(audio);
        div.classList.add('loaded');
    })
}

Revision as of 20:41, 4 April 2023

$("li:contains('Toolbox')").hide();

$("img").contextmenu(function () {
    return false;
});

$(document).ready(function () {
    handleAudioElements();
    replaceRolesWithAbilities();
});

function replaceRolesWithAbilities() 
{
    fetch("https://wiki.bloodontheclocktower.com/roles.json").then(function(resp) 
    { 
        if (resp.ok) 
        {
            resp.json().then(function(roles) 
            {
                console.log(roles);

                document.querySelectorAll("[data-role]").forEach(function(e) 
                {
                    let filtered = roles
                        .filter(function(r) {
                            return r.name === e.dataset.role;
                        })

                    if (filtered > 0) {
                        e.dataset.role = filtered[0].ability
                    }
                    else {
                        delete e.dataset.role;
                    }
                });
            })
        }
        else 
        {
            console.log("clearing")
            document.querySelectorAll("[data-role]").forEach(function(e) 
            {
                delete e.dataset.role;
            });
        }
    });
}

function handleAudioElements() 
{
    document.querySelectorAll('.html5audio:not(.loaded)').forEach(function (div) {
        var data = div.dataset;
        var file = data.file;
        if (!file) {
            return;
        }
        var format = file.split('.').pop();
        var preload = data.preload;
        var download = data.download;
        var options = data.options;
        var opts = { controls: '' };
        var volume = Number(Number(data.volume).toFixed(1));

        if (format === 'mp3') {
            format = 'mpeg';
        }

        if (format === 'm4a') {
            format = 'mp4';
        }

        if (preload !== 'auto' || preload !== 'metadata') {
            preload = 'none';
        }
        opts.preload = preload;

        if (download === 'false') {
            opts.controlsList = 'nodownload';
        }

        if (options) {
            var valid = ['autoplay', 'loop', 'muted'];
            options.split(',').forEach(function (el) {
                el = el.trim();
                if (valid.indexOf(el) !== -1) {
                    opts[el] = '';
                }
            });
        }

        var audio = document.createElement('audio');

        Object.keys(opts).forEach(function (attr) {
            var value = opts[attr];
            audio.setAttribute(attr, value);
        });

        var source = document.createElement('source');
        source.src = file;
        source.type = 'audio/' + format;

        audio.append(source);

        if (volume >= 0 && volume <= 1) {
            audio.volume = volume;
        }

        div.innerHTML = '';
        div.appendChild(audio);
        div.classList.add('loaded');
    })
}