[0.13-0.15] [Library]Factorio Standard Library Project 0.8.0

Enhance Your Overall Game-Play.
Mod-Database, Calculators, Cheatsheets, Multiplayer, Scripts, Libs and Other Useful Stuff.
User avatar
Afforess
Filter Inserter
Filter Inserter
Posts: 421
Joined: Tue May 05, 2015 6:07 pm

[0.13-0.15] [Library]Factorio Standard Library Project 0.8.0

Post by Afforess » Wed Apr 06, 2016 1:14 am

Type: Library
Name: Factorio Standard Library
Description: The Factorio Standard Library is a project to bring Factorio modders high-quality, commonly-required utilities and tools
License: MIT License
Version: 0.8.0
Release: 2017-01-12
Tested-With-Factorio-Version: 0.13.11+, 0.14.X, 0.15.X
Category: Library
Github: https://github.com/Afforess/Factorio-Stdlib
Releases: https://github.com/Afforess/Factorio-Stdlib/releases
Wiki: https://github.com/Afforess/Factorio-Stdlib/wiki
Lua Docs: http://afforess.github.io/Factorio-Stdlib/

What is the Factorio Standard Library?
Description
Why the Factorio Standard Library?
Why
How do I use the Factorio Standard Library?
Contributing to the Factorio Standard Library
Contributions
Version history
Versions
Last edited by Afforess on Thu Apr 27, 2017 11:28 pm, edited 25 times in total.

seronis
Fast Inserter
Fast Inserter
Posts: 225
Joined: Fri Mar 04, 2016 8:04 pm

Re: [0.12.x] [Library] Factorio Standard Library Project

Post by seronis » Wed Apr 06, 2016 4:49 am

Outstanding. Thank you for your work

Supercheese
Filter Inserter
Filter Inserter
Posts: 823
Joined: Mon Sep 14, 2015 7:40 am

Re: [0.12.x] [Library] Factorio Standard Library Project

Post by Supercheese » Wed Apr 06, 2016 10:07 pm

Another nice bit to have would be a function to copy the contents of one inventory into another (perhaps even with filters to only copy certain types of items?)

A simplistic example:

Code: Select all

function copyInventory(from, to)
	local inventory = from.get_inventory(defines.inventory.chest)
	local contents = inventory.get_contents()
	for n, c in pairs(contents) do
		to.insert({name=n, count=c})
	end
end
I'm not sure the above code will work in all cases, though -- like for blueprints, it might not copy over the set-up blueprint but just give a blank one instead. And it hardcodes the #define for chest, rather than allowing others like player inventory, etc.

User avatar
Afforess
Filter Inserter
Filter Inserter
Posts: 421
Joined: Tue May 05, 2015 6:07 pm

Re: [0.12.x] [Library] Factorio Standard Library Project

Post by Afforess » Thu Apr 07, 2016 2:12 am

Supercheese wrote:Another nice bit to have would be a function to copy the contents of one inventory into another (perhaps even with filters to only copy certain types of items?)

A simplistic example:

Code: Select all

function copyInventory(from, to)
	local inventory = from.get_inventory(defines.inventory.chest)
	local contents = inventory.get_contents()
	for n, c in pairs(contents) do
		to.insert({name=n, count=c})
	end
end
I'm not sure the above code will work in all cases, though -- like for blueprints, it might not copy over the set-up blueprint but just give a blank one instead. And it hardcodes the #define for chest, rather than allowing others like player inventory, etc.
Inventory.copy_inventory is now in release 0.1.0.

Also notable, all of the code except the logging is currently unit tested. This actually caught a bug in the codebase, and has already proven valuable. ;)

User avatar
Afforess
Filter Inserter
Filter Inserter
Posts: 421
Joined: Tue May 05, 2015 6:07 pm

Re: [0.12.x] [Library] Factorio Standard Library Project 0.2.0

Post by Afforess » Sat Apr 09, 2016 4:11 am

Version 0.2.0 released. More functions, more unit tests, and now, error messages for missing arguments when using stdlib apis. See the API docs or changelog for details.

User avatar
Afforess
Filter Inserter
Filter Inserter
Posts: 421
Joined: Tue May 05, 2015 6:07 pm

Re: [0.12.x] [Library] Factorio Standard Library Project 0.2.1

Post by Afforess » Tue Apr 12, 2016 4:03 am

Version 0.2.1 is released. Two new Area functions, and improved the documentation for the Area functions.

MrDoomah
Fast Inserter
Fast Inserter
Posts: 195
Joined: Mon Jun 01, 2015 1:11 pm

Re: [0.12.x] [Library] Factorio Standard Library Project 0.2.1

Post by MrDoomah » Tue Apr 12, 2016 9:13 am

Hey, perhaps you can include my code for finding all entities (or filtered entities):

Code: Select all

function create_number_table(array)
	local new_array = {}
	for _,v in pairs(array) do
		table.insert(new_array,v)
	end
	return new_array
end

function find_entities(input)
	-- input = {name = string, type = string, force = string or force, surface = string or {table of surface(s)}
	local array = {}
	
	if type(input.surface) == "string" then input.surface = {game.surfaces[input.surface]} end
	local surfaces = input.surface or game.surfaces
	
	for _,surface in pairs(surfaces) do
		for chunk in surface.get_chunks() do
			local entities = surface.find_entities_filtered{
				area = {left_top = {chunk.x*32, chunk.y*32}, right_bottom = {(chunk.x+1)*32, (chunk.y+1)*32}}, 
				name = input.name, 
				type = input.type, 
				force = input.force}
			for _,entity in ipairs(entities) do
				array["x"..entity.position.x.."y"..entity.position.y] = entity
			end
		end
	end
	return create_number_table(array)
end
Input is a table containing:
name (string)
type (string)
force (string or force (eg game.player.force)
surface (string eg "nauvis" or table of surfaces eg {game.player.surface}, you can't input game.player.surface directly without brackets)
all optional.

The create_number_array() function is optional, it just make sure that your returned array is nicely ordered so you can do a #operator on it.

It could technically overwrite entities if they are on the same spot since I just their location as key for the array. (This is on purpose so that entities that are on chuck borders don't appear twice in the array, without the need to check the array whether or not that entity is already in it.)

User avatar
Afforess
Filter Inserter
Filter Inserter
Posts: 421
Joined: Tue May 05, 2015 6:07 pm

Re: [0.12.x] [Library] Factorio Standard Library Project 0.2.1

Post by Afforess » Sun Apr 24, 2016 10:11 pm

Factorio Stdlib 0.3.0 is released, with many new additions. See the changelog for full details.
MrDoomah wrote:Hey, perhaps you can include my code for finding all entities (or filtered entities)
Thanks for the suggestion. 0.3.0 includes Surface.find_all_entities, which closely matches what you suggested.

User avatar
Afforess
Filter Inserter
Filter Inserter
Posts: 421
Joined: Tue May 05, 2015 6:07 pm

Re: [0.12.x] [Library] Factorio Standard Library Project 0.4.0

Post by Afforess » Mon May 09, 2016 11:11 pm

Factorio Standard Library 0.4.0 is released! Many improvements to core classes, like table and string. Factorio Standard Library is entirely forward compatible, if you are on an old version, there is zero risk in upgrading.

User avatar
Afforess
Filter Inserter
Filter Inserter
Posts: 421
Joined: Tue May 05, 2015 6:07 pm

Re: [0.12.x] [Library] Factorio Standard Library Project 0.4.0

Post by Afforess » Tue May 10, 2016 2:53 am

I've updated the wiki with two new examples on how to use the Factorio Standard Library:

The first new example is on avoiding iteration, and general stdlib tools: https://github.com/Afforess/Factorio-St ... dlib-tools

The second new example is on how to take advantage of entity data storage: https://github.com/Afforess/Factorio-St ... ntity-data

kasandraen
Inserter
Inserter
Posts: 40
Joined: Wed May 27, 2015 11:00 pm

Re: [0.12.x] [Library] Factorio Standard Library Project 0.4.0

Post by kasandraen » Tue May 10, 2016 3:48 pm

I know a few functions I'd like to have easier acces to. dysoch use them a lot in Dytech. If you check Dytech Core and the Ovvrire functions, the functions like change recipe, addtorecipe etc are really helpful to use

User avatar
Afforess
Filter Inserter
Filter Inserter
Posts: 421
Joined: Tue May 05, 2015 6:07 pm

Re: [0.12.x] [Library] Factorio Standard Library Project 0.4.0

Post by Afforess » Tue May 10, 2016 5:05 pm

kasandraen wrote:I know a few functions I'd like to have easier acces to. dysoch use them a lot in Dytech. If you check Dytech Core and the Ovvrire functions, the functions like change recipe, addtorecipe etc are really helpful to use
Sounds like a good idea. I haven't written a utility for the data class yet, but it is high on my list of things to improve.

orzelek
Smart Inserter
Smart Inserter
Posts: 3254
Joined: Fri Apr 03, 2015 10:20 am

Re: [0.12.x] [Library] Factorio Standard Library Project 0.4.0

Post by orzelek » Tue May 10, 2016 5:15 pm

Afforess wrote:
kasandraen wrote:I know a few functions I'd like to have easier acces to. dysoch use them a lot in Dytech. If you check Dytech Core and the Ovvrire functions, the functions like change recipe, addtorecipe etc are really helpful to use
Sounds like a good idea. I haven't written a utility for the data class yet, but it is high on my list of things to improve.
You should talk with bobbingabout - he wrote boblibrary and those kind of functions are there already.

User avatar
Afforess
Filter Inserter
Filter Inserter
Posts: 421
Joined: Tue May 05, 2015 6:07 pm

Re: [0.12.x] [Library] Factorio Standard Library Project 0.4.0

Post by Afforess » Tue May 10, 2016 5:22 pm

orzelek wrote:
Afforess wrote:
kasandraen wrote:I know a few functions I'd like to have easier acces to. dysoch use them a lot in Dytech. If you check Dytech Core and the Ovvrire functions, the functions like change recipe, addtorecipe etc are really helpful to use
Sounds like a good idea. I haven't written a utility for the data class yet, but it is high on my list of things to improve.
You should talk with bobbingabout - he wrote boblibrary and those kind of functions are there already.
I've seen and used a few of those myself for Marathon, so I know exactly what you are referring to ;)

jorgenRe
Filter Inserter
Filter Inserter
Posts: 535
Joined: Wed Apr 09, 2014 3:32 pm

Re: [0.12.x] [Library] Factorio Standard Library Project 0.4.0

Post by jorgenRe » Tue May 10, 2016 5:33 pm

Like this :)!

:ugeek:
[spoiler=Logo]Image[/spoiler]
Noticed the told change in FFF #111 so il continue to use my signature ^_^
Thanks for listening to our suggestions, devs :D!
I would jump of joy if we could specify which tiles spawned in a surfaces

User avatar
CorrettoSambuca
Long Handed Inserter
Long Handed Inserter
Posts: 57
Joined: Sun May 04, 2014 9:29 am

Re: [0.12.x] [Library] Factorio Standard Library Project 0.4.0

Post by CorrettoSambuca » Tue May 10, 2016 7:03 pm

Hi, just leaving a note to say thanks for your work :)

By the way, is there an easy way to trigger events on a clock? For example every sunset and so on...

User avatar
y.petremann
Filter Inserter
Filter Inserter
Posts: 389
Joined: Mon Mar 17, 2014 4:24 pm

Re: [0.12.x] [Library] Factorio Standard Library Project 0.4.0

Post by y.petremann » Thu May 12, 2016 1:42 am

Something that would be really great would be a gui library (like what I already do in diplomacy) that would permit :
  • Creating template (with styles) that can later be used needing less repetition of code and a better understanding of the code.
  • Anonymous gui elements (sometimes you don't need a name for a label you never touch again)
  • Advanced element event callback :
    • All : custom function callback and arguments per elements (like I do to pass arguments in diplomacy)
    • Checkbox : Current state
    • Text Area : Text content
    {*]Widgets groups : They will act like a single wigdet and so modifying a property would modify the widget inside it :
    • An example would be a progressbar with label.
    • Simple question dialog.
      {*]Item cell.

User avatar
Afforess
Filter Inserter
Filter Inserter
Posts: 421
Joined: Tue May 05, 2015 6:07 pm

Re: [0.12.x] [Library] Factorio Standard Library Project 0.4.0

Post by Afforess » Thu May 12, 2016 2:01 am

CorrettoSambuca wrote:Hi, just leaving a note to say thanks for your work :)

By the way, is there an easy way to trigger events on a clock? For example every sunset and so on...
There isn't (you could do an event on tick, and check the time of day), but clock events are an interesting idea.

User avatar
Afforess
Filter Inserter
Filter Inserter
Posts: 421
Joined: Tue May 05, 2015 6:07 pm

Re: [0.12.x] [Library] Factorio Standard Library Project 0.4.0

Post by Afforess » Thu May 12, 2016 2:03 am

y.petremann wrote:Something that would be really great would be a gui library (like what I already do in diplomacy) that would permit :
  • Creating template (with styles) that can later be used needing less repetition of code and a better understanding of the code.
  • Anonymous gui elements (sometimes you don't need a name for a label you never touch again)
  • Advanced element event callback :
    • All : custom function callback and arguments per elements (like I do to pass arguments in diplomacy)
    • Checkbox : Current state
    • Text Area : Text content
    {*]Widgets groups : They will act like a single wigdet and so modifying a property would modify the widget inside it :
    • An example would be a progressbar with label.
    • Simple question dialog.
      {*]Item cell.
Yea, I have some minor experience with the GUI library, and I will suffice to say it could be massively improved by a library like stdlib. I agree with custom callbacks (the one giant event the game currently offers leads to terrible code most of the time), and the idea of creating gui templates is intriguing. I think there is a lot of ideas that for this particular part of the API.

User avatar
Afforess
Filter Inserter
Filter Inserter
Posts: 421
Joined: Tue May 05, 2015 6:07 pm

Re: [0.12.x] [Library] Factorio Standard Library Project 0.5.0

Post by Afforess » Sun Jun 12, 2016 5:48 pm

The Factorio Standard Library 0.5.0 is released, with a number of improvements & a few bug fixes:

Version 0.5.0
  • Improved table.map, filter, and each to also include additional arguments and index.
  • Added Event.core_events, allows registering Events for on_init, on_load, and on_configuration_changed
  • Added options to Logger.new, adds option to modify the file extension and alter the timestamp format
  • Added Chunk.get to calculate the chunk coordinates for a given tile position
  • Added Chunk.get_data, retrieves mod data stored on a chunk position
  • Added Chunk.set_data sets mod data on a chunk position
  • Added Tile.from_position, calculates tile coordinates from a position
  • Added Tile.to_area, returns the area that a single tile occupies
  • Added Tile.get_data, retrieves mod data stored on a tile position
  • Added Tile.set_data, sets mod data on a tile position
  • Added Area.spiral_iterate, is an alternate iterator (compared to Area.iterate) that iterates the Area in an inside-out spiral fashion
  • Added Area.center, returns the center position of an Area
  • Added string.contains, tests if a string contains a substring
  • Added Time contants, provides easy reference for Time.SECOND, Time.MINUTE, Time.HOUR, Time.DAY, and Time.WEEK in factorio tick time
  • Improved the lua docs, so they share the same look and feel as the factorio lua docs
  • Fixed Logger writing after one hour instead of one minute
  • Fixed Event registry with Event.core_events.init not raising errors correctly
  • Note: Thanks to mojo2012, Choumiko, and Supercheese for their contributions to 0.5.0

Post Reply

Return to “Tools”