Simple Compress

by Zaflis

Adds recipes to compress and decompress ores and plates

5 months ago
0.17 - 1.1

g Guide to adding compress support to other mods through this one

2 years ago
(updated 3 months ago)

While it is possible for me to add support for other mods, it is possible to do it other way around too, and it is just as simple. It comes in 2-3 parts, adding code that is run in data/prototype phase and a locale name for each compressed item. You can look for examples in this mod's code (mods.lua), and you have available code from functions.lua. The 3rd part is either using compressed graphics from this mod or make new one to yours. You can recolor from white version of icon using R,G,B in range 0..1.

Here is an example data.lua, if i were to make quarries compressable (comments are extra):

-- function SimpleCompress_AddTintedItem(_name, _order, _icon, _tint)
-- Valid _icon values are all "graphics\compressed-__icon__.png" files
-- _order is largely irrelevant, use item name to sort items alphabetically.

if simpleCompress then
  -- Where do we want the compressed item(s) to show?
  -- Same place as quarry itself maybe
  simpleCompress.currentSubgroup = data.raw.item["quarry"].subgroup
  -- Or in the intermediates? simpleCompress.currentSubgroup = "intermediate-product"

  --if simpleCompress.ores then
    -- If you had ores, put them here... Unlock with OreTech


  if simpleCompress.plates then

    -- Lets show these quarries as squeezed red plates...
    SimpleCompress_AddTintedItem("quarry", "quarry", "plate", {r=1, g=0, b=0})
    SimpleCompress_UnlockPlateTechAndRecipe("quarry") -- Unlock with same item name

And related locale\en\locale.cfg:

compressed-quarry=Compressed quarries

Now you could also make new image in "graphics\" folder for the compressed item, call it "compressed-quarry.png", and use "quarry" instead of "plate" in the TintedItem function.

And last but not least this mod needs to be added as optional dependency in the info.json.
"dependencies": [ "base >= 0.17", "? SimpleCompress >= 0.17.4"],

functions.lua contents for addon modding:

function SimpleCompress_AddTintedItem(_name, _order, _icon, _tint)
_name can be anything, spaces are not recommended in any name or icon parameters.
_order is about where it shows up in crafting UI compared to other recipes and sorted alphabetically. Use your modname shortened for example.
_icon will use "/graphics/compressed-" .. _icon .. ".png" textures that come with SimpleCompress.
_tint is a color like {r=0.62, g=0.8, b=1}.

function SimpleCompress_AddCustomItem(_name, _order, _icon, _iconsize)
_icon is intended for using full filename path here for texture.
_iconsize size of icon.

function SimpleCompress_AddCustomIcons(_name, _order, _icons)
_icons in this function is a table. A table can have values like "icon", "icon_size" and "tint", wrapped in { } and separated by commas.

function SimpleCompress_AddRecipe(_name, _ingredient)
_name still should use same name as the icon.
_ingredient is internal name of the original unstacked item.

function SimpleCompress_AddSmeltingRecipe(_name, _result)
_result is internal name of the item made by smelting. Amount assumes 1:1 smelting ratio affected by the ratio multiplier in mod settings.
If you want to customize this more, see recipe.lua at "-- Compressed ores" section where compressed-stone smelting is dealt with by altering data.raw. However i don't recommend making smelting recipes for advanced alloys such as bob's mods. You can just uncompress the items first and deal with it normally.

function SimpleCompress_UnlockOreTech(_name)
function SimpleCompress_UnlockOreSmeltingTech(_name)
function SimpleCompress_UnlockPlateTech(_name)
function SimpleCompress_UnlockPlateSmeltingTech(_name)
_name using same name as with icons and recipes for these.

function SimpleCompress_AddProductivity(_recipe)
_recipe using full name such as "smelt-compressed-" .. _name. Primarily smelting recipes uses productivity, compressing and uncompressing in assembler should not as that would lead to infinite item generation. Call this function after the smelting recipe is made.

6 months ago

Is there a function to add items using costume icons? SE received a request to add support, and we already have stacked icons for deadlock stacking, so it would be simple for us to use those icons.

6 months ago
(updated 6 months ago)

Oh... i never realized this issue before. Functions that other mods should be able to use are in prototypes\functions.lua, however currently they assume all graphics come from this mod's graphics and that is a mistake.

I need to think about a solution but also taking suggestions. It will likely effect other lua files calling these functions too, unless i just add new functions that take full names.

I mean textures in this mod are all grayscale, you can just recolor them to match whatever type of ore or plate. Unless they are fundamentally different shape...

6 months ago
(updated 6 months ago)

So i can add these:
function SimpleCompress_AddCustomItem(_name, _icon, _order)
function SimpleCompress_AddCustomTintedItem(_name, _order, _icon, _tint)

Would you say iconsize parameter is needed as well, or that we can all expect them to be 32 pixels?

As for the deadlock's icons, now that i think about it, they might be generated on the fly... not in a file? In that case the parameter i'd take is the actual icon and not filename. How complicated...

6 months ago
(updated 6 months ago)

These should cover all options:
function SimpleCompress_AddCustomItem(_name, _order, _icon, _iconsize)
function SimpleCompress_AddCustomIcons(_name, _order, _icons)

The _icons can be gotten from an existing variable or defined like:
icon = "SimpleCompress/graphics/compressed-iconname.png",
icon_size = 32,
tint = {r=1, g=0, b=0}
I am unsure if you need to wrap it in doubles or not {{ ... }} It will either start or don't - I use doubles in the other functions.

I don't have test addon mod to really try it but i'll check that game starts without errors, see things in test-save and upload.

5 months ago

Allow a full icon parameter, plus an icon size parameter.
You can even have the parameter be a table, which would allow named keys inside of that table, which can you can make assumptions about if they're absent (for example, if icon size is not specified, assume 32)

5 months ago

Yes, this SimpleCompress_AddCustomIcons() takes in a table. I uploaded the version earlier.

3 months ago

Thanks for this guide. I've added compatibility to Titanium and Lead mods.

One note, you might want to link this guide from your main description so it's easier to find.

3 months ago

I updated description and also first post a bit. I thought those functions deserve an explanation.

New response