Initial commit
This commit is contained in:
commit
ced2a4c3e4
|
@ -0,0 +1 @@
|
|||
*.zip
|
|
@ -0,0 +1,33 @@
|
|||
column_limit: 100
|
||||
indent_width: 2
|
||||
use_tab: false
|
||||
tab_width: 4
|
||||
continuation_indent_width: 4
|
||||
keep_simple_control_block_one_line: false
|
||||
keep_simple_function_one_line: false
|
||||
align_args: true
|
||||
break_after_functioncall_lp: false
|
||||
break_before_functioncall_rp: false
|
||||
align_parameter: true
|
||||
chop_down_parameter: true
|
||||
break_after_functiondef_lp: true
|
||||
break_before_functiondef_rp: true
|
||||
align_table_field: true
|
||||
break_after_table_lb: true
|
||||
break_before_table_rb: true
|
||||
chop_down_table: false
|
||||
chop_down_kv_table: true
|
||||
column_table_limit: 100
|
||||
column_table_limit_kv: 100
|
||||
table_sep: ","
|
||||
extra_sep_at_table_end: true
|
||||
break_after_operator: false
|
||||
single_quote_to_double_quote: true
|
||||
double_quote_to_single_quote: false
|
||||
spaces_before_call: 1
|
||||
spaces_inside_functiondef_parens: false
|
||||
spaces_inside_functioncall_parens: false
|
||||
spaces_inside_table_braces: false
|
||||
spaces_around_equals_in_field: true
|
||||
line_breaks_after_function_body: 1
|
||||
line_separator: input
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"recommendations": [
|
||||
"koihik.vscode-lua-format",
|
||||
],
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"editor.detectIndentation": false,
|
||||
"editor.tabSize": 4,
|
||||
"editor.insertSpaces": false,
|
||||
"[lua]": {
|
||||
"editor.detectIndentation": false,
|
||||
"editor.tabSize": 2,
|
||||
"editor.insertSpaces": true,
|
||||
},
|
||||
"vscode-lua-format.configPath": ".vscode/.lua-format"
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
How to Contribute
|
||||
=================
|
||||
|
||||
We'd love to accept your patches and contributions to this project.
|
||||
We just need you to follow the Contributor License Agreement outlined
|
||||
in the latest v0.0.x of https://github.com/Skrunix/license
|
|
@ -0,0 +1,7 @@
|
|||
Skrunix Software License
|
||||
========================
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software is
|
||||
outlined in the latest v0.0.x of https://github.com/Skrunix/license
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS"
|
|
@ -0,0 +1,15 @@
|
|||
# Standard Library
|
||||
|
||||
Factorio Modding Standard Library
|
||||
|
||||
---
|
||||
|
||||
### Data
|
||||
```lua
|
||||
fmsl.log.color = true
|
||||
```
|
||||
|
||||
### Control
|
||||
```lua
|
||||
fmsl = require("__fmsl__.fmsl")
|
||||
```
|
|
@ -0,0 +1,9 @@
|
|||
---------------------------------------------------------------------------------------------------
|
||||
Version: 0.0.1
|
||||
Date: 15.09.2024
|
||||
Features:
|
||||
- Initial release
|
||||
Scripting:
|
||||
- table.remove_key
|
||||
- fmsl.table.merge
|
||||
- fmsl.array.concat
|
|
@ -0,0 +1,4 @@
|
|||
require("std.array")
|
||||
require("std.table")
|
||||
|
||||
fmsl = {log = require("std.log")}
|
|
@ -0,0 +1,4 @@
|
|||
require("std.array")
|
||||
require("std.table")
|
||||
|
||||
return {box = require("fmsl.box"), position = require("fmsl.position"), log = require("std.log")}
|
|
@ -0,0 +1,48 @@
|
|||
-- Bounding-box defined by two points
|
||||
--
|
||||
-- Represented as {left_top = Position, right_bottom = Position} or {Position, Position}
|
||||
local Box = {}
|
||||
|
||||
-- Asserts that the box is valid
|
||||
-- @param box: Box or Any
|
||||
-- @return ERROR
|
||||
function Box.assert(box)
|
||||
local box_type = type(box)
|
||||
if box_type ~= "table" then
|
||||
error("Unsupported box type: " .. box_type)
|
||||
end
|
||||
|
||||
local box_left_top = box.left_top or box[1]
|
||||
local box_left_top_type = type(box_left_top)
|
||||
if box_left_top_type ~= "table" then
|
||||
error("Box has invalid left_top type: " .. box_left_top_type)
|
||||
end
|
||||
fmsl.position.assert(box_left_top)
|
||||
|
||||
local box_right_bottom = box.right_bottom or box[2]
|
||||
local box_right_bottom_type = type(box_right_bottom)
|
||||
if box_right_bottom_type ~= "table" then
|
||||
error("Box has invalid right_bottom type: " .. box_right_bottom_type)
|
||||
end
|
||||
fmsl.position.assert(box_right_bottom)
|
||||
end
|
||||
|
||||
-- Create a new box
|
||||
-- @param center: Position
|
||||
-- @param radius: double
|
||||
-- @return Box
|
||||
function Box.center_radius(center, radius)
|
||||
fmsl.position.assert(center)
|
||||
|
||||
local radius_type = type(radius)
|
||||
if radius_type ~= "number" then
|
||||
error("Radius has invalid x type: " .. radius_type)
|
||||
end
|
||||
|
||||
return {
|
||||
left_top = fmsl.position.sub(center, radius),
|
||||
right_bottom = fmsl.position.add(center, radius),
|
||||
}
|
||||
end
|
||||
|
||||
return Box
|
|
@ -0,0 +1,62 @@
|
|||
-- Coordinates on a surface
|
||||
--
|
||||
-- Represented as {x = double, y = double} or {double, double}
|
||||
local Position = {}
|
||||
|
||||
-- Asserts that the position is valid
|
||||
-- @param position: Position or Any
|
||||
-- @return ERROR
|
||||
function Position.assert(position)
|
||||
local position_type = type(position)
|
||||
if position_type ~= "table" then
|
||||
error("Unsupported position type: " .. position_type)
|
||||
end
|
||||
|
||||
local position_x_type = type(position.x or position[1])
|
||||
if position_x_type ~= "number" then
|
||||
error("Position has invalid x type: " .. position_x_type)
|
||||
end
|
||||
|
||||
local position_y_type = type(position.y or position[2])
|
||||
if position_y_type ~= "number" then
|
||||
error("Position has invalid y type: " .. position_x_type)
|
||||
end
|
||||
end
|
||||
|
||||
-- Add the offset to the position
|
||||
-- @param position: Position
|
||||
-- @param offset: Position or double
|
||||
-- @return Position
|
||||
function Position.add(position, offset)
|
||||
fmsl.position.assert(position)
|
||||
|
||||
if type(offset) == "number" then
|
||||
return {x = (position.x or position[1]) + offset, y = (position.y or position[2]) + offset}
|
||||
end
|
||||
|
||||
if type(offset) == "table" then
|
||||
return {x = (position.x or position[1]) + offset, y = (position.y or position[2]) + offset}
|
||||
end
|
||||
|
||||
error("Unsupported offset type: " .. type(offset))
|
||||
end
|
||||
|
||||
-- Subtract the offset to the position
|
||||
-- @param position: Position
|
||||
-- @param offset: Position or double
|
||||
-- @return Position
|
||||
function Position.sub(position, offset)
|
||||
fmsl.position.assert(position)
|
||||
|
||||
if type(offset) == "number" then
|
||||
return {x = (position.x or position[1]) - offset, y = (position.y or position[2]) - offset}
|
||||
end
|
||||
|
||||
if type(offset) == "table" then
|
||||
return {x = (position.x or position[1]) - offset, y = (position.y or position[2]) - offset}
|
||||
end
|
||||
|
||||
error("Unsupported offset type: " .. type(offset))
|
||||
end
|
||||
|
||||
return Position
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "fmsl",
|
||||
"version": "0.0.1",
|
||||
"title": "Standard Library",
|
||||
"description": "Factorio Modding Standard Library",
|
||||
"author": "David Skrundz",
|
||||
"contact": "david@skrundz.ca",
|
||||
"homepage": "https://git.skrundz.dev/skrundztorio/fmsl",
|
||||
"factorio_version": "1.1",
|
||||
"dependencies": []
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import os
|
||||
from zipfile import ZipFile
|
||||
|
||||
modFiles = [
|
||||
"info.json",
|
||||
"changelog.txt",
|
||||
"thumbnail.png",
|
||||
"LICENSE.md",
|
||||
|
||||
"data.lua",
|
||||
"fmsl.lua",
|
||||
]
|
||||
modFolders = [
|
||||
"fmsl",
|
||||
"std",
|
||||
]
|
||||
|
||||
with open("info.json") as file:
|
||||
modInfo = json.load(file)
|
||||
|
||||
mod_name = modInfo["name"]
|
||||
mod_version = modInfo["version"]
|
||||
zipName = f"{mod_name}_{mod_version}"
|
||||
|
||||
with ZipFile(f"{zipName}.zip", 'w') as modZip:
|
||||
for file in modFiles:
|
||||
modZip.write(file, arcname=f"{zipName}/{file}")
|
||||
for folder in modFolders:
|
||||
for root, dirs, files in os.walk(folder):
|
||||
for file in files:
|
||||
filePath = os.path.join(root, file)
|
||||
archivePath = os.path.relpath(filePath, os.path.join(folder, '..'))
|
||||
modZip.write(filePath, arcname=f"{zipName}/{archivePath}")
|
|
@ -0,0 +1,14 @@
|
|||
-- Concatenate multiple arrays into a new table, in order
|
||||
-- @param ...: Table
|
||||
-- @return Table
|
||||
function table.concat_new(...)
|
||||
local result = {}
|
||||
for _, array in ipairs({...}) do
|
||||
if array then
|
||||
for _, value in ipairs(array) do
|
||||
table.insert(result, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
local Log = {
|
||||
color = false,
|
||||
checkmarks = {
|
||||
[false] = {[false] = "✗", [true] = "✓"},
|
||||
[true] = {[false] = "❌", [true] = "✅"},
|
||||
},
|
||||
}
|
||||
|
||||
function Log.checkmark(success)
|
||||
return Log.checkmarks[Log.color][success]
|
||||
end
|
||||
|
||||
return Log
|
|
@ -0,0 +1,24 @@
|
|||
-- Remove a key from a table and return the value
|
||||
-- @param table: Table
|
||||
-- @param key: Any
|
||||
-- @return Any
|
||||
function table.remove_key(table, key)
|
||||
local value = table[key]
|
||||
table[key] = nil
|
||||
return value
|
||||
end
|
||||
|
||||
-- Merge multiple tables into a new table, with later tables taking precedence
|
||||
-- @param ...: Table
|
||||
-- @return Table
|
||||
function table.merge_new(...)
|
||||
local result = {}
|
||||
for _, table in ipairs({...}) do
|
||||
if table then
|
||||
for key, value in pairs(table) do
|
||||
result[key] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
Loading…
Reference in New Issue