Module:StoreLine: Difference between revisions

2,023 bytes removed ,  2 February 2023
no ge
(Created page with "local p = {} local lang = mw.language.getContentLanguage() local var = mw.ext.VariablesLua local params = require('Module:Paramtest') local yesno = require('Module:Yesno') local currency_image = require("Module:Currency Image") local commas = require("Module:Addcommas") local exchange = require('Module:Exchange') local find_gevalue = exchange._value local find_geprice = exchange._price local geprices_data = mw.loadData('Module:GEPrices/data') local ptitle = mw.title.g...")
 
(no ge)
 
Line 7: Line 7:
local commas = require("Module:Addcommas")
local commas = require("Module:Addcommas")


local exchange = require('Module:Exchange')
local find_gevalue = exchange._value
local find_geprice = exchange._price
local geprices_data = mw.loadData('Module:GEPrices/data')


local ptitle = mw.title.getCurrentTitle()
local ptitle = mw.title.getCurrentTitle()
Line 42: Line 37:
     local args = frame:getParent().args
     local args = frame:getParent().args
     -- Params and defaults
     -- Params and defaults
     local name, stock, buyvalue, sellvalue, geprice = params.defaults{
     local name, stock, buyvalue, sellvalue = params.defaults{
         {args.name or args.Name, ''},
         {args.name or args.Name, ''},
         {args.stock or args.Stock, ''},
         {args.stock or args.Stock, ''},
         {args.buy or args.Buy, ''},
         {args.buy or args.Buy, ''},
         {args.sell or args.Sell, ''},
         {args.sell or args.Sell, ''},
        {args.geprice or args.geprice, ''}
     }
     }
     local itemvalue = ''
     local itemvalue = ''
Line 54: Line 48:
     local displayname = params.default_to(args.displayname or args.DisplayName,name)
     local displayname = params.default_to(args.displayname or args.DisplayName,name)
     local image = 'File:' .. params.default_to(args.image or args.Image, name .. '.png')
     local image = 'File:' .. params.default_to(args.image or args.Image, name .. '.png')
    local gemw = yesno(args.gemw or 'yes', false)
     local restock = params.default_to(args.restock or args.Restock,-1)
     local restock = params.default_to(args.restock or args.Restock,-1)
      
      
    -- Check precached Module:GEPrices/data
 
    if gemw and geprice == '' then
        local cached_price = geprices_data[gemwname]
        if type(cached_price) == 'number' and cached_price > 0 then
            geprice = cached_price
        end
    end
   
    -- Lookup GE price
    if gemw and geprice == '' then
        local has_geprice, geprice_check = pcall(find_geprice,gemwname)
        if has_geprice and geprice_check > -1 then
            geprice = geprice_check
        end
    end
   
    -- Lookup GE value
    if gemw and itemvalue == '' then
        local has_gevalue, gevalue = pcall(find_gevalue,gemwname)
        if has_gevalue and gevalue > -1 then
            itemvalue = gevalue
        end
    end
   
     -- Lookup SMW value
     -- Lookup SMW value
     if itemvalue == ''  then
     if itemvalue == ''  then
Line 103: Line 73:
         end
         end
     end
     end
   
 
    local buymultiplier = var.var('BuyMultiplier', 1000)
    local sellmultiplier = var.var('SellMultiplier', 1000)
     local currency = var.var('Currency', 'Coins')
     local currency = var.var('Currency', 'Coins')
     local namenotes = var.var('NameNotes', '')
     local namenotes = var.var('NameNotes', '')
    local delta = var.var('Delta', 10)
     local useSmw = yesno(var.var('smw','yes'), true)
     local useSmw = yesno(var.var('smw','yes'), true)
     local hideimage = yesno(var.var('hideImage','no'), false)
     local hideimage = yesno(var.var('hideImage','no'), false)
    local hidege = yesno(var.var('hideGE','no'), false)
     local hidesell = yesno(var.var('hideSell','no'), false)
     local hidesell = yesno(var.var('hideSell','no'), false)
     local hidebuy = yesno(var.var('hideBuy','no'), false)
     local hidebuy = yesno(var.var('hideBuy','no'), false)
Line 121: Line 87:
     local buy_smw = tonumber(buyvalue)
     local buy_smw = tonumber(buyvalue)
     local sell_smw = tonumber(sellvalue) or 1e10
     local sell_smw = tonumber(sellvalue) or 1e10
    local ge_sort = tonumber(geprice)
     local buyCurrency = ''
     local buyCurrency = ''
     local sellCurrency = ''
     local sellCurrency = ''


    if buyvalue ~= 'N/A' then
        if buyvalue == '' and itemvalue ~= '' then
            buyvalue = math.floor(math.max(itemvalue*buymultiplier/1000,itemvalue*0.1))
            buy_smw = buyvalue
        end
        buyvalue = showCurrencyAmount(currency, buyvalue)
    end
    if sellvalue ~= 'N/A' then
        if sellvalue == '' and itemvalue ~= '' then
            sellvalue = math.floor(math.max(itemvalue*sellmultiplier/1000,1))
            sell_smw = sellvalue
        end
        sellvalue = showCurrencyAmount(currency, sellvalue)
    end
 
    if gemw and tonumber(geprice) ~= nil then
        geprice = showCurrencyAmount('coins', geprice)
    else
        ge_sort = 0
        geprice = 'Not sold'
    end
   
     if stock=='inf' then stock='∞' end --inf is easier to type
     if stock=='inf' then stock='∞' end --inf is easier to type
     if stock=='∞' then restock='N/A' end --self-documenting code
     if stock=='∞' then restock='N/A' end --self-documenting code
Line 239: Line 183:
         smw_sub['Store currency'] = currency
         smw_sub['Store currency'] = currency
         smw_sub['Store notes'] = namenotes
         smw_sub['Store notes'] = namenotes
        smw_sub['Store delta'] = delta
         mw.smw.subobject(smw_sub) -- add item subobject to page
         mw.smw.subobject(smw_sub) -- add item subobject to page
         mw.smw.set(smw) -- add data to page
         mw.smw.set(smw) -- add data to page
899

edits