Template talk:Tp

From Guild Wars 2 Wiki
Jump to navigationJump to search

not going to be used anyway…[edit]

Or we could just set a variable on the page..

{{#if: {{#var:TP}} | | {{#Widget:TP prices}}{{#vardefine:TP|+}} }}

-Chieftain AlexUser Chieftain Alex sig.png 07:21, 30 September 2014 (UTC)

The widget itself already does something like this. I was just worried that the (empty) widget call might add some overhead, but that’s probably not all that relevant. For “official” uses in the main namespace, the data attributes should be used anyway, and also offers much more flexibility (e.g. filling table cells instead of spans within table cells). poke | talk 09:21, 30 September 2014 (UTC)

Return cooper[edit]

Would it be possible for it to return price in single coopers, e.g. 15667? It would be useful for some calculations on pages. The F. Prince (talk) 14:37, 17 December 2016 (UTC)

As far as I see, this template only returns item ID in tag, price is calculated and injected by javascript into this tag, so in its current state that wouldn't be possible (I think) Czokalapik Avatar Czokalapik.png 11:22, 5 April 2018 (UTC)

Auto calculations of larger quantity[edit]

I have an idea on how to use this to calculate bulk price, now we can use {{tp|Iron Ore|sell}} to show single iron ore price, what if we could do calculation like {{tp|Iron Ore|sell|151}} to show buy/sell price of 151 Iron ores. For example that would return Gold coin 18 Silver coin 61 Copper coin instead Silver coin 11 Copper coin

Required changes to Template:Tp
<onlyinclude><span class="gw2-tpprice" {{#if:{{{2|}}}|data-info="{{{2}}}"}} {{#if:{{{3|}}}|data-quantity="{{{3}}}"}} data-id="{{#iferror:{{#expr:{{{1|@@@}}}}}|{{#explode:{{#show:{{{1|@@@}}}|?Has game id#}}|,|0}}|{{{1}}}}}">{{{placeholder|…}}}</span></onlyinclude>

or something more "fancy" to check if 3nd and 2nd parameters are present and or are integers or strings and put those variables in correct attributes (to allow different ordering of attributes)

Required changes to tradingPostPrices() function in MediaWiki:Common.js

(modified lines have // comments)

function tradingPostPrices () {
    if ( $('.gw2-tpprice').length === 0 ) {
        return;
    }
    function getCoin (coin, asHtml) {
        var text = (coin % 100) + 'c';
        var html = (coin % 100) + ' <img src="/images/e/eb/Copper_coin.png" alt="Copper" />';
        if (coin >= 100) {
            var silver = (coin / 100 >> 0) % 100;
            html = silver + ' <img src="/images/3/3c/Silver_coin.png" alt="Silver" /> ' + html;
            text = silver + 's ' + text;
        }
        if (coin >= 10000) {
            var gold = coin / 10000 >> 0;
            html = gold + ' <img src="/images/d/d1/Gold_coin.png" alt="Gold" /> ' + html;
            text = gold + 'g ' + text;
        }
        return asHtml ? html : text;
    }
    var elements = {};
    $('.gw2-tpprice').each(function () {
        var id = +this.getAttribute('data-id');
        var quantity = (this.hasAttribute('data-quantity')) ? (Number.isInteger(+this.getAttribute('data-quantity'))) ? +this.getAttribute('data-quantity') : 1 : 1; //check if there is data-quantity, if not, or is not integer, set 1
        if (!id || parseInt(id) != id) {
            return;
        }
        if (!elements[id]) {
            elements[id] = [];
        }
        elements[id].push({ elem: this, info: this.getAttribute('data-info'), quantity: quantity }); //add quantity to elements object
    });
    var ids = $.map(elements, function (o, i) { return i; });
    if (ids.length > 200) {
        console.log('tradingPostPrices: Only up to 200 trading post prices supported per single page.');
        ids = ids.slice(0,200);
    }
    $.getJSON('https://api.guildwars2.com/v2/commerce/prices?wiki=1&lang=en&ids=' + ids.join(',')).done(function (data) {
        $.each(data, function (index, item) {
            var buyText = 'Highest buy order: ' + getCoin(item.buys.unit_price);
            var sellText = 'Lowest sell offer: ' + getCoin(item.sells.unit_price);
            $.each(elements[item.id], function () {
                if (this.info == 'buy') {
                    this.elem.innerHTML = getCoin(item.buys.unit_price*this.quantity, true); //multiply by quantity
                    this.elem.title = buyText + ' (' + item.buys.quantity + ' ordered)';
                    this.elem.setAttribute('data-sort-value',item.buys.unit_price*this.quantity); //multiply by quantity
                }
                else if (this.info == 'sell') {
                    this.elem.innerHTML = getCoin(item.sells.unit_price*this.quantity, true); //multiply by quantity
                    this.elem.title = sellText + ' (' + item.sells.quantity + ' listed)';
                    this.elem.setAttribute('data-sort-value',item.sells.unit_price*this.quantity); //multiply by quantity
                }
                else {
                    this.elem.innerHTML = getCoin(item.sells.unit_price*this.quantity, true); //multiply by quantity
                    this.elem.title = sellText + ' / ' + buyText;
                    this.elem.setAttribute('data-sort-value',item.sells.unit_price*this.quantity); //multiply by quantity
                }
                if ((this.info == 'buy' && !item.buys.quantity) || (this.info != 'buy' && !item.sells.quantity)) {
                    this.elem.style.opacity = '.5';
                }
            });
        });
    });
}

Czokalapik Avatar Czokalapik.png 11:22, 5 April 2018 (UTC)

We don't typically calculate multiple totals on the same page. And we have a widget providing the qty*price functionality already: [[Widget:TP prices total]].
<div class="tpwrapper"><div class="tptotal" data-id="19976" data-qty="30"><span class="tpprice"></span></div></div>{{#Widget:TP prices total}}
-Chieftain AlexUser Chieftain Alex sig.png 17:37, 5 April 2018 (UTC)
but this widget does not put prices inline, and my suggested change is small one ;] plus you have to check every item ID to use TP prices total widget Czokalapik Avatar Czokalapik.png 05:59, 6 April 2018 (UTC)
The Faction Provisioner article could benefit from this proposed functionality. -- Dashface User Dashface.png 13:10, 31 July 2019 (UTC)
Bumping this to voice my support for adding a quantity parameter to this template. This template is used in Template:Vendor table row to calculate the TP cost of a vendor item (eg Black Lion Commemorative Sprocket), but it does not take into account the quantity of the vendor item (such as in the row for Piece of Zhaitaffy). While Template:Tp total placeholder does have quantity functionality, it relies on Template:Tp total calculate which should only be used once per page so it is not suitable for use in Vendor table row. --BuffsEverywhere (talk) 20:27, 10 December 2022 (UTC)
Done. Since parameter 2 is optional, I've set the quantity to be implemented via the "quantity" parameter (same parameter name as used on vendor table row). -Chieftain AlexUser Chieftain Alex sig.png 21:32, 10 December 2022 (UTC)