Editing Module:Sandbox/Asarta/Market

From Fallen London Wiki (Staging)

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 6: Line 6:
 
   ["shilling"] = {name = "Rat-Shilling", symbol = "R"}
 
   ["shilling"] = {name = "Rat-Shilling", symbol = "R"}
 
}
 
}
 
function extract_markets(args)
 
  for k, v in pairs(args) do
 
      if string.match(k, "Buying/Selling") then
 
        local shop_name = string.match(k, "(.-)Buying/Selling")
 
        table.insert(markets, shop_name)
 
      end
 
  end
 
  return markets
 
end
 
 
function extract_information(args, market)
 
  local buying_selling = args[market .. "Buying/Selling"] or nil
 
  if not buying_selling then
 
      return nil
 
  end
 
  local buy_price = string.match(buying_selling, "(.-)/")
 
  local sell_price = string.match(buying_selling, "/(.-)")
 
  local buy_currency = string.match(args[market .. "Buy Currency"], "(.-)")
 
  local sell_currency = string.match(args[market .. "Sell Currency"], "(.-)")
 
  local buy_message = args[market .. "Buy Message"]
 
  local sell_message = args[market .. "Sell Message"]
 
  local shop = args[market .. "Shop"]
 
  local sell_market = args[market .. "Sell Market"]
 
  local sell_market_appearance = args[market .. "Sell Market Appearance"]
 
  return buy_price, sell_price, buy_currency, sell_currency, buy_message, sell_message, shop, sell_market, sell_market_appearance
 
end
 
  
 
function normalise_currency(currency)
 
function normalise_currency(currency)
Line 64: Line 37:
 
end
 
end
 
    
 
    
function create_transaction(buy_price, sell_price, buy_currency, sell_currency, buy_message, sell_message, shop, sell_market, sell_market_appearance)
+
 
 +
function p.create_transaction(buy_price, sell_price, buy_currency, sell_currency, buy_message, sell_message, shop, sell_market, sell_market_appearance)
 
   local buy_currency_name = currency_attributes[buy_currency].name
 
   local buy_currency_name = currency_attributes[buy_currency].name
 
   local sell_currency_name = currency_attributes[sell_currency].name
 
   local sell_currency_name = currency_attributes[sell_currency].name
 
   sell_market_appearance = sell_market_appearance or sell_market
 
   sell_market_appearance = sell_market_appearance or sell_market
 
   local categories = {}
 
   local categories = {}
 +
  -- if buy_price and buy_price is neither - or Echo set properties for
 
   if buy_price and buy_price ~= "-" then
 
   if buy_price and buy_price ~= "-" then
 
       mw.smw.set({"Bought for", buy_price .. ";" .. buy_currency_name .. ";" .. shop})
 
       mw.smw.set({"Bought for", buy_price .. ";" .. buy_currency_name .. ";" .. shop})
 +
      -- if buy_currency is not echoes, set properties for loss of that currency
 
       if buy_currency ~= "echoes" then
 
       if buy_currency ~= "echoes" then
 
         mw.smw.set({"Loses", buy_currency_name})
 
         mw.smw.set({"Loses", buy_currency_name})
Line 76: Line 52:
 
       end
 
       end
 
   end
 
   end
 +
  -- if sell_price and sell_price is neither - or Echo set properties for
 
   if sell_price and sell_price ~= "-" then
 
   if sell_price and sell_price ~= "-" then
 
       mw.smw.set({"Sells for", sell_price .. ";" .. sell_currency_name .. ";" .. sell_market})
 
       mw.smw.set({"Sells for", sell_price .. ";" .. sell_currency_name .. ";" .. sell_market})
Line 95: Line 72:
  
  
   local transaction_table = mw.html.create("table"):addClass("article-table")
+
   local table = mw.html.create("table"):addClass("article-table")
 
 
 
   if buy_price and buy_price ~= "-" then
 
   if buy_price and buy_price ~= "-" then
       transaction_table:tag("tr")
+
       table:tag("tr")
 
         :tag("th"):wikitext("Buying"):done()
 
         :tag("th"):wikitext("Buying"):done()
 
         :tag("td"):wikitext(create_currency_symbol(buy_currency, buy_price))
 
         :tag("td"):wikitext(create_currency_symbol(buy_currency, buy_price))
Line 104: Line 80:
 
         :done()
 
         :done()
 
   end
 
   end
 
 
 
   if sell_price and sell_price ~= "-" then
 
   if sell_price and sell_price ~= "-" then
       transaction_table:tag("tr")
+
       table:tag("tr")
 
         :tag("th"):wikitext("Selling"):done()
 
         :tag("th"):wikitext("Selling"):done()
 
         :tag("td"):wikitext(create_currency_symbol(sell_currency, sell_price))
 
         :tag("td"):wikitext(create_currency_symbol(sell_currency, sell_price))
Line 112: Line 87:
 
         :done()
 
         :done()
 
   end
 
   end
 
 
 
   local output = mw.html.create("div")
 
   local output = mw.html.create("div")
 
   output:node(buying_selling_line)
 
   output:node(buying_selling_line)
   output:node(transaction_table)
+
   output:node(table)
 
   for _, category in ipairs(categories) do
 
   for _, category in ipairs(categories) do
 
       output:wikitext("[[Category:" .. category .. "]]")
 
       output:wikitext("[[Category:" .. category .. "]]")
 
   end
 
   end
 
 
 
   return output  
 
   return output  
 
end
 
end
 
function p.market(frame)
 
local args = frame.args
 
local parentArgs = frame:getParent().args
 
  local all_args = table.merge(args, parentArgs)
 
  local markets = extract_markets(all_args)
 
  local output = mw.html.create("div")
 
  for _, market in ipairs(markets) do
 
      local buy_price, sell_price, buy_currency, sell_currency, buy_message, sell_message, shop, sell_market, sell_market_appearance = extract_information(all_args, market)
 
      output:node(create_transaction(buy_price, sell_price, buy_currency, sell_currency, buy_message, sell_message, shop, sell_market, sell_market_appearance))
 
  end
 
  return output
 
end
 
  
 
return p
 
return p

Please note that all contributions to Fallen London Wiki (Staging) are considered to be released under the Creative Commons Attribution-ShareAlike (see Fallen London Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)
Preview page with this template

Template used on this page: