From a8b60a474aa86bd58295564491127ff23b993225 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Sat, 21 Sep 2024 07:09:32 +0900 Subject: [PATCH] Add Blueprint Landfill (#308) * Update gui.cfg * Update gui.cfg * Update gui.cfg * Update _file_loader.lua * Update roles.lua * Create landfill.lua * Create landfill.lua * Update landfill.lua * Update landfill.lua * Update landfill.lua * Update landfill.lua * Update landfill.lua * Update gui.cfg * Update gui.cfg * Update gui.cfg * Update landfill.lua * Update landfill.lua * Update landfill.lua * Update landfill.lua * Update gui.cfg * Update gui.cfg * Update gui.cfg * Update landfill.lua * Update landfill.lua * Update gui.cfg * Update gui.cfg * Update gui.cfg * Delete config/landfill.lua * Update landfill.lua * Update landfill.lua --- config/_file_loader.lua | 1 + config/expcore/roles.lua | 1 + locale/en/gui.cfg | 4 + locale/zh-CN/gui.cfg | 4 + locale/zh-TW/gui.cfg | 4 + modules/gui/landfill.lua | 185 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 199 insertions(+) create mode 100644 modules/gui/landfill.lua diff --git a/config/_file_loader.lua b/config/_file_loader.lua index 0e30f6a2..fab383e8 100644 --- a/config/_file_loader.lua +++ b/config/_file_loader.lua @@ -96,6 +96,7 @@ return { 'modules.gui.vlayer', 'modules.gui.research', 'modules.gui.module', + 'modules.gui.landfill', 'modules.gui.production', 'modules.gui.playerdata', 'modules.gui.surveillance', diff --git a/config/expcore/roles.lua b/config/expcore/roles.lua index 0befe067..61960187 100644 --- a/config/expcore/roles.lua +++ b/config/expcore/roles.lua @@ -291,6 +291,7 @@ local default = Roles.new_role('Guest','') 'gui/research', 'gui/autofill', 'gui/module', + 'gui/landfill', 'gui/production' } diff --git a/locale/en/gui.cfg b/locale/en/gui.cfg index cd5a0dbd..4a32da2a 100644 --- a/locale/en/gui.cfg +++ b/locale/en/gui.cfg @@ -293,6 +293,10 @@ control-type-storage-output=Storage Output [module] main-tooltip=Module GUI +[landfill] +main-tooltip=Blueprint Landfill GUI +cursor-none=You need to hold the blueprint in cursor + [production] main-tooltip=Production GUI label-prod=Production diff --git a/locale/zh-CN/gui.cfg b/locale/zh-CN/gui.cfg index 1358ebfe..67ddc215 100644 --- a/locale/zh-CN/gui.cfg +++ b/locale/zh-CN/gui.cfg @@ -297,6 +297,10 @@ control-type-storage-output=提取箱 [module] main-tooltip=模組介面 +[landfill] +main-tooltip=藍圖填海介面 +cursor-none=您需要將藍圖保持在遊標處 + [production] main-tooltip=製造介面 label-prod=製造 diff --git a/locale/zh-TW/gui.cfg b/locale/zh-TW/gui.cfg index 1358ebfe..67ddc215 100644 --- a/locale/zh-TW/gui.cfg +++ b/locale/zh-TW/gui.cfg @@ -297,6 +297,10 @@ control-type-storage-output=提取箱 [module] main-tooltip=模組介面 +[landfill] +main-tooltip=藍圖填海介面 +cursor-none=您需要將藍圖保持在遊標處 + [production] main-tooltip=製造介面 label-prod=製造 diff --git a/modules/gui/landfill.lua b/modules/gui/landfill.lua new file mode 100644 index 00000000..326c90c9 --- /dev/null +++ b/modules/gui/landfill.lua @@ -0,0 +1,185 @@ +--[[-- Gui Module - Landfill + - Landfill blueprint + @gui Landfill + @alias landfill_container +]] + +local Gui = require 'expcore.gui' --- @dep expcore.gui +local Event = require 'utils.event' --- @dep utils.event +local Roles = require 'expcore.roles' --- @dep expcore.roles + +local rolling_stocks = {} + +local function landfill_init() + for name, _ in pairs(game.get_filtered_entity_prototypes({{filter = 'rolling-stock'}})) do + rolling_stocks[name] = true + end +end + +local function rotate_bounding_box(box) + return { + left_top = { + x = -box.right_bottom.y, + y = box.left_top.x + }, + right_bottom = { + x = -box.left_top.y, + y = box.right_bottom.x + } + } +end + +local function curve_flip_lr(oc) + local nc = table.deepcopy(oc) + + for r=1, 8 do + for c=1, 8 do + nc[r][c] = oc[r][9 - c] + end + end + + return nc +end + +local function curve_flip_d(oc) + local nc = table.deepcopy(oc) + + for r=1, 8 do + for c=1, 8 do + nc[r][c] = oc[c][r] + end + end + + return nc +end + +local curves = {} + +curves[1] = { + {0, 0, 0, 0, 0, 1, 0, 0}, + {0, 0, 0, 0, 1, 1, 1, 0}, + {0, 0, 0, 1, 1, 1, 1, 0}, + {0, 0, 0, 1, 1, 1, 0, 0}, + {0, 0, 1, 1, 1, 0, 0, 0}, + {0, 0, 1, 1, 1, 0, 0, 0}, + {0, 0, 1, 1, 0, 0, 0, 0}, + {0, 0, 1, 1, 0, 0, 0, 0} +} +curves[6] = curve_flip_d(curves[1]) +curves[3] = curve_flip_lr(curves[6]) +curves[4] = curve_flip_d(curves[3]) +curves[5] = curve_flip_lr(curves[4]) +curves[2] = curve_flip_d(curves[5]) +curves[7] = curve_flip_lr(curves[2]) +curves[8] = curve_flip_d(curves[7]) + +local curve_n = {} + +for i, map in ipairs(curves) do + curve_n[i] = {} + local index = 1 + + for r=1, 8 do + for c=1, 8 do + if map[r][c] == 1 then + curve_n[i][index] = { + ['x'] = c - 5, + ['y'] = r - 5 + } + + index = index + 1 + end + end + end +end + +local function landfill_gui_add_landfill(blueprint) + local entities = blueprint.get_blueprint_entities() + local tile_index = 0 + local new_tiles = {} + + for _, ent in pairs(entities) do + -- vehicle + if not (rolling_stocks[ent.name] or ent.name == 'offshore-pump') then + -- curved rail, special + if ent.name ~= 'curved-rail' then + local box = game.entity_prototypes[ent.name].collision_box or game.entity_prototypes[ent.name].selection_box + + if game.entity_prototypes[ent.name].collision_mask['ground-tile'] == nil then + if ent.direction then + if ent.direction ~= defines.direction.north then + box = rotate_bounding_box(box) + + if ent.direction ~= defines.direction.east then + box = rotate_bounding_box(box) + + if ent.direction ~= defines.direction.south then + box = rotate_bounding_box(box) + end + end + end + end + + for y = math.floor(ent.position.y + box.left_top.y), math.floor(ent.position.y + box.right_bottom.y), 1 do + for x = math.floor(ent.position.x + box.left_top.x), math.floor(ent.position.x + box.right_bottom.x), 1 do + tile_index = tile_index + 1 + new_tiles[tile_index] = { + name = 'landfill', + position = {x, y} + } + end + end + end + + -- curved rail + else + local curve_mask = curve_n[ent.direction or 8] + + for m=1, #curve_mask do + new_tiles[tile_index + 1] = { + name = 'landfill', + position = {curve_mask[m].x + ent.position.x, curve_mask[m].y + ent.position.y} + } + + tile_index = tile_index + 1 + end + end + end + end + + local old_tiles = blueprint.get_blueprint_tiles() + + if old_tiles then + for _, old_tile in pairs(old_tiles) do + new_tiles[tile_index + 1] = { + name = 'landfill', + position = {old_tile.position.x, old_tile.position.y} + } + + tile_index = tile_index + 1 + end + end + + return {tiles = new_tiles} +end + +-- @element toolbar_button +Gui.toolbar_button('item/landfill', {'landfill.main-tooltip'}, function(player) + return Roles.player_allowed(player, 'gui/landfill') +end) +:on_click(function(player, _, _) + if player.cursor_stack and player.cursor_stack.valid_for_read then + if player.cursor_stack.type == 'blueprint' and player.cursor_stack.is_blueprint_setup() then + local modified = landfill_gui_add_landfill(player.cursor_stack) + + if modified and next(modified.tiles) then + player.cursor_stack.set_blueprint_tiles(modified.tiles) + end + end + + else + player.print{'landfill.cursor-none'} + end +end) + +Event.add(defines.events.on_player_joined_game, landfill_init)