1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-09-16 09:16:22 +02:00

bug fixes

This commit is contained in:
James Gillham
2017-08-12 02:12:10 +01:00
parent cc9e37cbc0
commit f0be94bdab
4 changed files with 31 additions and 42 deletions

View File

@@ -1,5 +1,6 @@
-- helpers
tau = 2 * math.pi
deg_to_rad = tau / 360
function degrees(angle)
@@ -7,6 +8,7 @@ function degrees(angle)
end
-- shape builders
function empty_builder(x, y)
return false
end
@@ -82,6 +84,7 @@ function picture_builder(data, width, height)
end
-- transforms and shape helpers
function translate(builder, x_offset, y_offset)
return function(x, y, world_x, world_y)
return builder(x - x_offset, y - y_offset, world_x, world_y)
@@ -202,52 +205,25 @@ end
-- pattern builders.
local function proccess_shape(shape, local_x, local_y, world_x, world_y, not_land)
local tile, entity = shape(local_x, local_y, world_x, world_y)
if not tile and not_land then
tile = not_land
end
return tile, entity
end
-- currently only useful for overriding not land tiles
function single_shape_builder(shape, options)
options = options or {}
local not_land = options.not_land
return function (local_x, local_y, world_x, world_y)
return proccess_shape(shape, local_x, local_y, world_x, world_y, not_land)
end
end
function single_pattern_builder(shape, width, height, options)
function single_pattern_builder(shape, width, height)
shape = shape or empty_builder
local half_width = width / 2
local half_height = height / 2
options = options or {}
local not_land = options.not_land
return function (local_x, local_y, world_x, world_y)
local_y = ((local_y + half_height) % height) - half_height + 0.5
local_x = ((local_x + half_width) % width) - half_width + 0.5
return proccess_shape(shape, local_x, local_y, world_x, world_y, not_land)
return shape(local_x, local_y, world_x, world_y)
end
end
function grid_pattern_builder(pattern, columns, rows, width, height, options)
function grid_pattern_builder(pattern, columns, rows, width, height)
local half_width = width / 2
local half_height = height / 2
options = options or {}
local not_land = options.not_land
return function (local_x, local_y, world_x, world_y)
local local_y2 = ((local_y + half_height) % height) - half_height + 0.5
local row_pos = math.floor(local_y / height + 0.5)
@@ -259,7 +235,7 @@ function grid_pattern_builder(pattern, columns, rows, width, height, options)
local col_i = col_pos % columns + 1
local shape = row[col_i] or empty_builder
return proccess_shape(shape, local_x2, local_y2, world_x, world_y, not_land)
return shape(local_x2, local_y2, world_x, world_y)
end
end
@@ -275,7 +251,7 @@ function change_tile(builder, old_tile, new_tile)
end
end
function change_collision_tile(builder, collides, new_tile, )
function change_collision_tile(builder, collides, new_tile)
return function (local_x, local_y, world_x, world_y )
local tile, entity = builder(local_x, local_y, world_x, world_y)
if tile.collides_with(collides) then
@@ -285,10 +261,11 @@ function change_collision_tile(builder, collides, new_tile, )
end
end
-- only changes tiles made by the factorio map generator.
function change_map_gen_tile(builder, old_tile, new_tile)
return function (local_x, local_y, world_x, world_y )
local tile, entity = builder(local_x, local_y, world_x, world_y)
if not tile then
if type(tile) == "boolean" and tile then
local gen_tile = MAP_GEN_SURFACE.get_tile(world_x, world_y)
if old_tile == gen_tile then
tile = new_tile
@@ -298,10 +275,11 @@ function change_map_gen_tile(builder, old_tile, new_tile)
end
end
-- only changes tiles made by the factorio map generator.
function change_map_gen_collision_tile(builder, collides, new_tile)
return function (local_x, local_y, world_x, world_y )
local tile, entity = builder(local_x, local_y, world_x, world_y)
if not tile then
if type(tile) == "boolean" and tile then
local gen_tile = MAP_GEN_SURFACE.get_tile(world_x, world_y)
if gen_tile.collides_with(collides) then
tile = new_tile

View File

@@ -0,0 +1,15 @@
require "locale.gen_combined.grilledham_map_gen.map_gen"
require "locale.gen_combined.grilledham_map_gen.builders"
local pic = require "locale.gen_combined.grilledham_map_gen.data.crosses3"
local scale_factor = 4
local shape = picture_builder(pic.data, pic.width, pic.height)
shape = scale(shape, scale_factor, scale_factor)
--shape = rotate(shape, degrees(45))
shape = invert(shape)
local map = single_pattern_builder(shape, pic.width * scale_factor, pic.height * scale_factor)
map = rotate(map, degrees(45))
return map

View File

@@ -4,6 +4,7 @@ require "locale.gen_combined.grilledham_map_gen.builders"
local square = rectangle_builder(32,32)
local circle = circle_builder(16)
local path = path_builder(8)
path = change_tile(path, true, "water")
square = compound_or({square, path})
circle = compound_or({circle, path})
@@ -15,14 +16,8 @@ local pattern =
}
local map = grid_pattern_builder(pattern, 2, 2, 64, 64)
--map = scale(map, 1, 1)
map = rotate(map, degrees(45))
map = single_pattern_builder(map, 128,128)
map = rotate(map, degrees(-45))
map = single_pattern_builder(map, 256, 256)
map = rotate(map, degrees(45))
map = change_map_gen_collision_tile(map, "water-tile", "grass")
return map

View File

@@ -10,7 +10,8 @@ in this file and your run_*type*_module(event) function will be called.
--require "locale.gen_combined.island_resort"
--grilledham's maps
MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.test"
--MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.test"
MAP_GEN = require "locale.gen_combined.grilledham_map_gen.presets.picture_test"
--shapes--
--require "locale.gen_shape.right"