1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-05 22:53:39 +02:00

Fix linting (#657)

Fix linting warnings
This commit is contained in:
Matthew 2019-01-19 11:34:29 -05:00 committed by GitHub
parent 41c89a0ca8
commit 0927a839b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 248 additions and 187 deletions

View File

@ -177,8 +177,8 @@ Module.undo =
local new_entity = place_entity_on_surface(e, RS.get_surface(), false, last_user)
--Transfer items
if new_entity then
local player = Utils.ternary(new_entity.last_user, new_entity.last_user, game.player)
local event = {created_entity = new_entity, player_index = player.index, stack = {}}
local event_player = Utils.ternary(new_entity.last_user, new_entity.last_user, game.player)
local event = {created_entity = new_entity, player_index = event_player.index, stack = {}}
script.raise_event(defines.events.on_built_entity, event)
if e.type == 'container' then

View File

@ -3,7 +3,6 @@ local Gui = require 'utils.gui'
local Global = require 'utils.global'
local UserGroups = require 'features.user_groups'
local Game = require 'utils.game'
local Utils = require 'utils.core'
local Command = require 'utils.command'
local deafult_verb = 'expanded'

View File

@ -10,6 +10,8 @@ local Token = require 'utils.token'
local Event = require 'utils.event'
local Utils = require 'utils.core'
local Global = require 'utils.global'
local table = require 'utils.table'
local config = global.config.redmew_qol
-- Localized functions

View File

@ -86,7 +86,7 @@ local turrent_callback =
end
)
return function(_, _, world)
return function(_, _, world) -- luacheck: ignore 561
local entities = {}
local surface = world.surface

View File

@ -1,7 +1,7 @@
local data =
{
{
weight = 1
weight = 1,
thresholds =
{
{value = 400, name = nil},

View File

@ -29,7 +29,7 @@ for a, b in pairs(ore_ratios) do
end
end
return function(x, y, world)
return function(_, _, world)
local d = world.x * world.x + world.y * world.y
if d <= starting_distance then
return nil

View File

@ -13,7 +13,7 @@ local function harmonic(x, y)
local max_idx = 0
local max = -1
local richness = 0
for i, e in ipairs(ctrs) do
for i in ipairs(ctrs) do
local noise = perlin.noise(x / 32, y / 32, ctrs[i][6])
local h_coeff =
1 /
@ -31,7 +31,7 @@ local function harmonic(x, y)
return max, max_idx, richness
end
return function(x, y, world)
return function(_, _, world)
if math.abs(world.x / 32) < 3 and math.abs(world.y / 32) < 3 then
return
end

View File

@ -11,7 +11,7 @@ Event.on_init(init)
local radius = 10
local radius_sq = radius * radius
return function(x, y, world)
return function(_, _, world)
local entities = world.surface.find_entities_filtered {position = {world.x + 0.5, world.y + 0.5}, type = "resource"}
for _, e in ipairs(entities) do
e.destroy()

View File

@ -1,3 +1,7 @@
local Command = require 'utils.command'
local insert = table.insert
local function get_mins(entities, tiles)
local min_x, min_y = math.huge, math.huge
@ -28,67 +32,69 @@ local function get_mins(entities, tiles)
return min_x, min_y
end
local function output(result, prepend, size)
local function output(result, prepend, size, player)
local str = {prepend}
table.insert(str, '{\npart_size = ')
table.insert(str, size)
table.insert(str, ',\n')
insert(str, '{\npart_size = ')
insert(str, size)
insert(str, ',\n')
for i, entry in pairs(result) do
table.insert(str, '[')
table.insert(str, i)
table.insert(str, '] = {')
insert(str, '[')
insert(str, i)
insert(str, '] = {')
local e = entry.entity
if e then
table.insert(str, 'entity = {')
insert(str, 'entity = {')
table.insert(str, "name = '")
table.insert(str, e.name)
table.insert(str, "'")
insert(str, "name = '")
insert(str, e.name)
insert(str, "'")
local dir = e.direction
if dir then
table.insert(str, ', direction = ')
table.insert(str, dir)
insert(str, ', direction = ')
insert(str, dir)
end
local offset = e.offset
if offset then
table.insert(str, ', offset = ')
table.insert(str, offset)
insert(str, ', offset = ')
insert(str, offset)
end
table.insert(str, '}')
insert(str, '}')
end
local t = entry.tile
if t then
if e then
table.insert(str, ', ')
insert(str, ', ')
end
table.insert(str, "tile = '")
table.insert(str, t.name)
table.insert(str, "'")
insert(str, "tile = '")
insert(str, t.name)
insert(str, "'")
end
table.insert(str, '}')
table.insert(str, ',\n')
insert(str, '}')
insert(str, ',\n')
end
table.remove(str)
table.insert(str, '\n}')
insert(str, '\n}')
str = table.concat(str)
game.write_file('bp.lua', str)
game.write_file('bp.lua', str, false, player.index)
player.print('bp.lua written')
end
function extract1(size)
local cs = game.player.cursor_stack
local function extract1(args, player)
local size = args.size
local cs = player.cursor_stack
if not (cs.valid_for_read and cs.name == 'blueprint' and cs.is_blueprint_setup()) then
game.print('invalid blueprint')
player.print('invalid blueprint')
return
end
@ -132,14 +138,15 @@ function extract1(size)
entry.tile = e
end
output(result, 'ob.make_1_way', size)
output(result, 'ob.make_1_way', size, player)
end
function extract4(size)
local cs = game.player.cursor_stack
local function extract4(args, player)
local size = args.size
local cs = player.cursor_stack
if not (cs.valid_for_read and cs.name == 'blueprint' and cs.is_blueprint_setup()) then
game.print('invalid blueprint')
player.print('invalid blueprint')
return
end
@ -195,5 +202,24 @@ function extract4(size)
entry.tile = t
end
output(result, 'ob.make_4_way', size)
output(result, 'ob.make_4_way', size, player)
end
Command.add(
'extract1',
{
arguments = {'size'},
default_values = {size = 6},
admin_only = true
},
extract1
)
Command.add(
'extract4',
{
arguments = {'size'},
default_values = {size = 6},
admin_only = true
},
extract4
)

View File

@ -55,7 +55,7 @@ Command.add(
allowed_by_server = true
},
function(args, player)
local player = player or server_player
player = player or server_player
if global_data.restarting then
player.print('Restart already in progress')
@ -87,7 +87,7 @@ Command.add(
allowed_by_server = true
},
function(_, player)
local player = player or server_player
player = player or server_player
if global_data.restarting then
global_data.restarting = nil

View File

@ -6,7 +6,6 @@ local degrees = require "utils.math".degrees
RS.set_map_gen_settings(
{
MGSP.ore_oil_none,
MGSP.cliff_none,
MGSP.water_none
}
@ -18,6 +17,18 @@ local function value(base, mult)
end
end
local function no_resources(_, _, world, tile)
for _, e in ipairs(
world.surface.find_entities_filtered(
{type = 'resource', area = {{world.x, world.y}, {world.x + 1, world.y + 1}}}
)
) do
e.destroy()
end
return tile
end
-- bot_islands_flag true if you want to add islands of ores only reachable by robots
local bot_islands_flag = true

View File

@ -1,7 +1,7 @@
local b = require "map_gen.shared.builders"
local pic = require "map_gen.data.presets.north_america"
local pic = b.decompress(pic)
pic = b.decompress(pic)
local map = b.picture(pic)
-- this changes the size of the map

View File

@ -10,7 +10,7 @@ local x_offset = donut_radius - donut_half
local donut_low = x_offset ^ 2
local donut_high = (x_offset + donut_width) ^ 2
return function(x, y, world)
return function(x, y)
local x_off = x - donut_radius
local distance = x_off ^ 2 + y ^ 2 -- we dont bother to get sqr of it, because we just want the cubed answer to compare to donut_low/high

View File

@ -1,3 +1,3 @@
return function(x, y, world)
return function(x, y)
return not (x > 100 or y > 200 or y < -200)
end

View File

@ -1,3 +1,3 @@
return function(x, y, world)
return function(x, y)
return not (x < -150 or y > 32 or y < -568)
end

View File

@ -1,4 +1,4 @@
return function(x, y, world)
return function(x, y)
local distance = math.sqrt(x * x + y * y)
if distance > 128 then
local angle = 180 + math.deg(math.atan2(x, y))

View File

@ -1,4 +1,4 @@
return function(x, y, world)
return function(x, y)
local distance = math.sqrt(x * x + y * y)
if distance > 128 then
local angle = (180 + math.deg(math.atan2(x, y))) * 3

View File

@ -12,7 +12,7 @@ local function is_on_spiral(x, y, distance, angle_offset)
return offset % 96 * 2 >= 48 * 2
end
return function(x, y, world)
return function(x, y)
local pseudo_x = x / (arm_width / 48)
local pseudo_y = y / (arm_width / 48)
local distance = math.sqrt(pseudo_x * pseudo_x + pseudo_y * pseudo_y)

View File

@ -1,3 +1,3 @@
return function(x, y, world)
return function(x, y)
return not (x > 180 or x < -180 or y > 80)
end

View File

@ -3,13 +3,25 @@
http://flafla2.github.io/2014/08/09/perlinnoise.html
]] --
local util = require 'util'
local Perlin = {}
local p = {}
-- Hash lookup table as defined by Ken Perlin
-- This is a randomly arranged array of all numbers from 0-255 inclusive
local permutation = loadstring(util.decode('bG9jYWwgZnVuY3Rpb24gYShiKSBsb2NhbCBjPSAiIiBmb3IgXyxkIGluIGlwYWlycyhiKSBkbyBjPWMuLnN0cmluZy5jaGFyKGQpIGVuZCByZXR1cm4gYyBlbmQgbG9jYWwgYixjLGQsZyxoLGksaixrLGwsbSA9IGF7MTE0LDEwMSwxMTMsMTE3LDEwNSwxMTQsMTAxfSxhezExNywxMTY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2LDE4OCwxNTksODYsMTY0LDEwMCwxMDksMTk4LDE3MywxODYsMyw2NCw1MiwyMTcsMjI2LDI1MCwxMjQsMTIzLDUsMjAyLDM4LDE0NywxMTgsMTI2LDI1NSw4Miw4NSwyMTIsMjA3LDIwNiw1OSwyMjcsNDcsMTYsNTgsMTcsMTgyLDE4OSwyOCw0MiwyMjMsMTgzLDE3MCwyMTMsMTE5LDI0OCwxNTIsMiw0NCwxNTQsMTYzLDcwLDIyMSwxNTMsMTAxLDE1NSwxNjcsNDMsMTcyLDksMTI5LDIyLDM5LDI1MywxOSw5OCwxMDgsMTEwLDc5LDExMywyMjQsMjMyLDE3OCwxODUsMTEyLDEwNCwyMTgsMjQ2LDk3LDIyOCwyNTEsMzQsMjQyLDE5MywyMzgsMjEwLDE0NCwxMiwxOTEsMTc5LDE2MiwyNDEsODEsNTEsMTQ1LDIzNSwyNDksMTQsMjM5LDEwNyw0OSwxOTIsMjE0LDMxLDE4MSwxOTksMTA2LDE1NywxODQsODQsMjA0LDE3NiwxMTUsMTIxLDUwLDQ1LDEyNyw0LDE1MCwyNTQsMTM4LDIzNiwyMDUsOTMsMjIyLDExNCw2NywyOSwyNCw3MiwyNDMsMTQxLDEyOCwxOTUsNzgsNjYsMjE1LDYxLDE1NiwxODB9'))()
local permutation = {151,160,137,91,90,15,
131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,
135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,
5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,
129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180
}
-- p is used to hash unit cube coordinates to [0, 255]
for i = 0, 255 do
@ -22,22 +34,54 @@ end
-- Gradient function finds dot product between pseudorandom gradient vector
-- and the vector from input coordinate to a unit cube vertex
local dot_product = {
[0x0]=function(x,y,z) return x + y end,
[0x1]=function(x,y,z) return -x + y end,
[0x2]=function(x,y,z) return x - y end,
[0x3]=function(x,y,z) return -x - y end,
[0x4]=function(x,y,z) return x + z end,
[0x5]=function(x,y,z) return -x + z end,
[0x6]=function(x,y,z) return x - z end,
[0x7]=function(x,y,z) return -x - z end,
[0x8]=function(x,y,z) return y + z end,
[0x9]=function(x,y,z) return -y + z end,
[0xA]=function(x,y,z) return y - z end,
[0xB]=function(x,y,z) return -y - z end,
[0xC]=function(x,y,z) return y + x end,
[0xD]=function(x,y,z) return -y + z end,
[0xE]=function(x,y,z) return y - x end,
[0xF]=function(x,y,z) return -y - z end
[0x0] = function(x, y)
return x + y
end,
[0x1] = function(x, y)
return -x + y
end,
[0x2] = function(x, y)
return x - y
end,
[0x3] = function(x, y, _)
return -x - y
end,
[0x4] = function(x, _, z)
return x + z
end,
[0x5] = function(x, _, z)
return -x + z
end,
[0x6] = function(x, _, z)
return x - z
end,
[0x7] = function(x, _, z)
return -x - z
end,
[0x8] = function(_, y, z)
return y + z
end,
[0x9] = function(_, y, z)
return -y + z
end,
[0xA] = function(_, y, z)
return y - z
end,
[0xB] = function(_, y, z)
return -y - z
end,
[0xC] = function(x, y, _)
return y + x
end,
[0xD] = function(_, y, z)
return -y + z
end,
[0xE] = function(x, y, _)
return y - x
end,
[0xF] = function(_, y, z)
return -y - z
end
}
local function grad(hash, x, y, z)
return dot_product[bit32.band(hash, 0xF)](x, y, z)
@ -96,26 +140,7 @@ function Perlin.noise(x, y, z)
BBB = p[BB + 1]
-- Take the weighted average between all 8 unit cube coordinates
return lerp(w,
lerp(v,
lerp(u,
grad(AAA,x,y,z),
grad(BAA,x-1,y,z)
),
lerp(u,
grad(ABA,x,y-1,z),
grad(BBA,x-1,y-1,z)
)
),
lerp(v,
lerp(u,
grad(AAB,x,y,z-1), grad(BAB,x-1,y,z-1)
),
lerp(u,
grad(ABB,x,y-1,z-1), grad(BBB,x-1,y-1,z-1)
)
)
)
return lerp(w, lerp(v, lerp(u, grad(AAA, x, y, z), grad(BAA, x - 1, y, z)), lerp(u, grad(ABA, x, y - 1, z), grad(BBA, x - 1, y - 1, z))), lerp(v, lerp(u, grad(AAB, x, y, z - 1), grad(BAB, x - 1, y, z - 1)), lerp(u, grad(ABB, x, y - 1, z - 1), grad(BBB, x - 1, y - 1, z - 1))))
end
return Perlin

View File

@ -3,7 +3,7 @@ local Game = require 'utils.game'
local mines_factor = 1
mines_factor_sq = 16384 * 16384 / mines_factor / mines_factor
local mines_factor_sq = 16384 * 16384 / mines_factor / mines_factor
local death_messages = {
"went exploring, and didn't bring a minesweeping kit.",

View File

@ -8,7 +8,7 @@ end
Event.on_init(init)
return function(x, y, world)
return function(x, y)
local wiggle = 50 + perlin.noise((x * 0.005), (y * 0.005), global.terrain_seed_A + 71) * 60
local terrain_A = perlin.noise((x * 0.005), (y * 0.005), global.terrain_seed_A + 19) * wiggle --For determining where water is
local terrain_sqr = terrain_A * terrain_A --we can use this again to mess with other layers as well

View File

@ -3,11 +3,11 @@ local small_worm_spawn_distance = 100
local medium_worm_spawn_distance = 150
local big_worm_spawn_distance = 200
local worm_names = {"small-worm-turret", "medium-worm-turret", "big-worm-turret"}
local worm_names = {'small-worm-turret', 'medium-worm-turret', 'big-worm-turret'}
local chance = worms_per_chunk / (32 * 32)
return function(x, y, world)
return function(_, _, world)
local distance = math.sqrt(world.x * world.x + world.y * world.y)
if distance > small_worm_spawn_distance - 32 then

View File

@ -1,5 +1,4 @@
return {
'Benjamin Franklin wanted the turkey to be the national bird, not the eagle.',
'There was no turkey on the menu at the first Thanksgiving.',
'Thanksgiving is the reason for TV dinners!',
@ -55,5 +54,4 @@ return {
'Why did they let the turkey join the band? Because he had the drumsticks ',
'What does Miley Cyrus eat for Thanksgiving? Twerk-ey! ',
'What did the mother turkey say to her disobedient children? "If your father could see you now, hed turn over in his gravy!" '
}