Editing Module:Test/lib/util

Jump to navigation Jump to search

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 1: Line 1:
if mw then
 
  Search = Search or require("Module:Test/lib/search")
 
else
 
  Search = Search or require "lib/search"
 
end
 
 
 
local util = {}
 
local util = {}
  
Line 12: Line 6:
  
 
util.table = {}
 
util.table = {}
 
function util.table.check(tbl, ...)
 
  local inside = tbl
 
  for i,v in pairs(arg) do
 
    if i ~= 'n' then
 
      inside = Search.find(v, inside or {})
 
    end
 
  end
 
  return inside and true
 
end
 
 
function util.table.checkMultiple(tbl, filters)
 
  local checked = false
 
  for _,filter in ipairs(filters) do
 
    if util.table.check(tbl, unpack(filter)) then
 
      checked = true
 
    else
 
      return false
 
    end
 
  end
 
  return checked
 
end
 
 
function util.table.isIn(var, table)
 
  assert(type(var) == 'nil', "isIn: Empty argument #1")
 
  assert(type(table) == 'table', string.format("isIn: Bad argument #2 ('table' expected, got '%s'", type(table)))
 
  for k,v in pairs(table) do
 
    if var == k or var == v then
 
      return true
 
    end
 
  end
 
  return false
 
end
 
  
 
-- procedure
 
-- procedure
Line 135: Line 96:
  
 
   for k, v in pairs(tbl) do
 
   for k, v in pairs(tbl) do
     local formatting = string.rep("  ", indent) .. k .. ": "
+
     formatting = string.rep("  ", indent) .. k .. ": "
 
     if type(v) == "table" then
 
     if type(v) == "table" then
 
       print(formatting)
 
       print(formatting)
Line 186: Line 147:
 
end
 
end
  
function util.round(num, numDecimalPlaces)
+
----------
   return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
+
-- diet --
 +
----------
 +
 
 +
util.diet = {}
 +
 
 +
util.diet.foodType = {
 +
  None = true,
 +
  VegetableOrFruit = true,
 +
  Meat = true,
 +
  Fluid = true,
 +
  Corpse = true,
 +
  Seed = true,
 +
  AnimalProduct = true,
 +
  Plant = true,
 +
  Tree = true,
 +
  Meal = true,
 +
  Processed = true,
 +
  Liquor = true,
 +
  Kibble = true,
 +
  VegetarianAnimal = {
 +
    VegetableOrFruit = true,
 +
    Seed = true,
 +
    Meal = true,
 +
    Processed = true,
 +
    Liquor = true,
 +
    Kibble = true
 +
  },
 +
  VegetarianRoughAnimal = {
 +
    VegetableOrFruit = true,
 +
    Seed = true,
 +
    Plant = true,
 +
    Meal = true,
 +
    Processed = true,
 +
    Liquor = true,
 +
    Kibble = true
 +
  },
 +
  CarnivoreAnimal = {
 +
    Meat = true,
 +
    Corpse = true,
 +
    Meal = true,
 +
    Processed = true,
 +
    Kibble = true
 +
  },
 +
  CarnivoreAnimalStrict = {
 +
    Meat = true,
 +
    Corpse = true
 +
  },
 +
  OmnivoreAnimal = {
 +
    VegetableOrFruit = true,
 +
    Meat = true,
 +
    Corpse = true,
 +
    Seed = true,
 +
    Meal = true,
 +
    Processed = true,
 +
    Liquor = true,
 +
    Kibble = true
 +
  },
 +
  OmnivoreRoughAnimal = {
 +
    VegetableOrFruit = true,
 +
    Meat = true,
 +
    Corpse = true,
 +
    Seed = true,
 +
    Plant = true,
 +
    Meal = true,
 +
    Processed = true,
 +
    Liquor = true,
 +
    Kibble = true
 +
  },
 +
  DendrovoreAnimal = {
 +
    VegetableOrFruit = true,
 +
    Seed = true,
 +
    Tree = true,
 +
    Processed = true,
 +
    Kibble = true
 +
  },
 +
  OvivoreAnimal = {
 +
    AnimalProduct = true,
 +
    Meal = true,
 +
    Processed = true,
 +
    Kibble = true
 +
  },
 +
  OmnivoreHuman = {
 +
    VegetableOrFruit = true,
 +
    Meat = true,
 +
    Fluid = true,
 +
    Corpse = true,
 +
    Seed = true,
 +
    AnimalProduct = true,
 +
    Meal = true,
 +
    Processed = true,
 +
    Liquor = true,
 +
    Kibble = true
 +
  }
 +
}
 +
 
 +
function util.diet.resolveDietCategory(foodType)
 +
   if foodType.None then
 +
      return "Never eats"
 +
  end
 +
  if foodType.Tree then
 +
      return "Dendrovorous"
 +
  end
 +
  if foodType.Meat then
 +
      if foodType.VegetableOrFruit or foodType.Plant then
 +
          return "Omnivorous"
 +
      end
 +
      return "Carnivorous"
 +
  end
 +
  if foodType.AnimalProduct then
 +
      return "Ovivorous"
 +
  end
 +
  return "Herbivorous"
 
end
 
end
  
 
return util -- return module
 
return util -- return module

Please note that all contributions to RimWorld Wiki are considered to be released under the CC BY-SA 3.0 (see RimWorld 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)