1
0
mirror of https://github.com/teoxoy/factorio-blueprint-editor.git synced 2025-01-18 02:58:31 +02:00

made the parser a separate project

This commit is contained in:
Teoxoy 2018-09-15 20:40:48 +02:00
parent b1a599789a
commit bef015ebed
34 changed files with 2630 additions and 84395 deletions

4501
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"start": "parcel src/index.html",
"prebuild": "rimraf dist && cpx src/spritesheets/* dist/spritesheets",
"prebuild": "rimraf dist",
"build": "parcel build src/index.html",
"setupDist": "git worktree add dist gh-pages",
"deploy": "cd dist && git add --all && git reset -- stats && git commit -m \"new version\" && git push origin gh-pages"
@ -25,7 +25,8 @@
"immutable": "^3.8.2",
"keyboardjs": "^2.4.1",
"normalize.css": "^8.0.0",
"pixi.js": "^4.8.1"
"pixi.js": "^4.8.1",
"factorio-data": "git+https://github.com/Teoxoy/factorio-data.git"
},
"devDependencies": {
"@types/keyboardjs": "^2.2.31",

View File

@ -1,598 +0,0 @@
defines = {
alert_type = {
custom = 6,
entity_destroyed = 0,
entity_under_attack = 1,
no_material_for_construction = 3,
no_storage = 7,
not_enough_construction_robots = 2,
not_enough_repair_packs = 4,
turret_fire = 5
},
chain_signal_state = {
all_open = 1,
none = 0,
none_open = 3,
partially_open = 2
},
chunk_generated_status = {
basic_tiles = 20,
corrected_tiles = 30,
custom_tiles = 10,
entities = 50,
nothing = 0,
tiles = 40
},
circuit_condition_index = {
arithmetic_combinator = 1,
constant_combinator = 1,
decider_combinator = 1,
inserter_circuit = 1,
inserter_logistic = 2,
lamp = 1,
offshore_pump = 1,
pump = 1
},
circuit_connector_id = {
accumulator = 1,
combinator_input = 1,
combinator_output = 2,
constant_combinator = 1,
container = 1,
electric_pole = 1,
inserter = 1,
lamp = 1,
offshore_pump = 1,
programmable_speaker = 1,
pump = 1,
rail_chain_signal = 1,
rail_signal = 1,
roboport = 1,
storage_tank = 1,
wall = 1
},
command = {
attack = 1,
attack_area = 5,
build_base = 7,
compound = 3,
flee = 8,
go_to_location = 2,
group = 4,
wander = 6
},
compound_command = {
logical_and = 0,
logical_or = 1,
return_last = 2
},
control_behavior = {
inserter = {
circuit_mode_of_operation = {
enable_disable = 0,
none = 3,
read_hand_contents = 2,
set_filters = 1,
set_stack_size = 4
},
hand_read_mode = {
hold = 1,
pulse = 0
}
},
lamp = {
circuit_mode_of_operation = {
use_colors = 0
}
},
logistic_container = {
circuit_mode_of_operation = {
send_contents = 0,
set_requests = 1
}
},
mining_drill = {
resource_read_mode = {
entire_patch = 1,
this_miner = 0
}
},
roboport = {
circuit_mode_of_operation = {
read_logistics = 0,
read_robot_stats = 1
}
},
train_stop = {
circuit_mode_of_operation = {
enable_disable = 0,
read_from_train = 2,
read_stopped_train = 3,
send_to_train = 1
}
},
transport_belt = {
content_read_mode = {
hold = 1,
pulse = 0
}
},
type = {
accumulator = 13,
arithmetic_combinator = 10,
constant_combinator = 11,
container = 1,
decider_combinator = 9,
generic_on_off = 2,
inserter = 3,
lamp = 4,
logistic_container = 5,
mining_drill = 16,
programmable_speaker = 17,
rail_chain_signal = 18,
rail_signal = 14,
roboport = 6,
storage_tank = 7,
train_stop = 8,
transport_belt = 12,
wall = 15
}
},
controllers = {
character = 1,
ghost = 0,
god = 2
},
deconstruction_item = {
entity_filter_mode = {
blacklist = 1,
whitelist = 0
},
tile_filter_mode = {
blacklist = 1,
whitelist = 0
},
tile_selection_mode = {
always = 1,
never = 2,
normal = 0,
only = 3
}
},
difficulty = {
easy = 0,
hard = 2,
normal = 1
},
difficulty_settings = {
recipe_difficulty = {
expensive = 1,
normal = 0
},
technology_difficulty = {
expensive = 1,
normal = 0
}
},
direction = {
east = 2,
north = 0,
northeast = 1,
northwest = 7,
south = 4,
southeast = 3,
southwest = 5,
west = 6
},
distraction = {
by_anything = 3,
by_damage = 4,
by_enemy = 1,
none = 0
},
events = {
on_biter_base_built = 55,
on_built_entity = 6,
on_canceled_deconstruction = 21,
on_character_corpse_expired = 90,
on_chunk_charted = 98,
on_chunk_generated = 12,
on_combat_robot_expired = 80,
on_console_chat = 71,
on_console_command = 72,
on_difficulty_settings_changed = 60,
on_entity_damaged = 97,
on_entity_died = 4,
on_entity_renamed = 57,
on_entity_settings_pasted = 31,
on_force_created = 27,
on_forces_merging = 28,
on_gui_checked_state_changed = 3,
on_gui_click = 1,
on_gui_closed = 84,
on_gui_elem_changed = 67,
on_gui_opened = 83,
on_gui_selection_state_changed = 58,
on_gui_text_changed = 2,
on_gui_value_changed = 85,
on_marked_for_deconstruction = 20,
on_market_item_purchased = 53,
on_mod_item_opened = 82,
on_picked_up_item = 5,
on_player_alt_selected_area = 50,
on_player_ammo_inventory_changed = 36,
on_player_armor_inventory_changed = 35,
on_player_built_tile = 45,
on_player_cancelled_crafting = 96,
on_player_changed_force = 56,
on_player_changed_position = 81,
on_player_changed_surface = 51,
on_player_cheat_mode_disabled = 89,
on_player_cheat_mode_enabled = 88,
on_player_configured_blueprint = 70,
on_player_crafted_item = 13,
on_player_created = 24,
on_player_cursor_stack_changed = 29,
on_player_deconstructed_area = 69,
on_player_demoted = 76,
on_player_died = 41,
on_player_display_resolution_changed = 93,
on_player_display_scale_changed = 94,
on_player_driving_changed_state = 26,
on_player_dropped_item = 54,
on_player_gun_inventory_changed = 37,
on_player_joined_game = 43,
on_player_left_game = 44,
on_player_main_inventory_changed = 32,
on_player_mined_entity = 65,
on_player_mined_item = 8,
on_player_mined_tile = 46,
on_player_muted = 86,
on_player_pipette = 92,
on_player_placed_equipment = 38,
on_player_promoted = 75,
on_player_quickbar_inventory_changed = 33,
on_player_removed = 73,
on_player_removed_equipment = 39,
on_player_respawned = 42,
on_player_rotated_entity = 19,
on_player_selected_area = 49,
on_player_setup_blueprint = 68,
on_player_tool_inventory_changed = 34,
on_player_unmuted = 87,
on_player_used_capsule = 74,
on_pre_entity_settings_pasted = 30,
on_pre_ghost_deconstructed = 91,
on_pre_player_crafted_item = 95,
on_pre_player_died = 40,
on_pre_player_mined_item = 11,
on_pre_surface_deleted = 63,
on_put_item = 9,
on_research_finished = 18,
on_research_started = 17,
on_resource_depleted = 25,
on_robot_built_entity = 14,
on_robot_built_tile = 47,
on_robot_mined = 16,
on_robot_mined_entity = 64,
on_robot_mined_tile = 48,
on_robot_pre_mined = 15,
on_rocket_launched = 10,
on_runtime_mod_setting_changed = 59,
on_sector_scanned = 7,
on_selected_entity_changed = 52,
on_surface_created = 61,
on_surface_deleted = 62,
on_tick = 0,
on_train_changed_state = 23,
on_train_created = 66,
on_trigger_created_entity = 22,
script_raised_built = 77,
script_raised_destroy = 78,
script_raised_revive = 79
},
group_state = {
attacking_distraction = 2,
attacking_target = 3,
finished = 4,
gathering = 0,
moving = 1
},
gui_type = {
achievement = 8,
blueprint_library = 9,
bonus = 6,
controller = 3,
custom = 16,
entity = 1,
equipment = 10,
item = 5,
kills = 13,
logistic = 11,
none = 0,
other_player = 12,
permissions = 14,
production = 4,
research = 2,
trains = 7,
tutorials = 15
},
input_action = {
add_permission_group = 177,
alt_select_area = 129,
alt_select_blueprint_entities = 94,
begin_mining = 2,
begin_mining_terrain = 46,
build_item = 44,
build_rail = 125,
build_terrain = 120,
cancel_craft = 64,
cancel_deconstruct = 114,
cancel_new_blueprint = 22,
cancel_research = 126,
change_active_item_group_for_crafting = 78,
change_active_item_group_for_filters = 89,
change_active_quick_bar = 17,
change_arithmetic_combinator_parameters = 115,
change_blueprint_book_record_label = 109,
change_decider_combinator_parameters = 116,
change_item_label = 124,
change_picking_state = 150,
change_programmable_speaker_alert_parameters = 118,
change_programmable_speaker_circuit_parameters = 119,
change_programmable_speaker_parameters = 117,
change_riding_state = 47,
change_shooting_state = 58,
change_single_blueprint_record_label = 100,
change_train_stop_station = 77,
change_train_wait_condition = 121,
change_train_wait_condition_data = 122,
clean_cursor_stack = 13,
clear_selected_blueprint = 131,
clear_selected_deconstruction_item = 132,
connect_rolling_stock = 10,
copy_entity_settings = 24,
craft = 56,
create_blueprint_like = 104,
cursor_split = 52,
cursor_transfer = 51,
custom_input = 123,
cycle_blueprint_book_backwards = 36,
cycle_blueprint_book_forwards = 35,
deconstruct = 92,
delete_blueprint_record = 103,
delete_custom_tag = 175,
delete_permission_group = 176,
destroy_opened_item = 26,
disconnect_rolling_stock = 11,
drag_train_schedule = 142,
drag_train_wait_condition = 143,
drop_blueprint_record = 102,
drop_item = 43,
drop_to_blueprint_book = 174,
edit_custom_tag = 137,
edit_permission_group = 138,
edit_train_schedule = 76,
export_blueprint = 111,
fast_entity_split = 164,
fast_entity_transfer = 163,
grab_blueprint_record = 101,
gui_checked_state_changed = 80,
gui_click = 73,
gui_elem_changed = 140,
gui_selection_state_changed = 81,
gui_text_changed = 79,
gui_value_changed = 82,
import_blueprint = 112,
import_blueprint_string = 139,
inventory_split = 63,
inventory_transfer = 54,
launch_rocket = 16,
market_offer = 75,
mod_settings_changed = 135,
open_achievements_gui = 33,
open_blueprint_library_gui = 18,
open_blueprint_record = 98,
open_bonus_gui = 31,
open_character_gui = 9,
open_equipment = 50,
open_gui = 7,
open_item = 48,
open_kills_gui = 20,
open_logistic_gui = 41,
open_mod_item = 49,
open_production_gui = 19,
open_technology_gui = 15,
open_train_gui = 170,
open_train_station_gui = 127,
open_trains_gui = 32,
open_tutorials_gui = 34,
paste_entity_settings = 25,
place_equipment = 83,
remove_cables = 110,
reset_assembling_machine = 14,
reverse_rotate_entity = 5,
rotate_entity = 4,
select_area = 128,
select_blueprint_entities = 93,
select_entity_slot = 145,
select_gun = 156,
select_item = 144,
select_tile_slot = 146,
set_auto_launch_rocket = 158,
set_autosort_inventory = 157,
set_behavior_mode = 162,
set_car_weapons_control = 179,
set_circuit_condition = 67,
set_circuit_mode_of_operation = 72,
set_deconstruction_item_tile_selection_mode = 173,
set_deconstruction_item_trees_and_rocks_only = 172,
set_entity_color = 171,
set_entity_energy_property = 136,
set_filter = 65,
set_infinity_container_filter_item = 134,
set_infinity_container_remove_unfiltered_items = 178,
set_inserter_max_stack_size = 169,
set_inventory_bar = 88,
set_logistic_filter_item = 70,
set_logistic_filter_signal = 71,
set_logistic_trash_filter_item = 133,
set_request_from_buffers = 180,
set_research_finished_stops_game = 168,
set_signal = 68,
set_single_blueprint_record_icon = 97,
set_splitter_priority = 149,
set_train_stopped = 165,
setup_assembling_machine = 59,
setup_blueprint = 95,
setup_single_blueprint_record = 96,
shortcut_quick_bar_transfer = 155,
smart_pipette = 61,
stack_split = 62,
stack_transfer = 53,
start_repair = 91,
start_research = 69,
start_walking = 45,
switch_connect_to_logistic_network = 161,
switch_constant_combinator_state = 159,
switch_power_switch_state = 160,
switch_to_rename_stop_gui = 30,
take_equipment = 84,
toggle_deconstruction_item_entity_filter_mode = 39,
toggle_deconstruction_item_tile_filter_mode = 40,
toggle_driving = 6,
toggle_enable_vehicle_logistics_while_moving = 38,
toggle_show_entity_info = 27,
use_ability = 85,
use_artillery_remote = 87,
use_item = 86,
wire_dragging = 57,
write_to_console = 74
},
inventory = {
assembling_machine_input = 2,
assembling_machine_modules = 4,
assembling_machine_output = 3,
beacon_modules = 1,
burnt_result = 6,
car_ammo = 3,
car_trunk = 2,
cargo_wagon = 1,
chest = 1,
fuel = 1,
furnace_modules = 4,
furnace_result = 3,
furnace_source = 2,
god_main = 2,
god_quickbar = 1,
item_main = 1,
lab_input = 2,
lab_modules = 3,
mining_drill_modules = 2,
player_ammo = 4,
player_armor = 5,
player_guns = 3,
player_main = 1,
player_quickbar = 2,
player_tools = 6,
player_trash = 8,
player_vehicle = 7,
roboport_material = 2,
roboport_robot = 1,
robot_cargo = 1,
robot_repair = 2,
rocket_silo_result = 6,
rocket_silo_rocket = 5,
turret_ammo = 1
},
logistic_member_index = {
character_provider = 2,
character_requester = 0,
character_storage = 1,
generic_on_off_behavior = 0,
logistic_container = 0,
vehicle_storage = 1
},
logistic_mode = {
active_provider = 1,
buffer = 5,
none = 0,
passive_provider = 4,
requester = 3,
storage = 2
},
mouse_button_type = {
left = 2,
middle = 8,
none = 1,
right = 4
},
rail_connection_direction = {
left = 0,
none = 3,
right = 2,
straight = 1
},
rail_direction = {
back = 1,
front = 0
},
riding = {
acceleration = {
accelerating = 1,
braking = 2,
nothing = 0,
reversing = 3
},
direction = {
left = 0,
right = 2,
straight = 1
}
},
shooting = {
not_shooting = 0,
shooting_enemies = 1,
shooting_selected = 2
},
signal_state = {
closed = 1,
open = 0,
reserved = 2,
reserved_by_circuit_network = 3
},
train_state = {
arrive_signal = 4,
arrive_station = 6,
manual_control = 9,
manual_control_stop = 8,
no_path = 3,
no_schedule = 2,
on_the_path = 0,
path_lost = 1,
wait_signal = 5,
wait_station = 7
},
transport_line = {
left_line = 1,
left_split_line = 5,
left_underground_line = 3,
right_line = 2,
right_split_line = 6,
right_underground_line = 4,
secondary_left_line = 3,
secondary_left_split_line = 7,
secondary_right_line = 4,
secondary_right_split_line = 8
},
wire_connection_id = {
electric_pole = 0,
power_switch_left = 0,
power_switch_right = 1
},
wire_type = {
copper = 1,
green = 3,
red = 2
}
}

View File

@ -1,103 +0,0 @@
const fse = require('fs-extra')
const lua2js = require('lua2js')
const execSync = require('child_process').execSync
const factorioDirectory = process.argv[2]
//run /c game.write_file("defines.lua", serpent.block(_G.defines, {comments=false}))
// Load Order:
// data.lua
// data-updates.lua
// data-final-fixes.lua
const reqLualibRegex = /.*?require\s*\(*['"]([^.]+?)['"]\)*/g
const reqRegex = /require\s*\(*['"](.+?)['"]\)*/g
let loadedModules = []
function searchLoadRemoveDependencies(contents, regex, baseFolder) {
let newModules = []
let match = regex.exec(contents)
while (match !== null) {
let dep = match[1]
if (!loadedModules.includes(dep)) {
//load module
loadedModules.push(dep)
newModules.push({
index: match.index,
name: dep
})
}
match = regex.exec(contents)
}
let offset = 0
for (let i = 0; i < newModules.length; i++) {
let startPart = contents.slice(0, newModules[i].index + offset)
let endPart = contents.slice(newModules[i].index + offset)
let depData = readRequireOfFile(baseFolder, newModules[i].name.replace(/\./g, '/') + '.lua') + '\n'
contents = startPart + depData + endPart
offset += depData.length
}
// remove all requires
contents = contents.replace(regex, '')
return contents
}
function readRequireOfFile(baseFolder, pathCon) {
let contents = fse.readFileSync(factorioDirectory + baseFolder + pathCon).toString()
contents = searchLoadRemoveDependencies(contents, reqLualibRegex, 'core/lualib/')
contents = searchLoadRemoveDependencies(contents, reqRegex, baseFolder)
// remove last return
contents = contents.replace(/return\s*\b.+?\b\s*$/g, '')
// if a return is an obj, convert the return with the filename
contents = contents.replace(/return\s(\{(.|\n)+?\})\s*$/g, function(match, capture){
let split = pathCon.split('/')
return split[split.length - 1].replace('.lua', '') + ' = ' + capture
})
if (pathCon.includes('autoplace_utils')) {
contents = contents.replace(/M/g, 'autoplace_utils')
}
return contents
}
const fileOrder = [
'core/lualib/dataloader.lua',
'core/data.lua',
'base/data.lua',
'base/data-updates.lua'
]
let mainFileData = ''
for (let i = 0; i < fileOrder.length; i++) {
let splitPath = fileOrder[i].split('/')
let data = readRequireOfFile(splitPath[0] + '/', splitPath.slice(1).join('/'))
mainFileData += data + '\n'
}
mainFileData = mainFileData
// var = require(...) results in var = var = {}
.replace(/\b[a-zA-Z_-]+?\b\s*(=\s*\b[a-zA-Z_-]+?\b\s*)=\s*\{/g, function(match, capture){
return match.replace(capture, '')
})
mainFileData = fse.readFileSync('./defines.lua').toString() + mainFileData
fse.writeFileSync('./temp.lua', mainFileData)
const data = lua2js.parser.parse(mainFileData)
fse.writeFileSync('./temp.js', `
require("lua2js").runtime;
${data}
require("fs").writeFileSync('./temp.json', JSON.stringify(Tget($get($, 'data'), 'raw').toObject(), null, 2));
`)
execSync('node temp.js')

View File

@ -1,9 +0,0 @@
const execSync = require('child_process').execSync
const factorioDataDirectory = 'B:/SteamLibrary/steamapps/common/Factorio/data/'
const outputDirectory = '../src/'
process.chdir('./parser')
execSync(`node exportRawData.js ${factorioDataDirectory}`)
execSync(`node processRawData.js ${factorioDataDirectory} ${outputDirectory}`)

View File

@ -1,11 +0,0 @@
{
"frames": {
<% layout.images.forEach(function (image, idx)
{ %>"<%= image.className %>": {
"frame": { "x": <%= image.x %>, "y": <%= image.y %>, "w": <%= image.width %>, "h": <%= image.height %> },
"sourceSize": { "w": <%= image.width %>, "h": <%= image.height %> }
}<% if (idx !== layout.images.length - 1) { %>,
<% } %><% }); %>
},
"meta": { "image": "entitySpritesheet.png" }
}

View File

@ -1,11 +0,0 @@
{
"frames": {
<% layout.images.forEach(function (image, idx)
{ %>"<%= image.className %>": {
"frame": { "x": <%= image.x %>, "y": <%= image.y %>, "w": <%= image.width %>, "h": <%= image.height %> },
"sourceSize": { "w": <%= image.width %>, "h": <%= image.height %> }
}<% if (idx !== layout.images.length - 1) { %>,
<% } %><% }); %>
},
"meta": { "image": "iconSpritesheet.png" }
}

View File

@ -1,467 +0,0 @@
const fse = require('fs-extra')
const nsg = require('node-sprite-generator')
const Jimp = require('jimp')
const util = require('util')
const factorioDirectory = process.argv[2]
const bundlesOutDir = process.argv[3] + 'bundles/'
const spritesheetsOutDir = process.argv[3] + 'spritesheets/'
function nameMapping(imagePath) {
const sP = imagePath.split('/')
return sP.splice(sP.length - 2).join('/').split('.')[0]
}
let rawData = JSON.parse(fse.readFileSync('./temp.json').toString()
.replace(/"(up|down|left|right|north|south|west|east)"/g, function(match, capture) {
if (capture === 'north' || capture === 'up') return '"0"'
if (capture === 'east' || capture === 'left') return '"2"'
if (capture === 'south' || capture === 'down') return '"4"'
if (capture === 'west' || capture === 'right') return '"6"'
}))
let tiles = {}
for (const k in rawData.tile) {
if (rawData.tile[k].minable) tiles[k] = rawData.tile[k]
}
console.log('Tiles: ' + Object.keys(tiles).length)
fse.writeFileSync(bundlesOutDir + 'tileBundle.json', JSON.stringify(tiles, null, 2).replace(/__base__|__core__/g, 'factorio-data'))
console.log('Recipes: ' + Object.keys(rawData.recipe).length)
fse.writeFileSync(bundlesOutDir + 'recipeBundle.json', JSON.stringify(rawData.recipe, null, 2).replace(/__base__|__core__/g, 'factorio-data'))
let inventory = []
let items = {}
let placeableEntities = ['curved-rail']
const blacklistedGroups = [
'environment',
'enemies',
'other'
]
for (const k in rawData['item-group']) {
const group = rawData['item-group'][k]
if (!blacklistedGroups.includes(group.name)) {
group.subgroups = []
inventory.push(group)
}
}
for (const k in rawData['item-subgroup']) {
const subgroup = rawData['item-subgroup'][k]
subgroup.items = []
for (const group of inventory) {
if (group.name === subgroup.group) {
group.subgroups.push(subgroup)
break
}
}
}
function findAllItems(data) {
if (data.constructor === Object) {
if (data.hasOwnProperty('subgroup')) {
addItem(data)
} else {
for (const k in data) {
if (data.hasOwnProperty(k)) {
findAllItems(data[k])
}
}
}
}
}
findAllItems(rawData)
for (const k in rawData['fluid']) {
const fluid = rawData['fluid'][k]
fluid.subgroup = 'fluid'
addItem(fluid)
}
function addItem(item) {
if ((item.flags && item.flags.includes('hidden')) || !(item.icon || item.icons) || !item.order || item.collision_box) return
for (let j = 0; j < inventory.length; j++) {
for (let k = 0; k < inventory[j].subgroups.length; k++) {
if (inventory[j].subgroups[k].name === item.subgroup) {
inventory[j].subgroups[k].items.push(item)
if (item.place_result) placeableEntities.push(item.place_result)
items[item.name] = item
return
}
}
}
}
console.log('Items: ' + Object.keys(items).length)
fse.writeFileSync(bundlesOutDir + 'itemBundle.json', JSON.stringify(items, null, 2).replace(/"((__base__|__core__)\/.+?)"/g, function(match, capture) {
return '"icon:' + nameMapping(capture) + '"'
}))
// sort and remove extra info from inventoryBundle
inventory.sort(sortByOrder)
for (let i = 0; i < inventory.length; i++) {
inventory[i].subgroups.sort(sortByOrder)
for (let j = 0; j < inventory[i].subgroups.length; j++) {
inventory[i].subgroups[j].items.sort(sortByOrder)
for (let k = 0; k < inventory[i].subgroups[j].items.length; k++) {
removeExtraInfo(inventory[i].subgroups[j].items[k])
}
removeExtraInfo(inventory[i].subgroups[j])
}
removeExtraInfo(inventory[i])
}
function sortByOrder(a, b) {
// https://forums.factorio.com/viewtopic.php?f=25&t=3236#p23818
// https://forums.factorio.com/viewtopic.php?f=25&t=24163#p152955
if (a.order < b.order) return -1
if (a.order > b.order) return 1
return 0
}
function removeExtraInfo(obj) {
for (const k of Object.keys(obj)) {
if (!['subgroups', 'items', 'name', 'icon', 'icons'].includes(k)) delete obj[k]
}
}
fse.writeFileSync(bundlesOutDir + 'inventoryBundle.json', JSON.stringify(inventory, null, 2).replace(/"((__base__|__core__)\/.+?)"/g, function(match, capture) {
return '"icon:' + nameMapping(capture) + '"'
}))
let paths = []
for (let i = 0, l = inventory.length; i < l; i++) {
paths.push(factorioDirectory + inventory[i].icon.replace(/__base__/g, 'base').replace(/__core__/g, 'core'))
for (let j = 0, l2 = inventory[i].subgroups.length; j < l2; j++) {
for (let k = 0, l3 = inventory[i].subgroups[j].items.length; k < l3; k++) {
const item = inventory[i].subgroups[j].items[k]
if (item.icon) {
paths.push(factorioDirectory + item.icon.replace(/__base__/g, 'base').replace(/__core__/g, 'core'))
} else {
for (let l = 0; l < item.icons.length; l++) {
paths.push(factorioDirectory + item.icons[l].icon.replace(/__base__/g, 'base').replace(/__core__/g, 'core'))
}
}
}
}
}
paths = Array.from(new Set(paths).values())
console.log('Icon sprites: ' + paths.length)
nsg({
src: paths,
spritePath: spritesheetsOutDir + 'iconSpritesheet.png',
stylesheet: './json-icon.tpl',
stylesheetPath: spritesheetsOutDir + 'iconSpritesheet.json',
stylesheetOptions: {
prefix: 'icon:',
nameMapping: nameMapping
},
compositor: 'jimp',
layout: 'packed',
layoutOptions: {
padding: 2
}
}, function(err) {
if (err)
console.log(err)
else
console.log('Icon sprite atlas generated!')
})
let entities = {}
function findAllEntities(data) {
if (data.constructor === Object) {
if (placeableEntities.includes(data.name) && data.hasOwnProperty('collision_box') && (!data.flags.includes('placeable-off-grid') || data.name === 'land-mine')) {
entities[data.name] = data
} else {
for (let k in data) {
if (data.hasOwnProperty(k)) {
findAllEntities(data[k])
}
}
}
}
}
findAllEntities(rawData)
const regexNameMatches = [
'combinator',
'underground-belt',
'transport-belt',
'splitter',
'inserter',
'turret',
'mining-drill',
'pump'
]
let nameMatches = [
'assembling-machine-2',
'assembling-machine-3',
'pipe-to-ground',
'oil-refinery',
'chemical-plant',
'heat-exchanger',
'boiler',
'train-stop'
]
for (let k in entities) {
// Size
const box = entities[k].selection_box
entities[k].size = {
width: Math.ceil(Math.abs(box[0][0]) + Math.abs(box[1][0])),
height: Math.ceil(Math.abs(box[0][1]) + Math.abs(box[1][1]))
}
// Move out splitters and underground-belts from transport-belt fast_replaceable_group
if (k.search('splitter') !== -1) {
entities[k].fast_replaceable_group = 'splitter'
}
if (k.search('underground-belt') !== -1) {
entities[k].fast_replaceable_group = 'underground-belt'
}
// Possible Rotations
for (let j = 0; j < regexNameMatches.length; j++) {
if (k.includes(regexNameMatches[j])) {
nameMatches.push(k)
}
}
}
// Actual land size of the offshore pump
entities['offshore-pump'].size = { width: 1, height: 1 }
for (let i = 0; i < nameMatches.length; i++) {
entities[nameMatches[i]].possible_rotations = [0, 2, 4, 6]
}
entities['storage-tank'].possible_rotations = [0, 2]
entities['gate'].possible_rotations = [0, 2]
entities['steam-engine'].possible_rotations = [0, 2]
entities['steam-turbine'].possible_rotations = [0, 2]
entities['straight-rail'].possible_rotations = [0, 2]
entities['rail-signal'].possible_rotations = [0, 1, 2, 3, 4, 5, 6, 7]
entities['rail-chain-signal'].possible_rotations = [0, 1, 2, 3, 4, 5, 6, 7]
// End Possible Rotations
// switch dir 2 and 6 for pipe-to-ground
let dir2 = Object.assign({}, entities['pipe-to-ground'].pictures['2'])
entities['pipe-to-ground'].pictures['2'] = entities['pipe-to-ground'].pictures['6']
entities['pipe-to-ground'].pictures['6'] = dir2
// shift.y-1 for dir 4 wall patch of gate
let wp4 = entities['gate'].wall_patch['4'].layers[0]
wp4.shift = [wp4.shift[0], wp4.shift[1] - 1]
if (wp4.hr_version) {
wp4.hr_version.shift = [wp4.hr_version.shift[0], wp4.hr_version.shift[1] - 1]
}
// fix shifts
entities['storage-tank'].pictures.window_background.shift = [0, 1]
entities['storage-tank'].pictures.window_background.hr_version.shift = [0, 1]
add_to_shift([0, -0.6875], entities['artillery-turret'].base_picture.layers[0])
add_to_shift([0, -0.6875], entities['artillery-turret'].cannon_barrel_pictures.layers[0])
add_to_shift([0, -0.6875], entities['artillery-turret'].cannon_base_pictures.layers[0])
function add_to_shift(shift, tab) {
if (tab.shift) {
tab.shift = [shift[0] + tab.shift[0], shift[1] + tab.shift[1]]
} else {
tab.shift = shift
}
if (tab.hr_version) {
if (tab.hr_version.shift) {
tab.hr_version.shift = [shift[0] + tab.hr_version.shift[0], shift[1] + tab.hr_version.shift[1]]
} else {
tab.hr_version.shift = shift
}
}
return tab
}
// Fix inconsistent radiuses
entities['beacon'].supply_area_distance += 1
entities['roboport'].construction_radius += 4
entities['roboport'].logistics_radius += 4
console.log('Entities: ' + Object.keys(entities).length)
fse.writeFileSync(bundlesOutDir + 'entityBundle.json', JSON.stringify(entities, null, 2).replace(/"((__base__|__core__)\/.+?)"/g, function(match, capture) {
return '"entity:' + nameMapping(capture) + '"'
}))
graphicsBundle()
async function graphicsBundle() {
let paths = []
let hrPaths = []
let re = /"filename":\s*"([^.]+?\.png)"/g
let str = JSON.stringify(entities)
let match
const excludeKeywords = [
'explosion',
'cloud',
'smoke',
'fire',
'muzzle-flash',
'-light\.padding',
'steam\.png',
'-shadow\.png',
'-shadow-',
'load-standup',
'flamethrower-turret-gun(-[^e]|[^-])',
'pump-[a-z]+?-liquid',
'pump-[a-z]+?-glass',
'accumulator-[a-z]+?-animation',
'connector\/(hr-)?.-.-',
'heated',
'gun-turret-gun-[m12]',
'roboport-recharging',
'segment-visualisation',
'graphics\/[^/]*$',
'-light\.png',
'-lights-color',
'boiling-green',
'power-switch-electricity',
'electric-furnace-heater',
'integration',
'arrows',
'hole',
'rocket-over',
'working',
'hand-closed'
]
const excludeKeywordsRegex = new RegExp(excludeKeywords.join('|'), 'g')
while ((match = re.exec(str)) !== null) {
let path = match[1].replace(/__base__/g, 'base').replace(/__core__/g, 'core')
if (match[1].search(excludeKeywordsRegex) === -1) {
if (match[1].search(/\/hr-/g) === -1) {
if (!paths.includes(path)) {
paths.push(path)
}
} else {
if (!hrPaths.includes(path)) {
hrPaths.push(path)
}
}
}
}
paths.push('base/graphics/entity/artillery-wagon/artillery-wagon-cannon-barrel-1.png')
paths.push('base/graphics/entity/artillery-wagon/artillery-wagon-cannon-barrel-5.png')
paths.push('base/graphics/entity/artillery-wagon/artillery-wagon-cannon-barrel-9.png')
paths.push('base/graphics/entity/artillery-wagon/artillery-wagon-cannon-barrel-13.png')
hrPaths.push('base/graphics/entity/artillery-wagon/hr-artillery-wagon-cannon-barrel-1.png')
hrPaths.push('base/graphics/entity/artillery-wagon/hr-artillery-wagon-cannon-barrel-5.png')
hrPaths.push('base/graphics/entity/artillery-wagon/hr-artillery-wagon-cannon-barrel-9.png')
hrPaths.push('base/graphics/entity/artillery-wagon/hr-artillery-wagon-cannon-barrel-13.png')
paths.push('base/graphics/entity/artillery-wagon/artillery-wagon-cannon-base-1.png')
paths.push('base/graphics/entity/artillery-wagon/artillery-wagon-cannon-base-5.png')
paths.push('base/graphics/entity/artillery-wagon/artillery-wagon-cannon-base-9.png')
paths.push('base/graphics/entity/artillery-wagon/artillery-wagon-cannon-base-13.png')
hrPaths.push('base/graphics/entity/artillery-wagon/hr-artillery-wagon-cannon-base-1.png')
hrPaths.push('base/graphics/entity/artillery-wagon/hr-artillery-wagon-cannon-base-5.png')
hrPaths.push('base/graphics/entity/artillery-wagon/hr-artillery-wagon-cannon-base-9.png')
hrPaths.push('base/graphics/entity/artillery-wagon/hr-artillery-wagon-cannon-base-13.png')
console.log('Entity images: ' + paths.length)
console.log('Entity HR images: ' + hrPaths.length)
let cropImages = [
['artillery-wagon-cannon', 4, 4],
['flamethrower-turret-gun-extension', 5, 1],
['gun-turret-gun-extension', 5, 1],
['laser-turret-gun-start', 15, 1],
['burner-mining-drill', 4, 8],
['electric-mining-drill', 8, 8],
['pumpjack-horsehead', 8, 5],
['assembling-machine-[1-3]\.png', 8, 4],
['centrifuge', 8, 8],
['lab.png', 11, 3],
['[^e]-pump-', 8, 4],
['splitter', 8, 4],
['radar', 8, 8],
['steam-engine', 8, 4],
['steam-turbine', 4, 2],
['transport-belt', 16, 1],
['laser-turret-gun', 8, 1],
['beacon-antenna', 8, 4],
['roboport-door-', 16, 1],
['gate(-rail(-base)?)?-[a-z]+?(-(left|right))?\.png', 8, 2],
['arm', 4, 3],
['rail-signal\.png', 3, 1],
['rail-chain-signal\.png', 4, 1],
['power-switch', 2, 3]
]
let addedHrPaths = []
let imagesToCrop = []
for (let i = 0; i < paths.length; i++) {
let pArr = paths[i].split('/')
if (pArr[pArr.length - 1] === 'electric-furnace-base.png') {
pArr[pArr.length - 1] = 'electric-furnace.png'
}
pArr[pArr.length - 1] = 'hr-' + pArr[pArr.length - 1]
let hrVersion = pArr.join('/')
if (hrPaths.includes(hrVersion)) {
paths[i] = hrVersion
addedHrPaths.push(hrVersion)
}
paths[i] = factorioDirectory + paths[i]
// Crop spritesheet
for (let j = 0, len2 = cropImages.length; j < len2; j++) {
if (paths[i].search(new RegExp(cropImages[j][0], 'g')) !== -1) {
let p = './temp/' + nameMapping(paths[i]) + '.png'
imagesToCrop.push({
path: paths[i],
outPath: p,
cropImgIndex: j
})
paths[i] = p
break
}
}
}
for (let i = 0; i < hrPaths.length; i++) {
if (!addedHrPaths.includes(hrPaths[i])) {
paths.push(factorioDirectory + hrPaths[i])
}
}
Promise.all(
imagesToCrop
.map(data => Jimp.read(data.path)
.then(img => img
.crop(0, 0, img.bitmap.width / cropImages[data.cropImgIndex][1], img.bitmap.height / cropImages[data.cropImgIndex][2])
.write(data.outPath)
))).then(() => {
console.log('Final entity images: ' + paths.length)
nsg({
src: paths,
spritePath: spritesheetsOutDir + 'entitySpritesheet.png',
stylesheet: './json-entity.tpl',
stylesheetPath: spritesheetsOutDir + 'entitySpritesheet.json',
stylesheetOptions: {
prefix: 'entity:',
nameMapping: nameMapping
},
compositor: 'jimp',
layout: 'packed',
layoutOptions: {
padding: 2
}
}, function(err) {
if (err) {
console.log(err)
} else {
fse.remove('./temp')
console.log('Entity sprite atlas generated!')
}
})
})
}

View File

@ -1,6 +1,13 @@
// tslint:disable:no-import-side-effect
import 'normalize.css'
import entitySpritesheetPNG from 'factorio-data/data/graphics/HREntitySpritesheet.png'
import entitySpritesheetJSON from 'factorio-data/data/graphics/HREntitySpritesheet.json'
import iconSpritesheetPNG from 'factorio-data/data/graphics/iconSpritesheet.png'
import iconSpritesheetJSON from 'factorio-data/data/graphics/iconSpritesheet.json'
import extra_iconSpritesheetPNG from './spritesheets/extra_iconSpritesheet.png'
import extra_iconSpritesheetJSON from './spritesheets/extra_iconSpritesheet.json'
import * as PIXI from 'pixi.js'
import keyboardJS from 'keyboardjs'
@ -71,7 +78,6 @@ for (const p of params) {
}
G.app = new PIXI.Application({
autoStart: false,
antialias: true,
resolution: window.devicePixelRatio
// roundPixels: true
@ -111,19 +117,18 @@ G.app.stage.addChild(G.toolbarContainer)
const infoContainer = new InfoContainer()
G.app.stage.addChild(infoContainer)
PIXI.loader
.add([
{ name: 'extra_iconSpritesheet', url: 'spritesheets/extra_iconSpritesheet.json' },
{ name: 'iconSpritesheet', url: 'spritesheets/iconSpritesheet.json' },
{ name: 'entitySpritesheet', url: 'spritesheets/entitySpritesheet.json' }
])
.load((_: any, resources: any) => {
G.app.renderer.plugins.prepare
.add(resources.extra_iconSpritesheet.spritesheet.baseTexture)
.add(resources.iconSpritesheet.spritesheet.baseTexture)
.add(resources.entitySpritesheet.spritesheet.baseTexture)
.upload(setup)
})
Promise.all([
[ entitySpritesheetPNG, entitySpritesheetJSON ],
[ iconSpritesheetPNG, iconSpritesheetJSON ],
[ extra_iconSpritesheetPNG, extra_iconSpritesheetJSON ]
].map(data =>
new Promise((resolve, reject) => {
const image = new Image()
image.src = data[0]
image.onload = () => new PIXI.Spritesheet(PIXI.BaseTexture.from(image), data[1]).parse(resolve)
image.onerror = reject
})
)).then(setup)
function setup() {
loadBpFromSource(bpSource).then(() => {
@ -135,7 +140,6 @@ function setup() {
y: G.app.renderer.height / 2
})
G.app.start()
G.app.renderer.view.style.display = 'block'
})
}

View File

@ -22,7 +22,7 @@
"version": { "type": "integer" },
"item": {
"type": "string",
"const": "blueprint-book"
"const": "blueprint_book"
},
"label": { "type": "string" },
"active_index": { "type": "integer" },

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -127,7 +127,7 @@ export class BlueprintContainer extends PIXI.Container {
// TODO: maybe check for curved rails as well
for (const entity_number of G.bp.rawEntities.keys()) {
const entity = G.bp.entity(entity_number)
if (entity.name === 'straight-rail') {
if (entity.name === 'straight_rail') {
const x = Math.abs(entity.position.x)
const y = Math.abs(entity.position.y)
G.railMoveOffset = {

View File

@ -46,7 +46,7 @@ export class EditEntityContainer extends PIXI.Container {
const entity = G.bp.entity(entity_number)
const cc = entity.entityData.crafting_categories
if (cc && !cc.includes('rocket-building') && !cc.includes('smelting')) {
if (cc && !cc.includes('rocket_building') && !cc.includes('smelting')) {
const recipeContainer = new PIXI.Container()
const background = new PIXI.Sprite(PIXI.Texture.WHITE)
background.anchor.set(0.5, 0.5)

View File

@ -51,7 +51,7 @@ export class EntityContainer extends PIXI.Container {
for (let i = 0, l = anims.length; i < l; i++) {
const img = new EntitySprite(anims[i])
if (entity.name === 'straight-rail' || entity.name === 'curved-rail') {
if (entity.name === 'straight_rail' || entity.name === 'curved_rail') {
if (i < 2) {
img.zIndex = -10
} else if (i < 4) {
@ -59,7 +59,7 @@ export class EntityContainer extends PIXI.Container {
} else {
img.zIndex = -8
}
} else if (entity.type === 'transport-belt' || entity.name === 'heat-pipe') {
} else if (entity.type === 'transport_belt' || entity.name === 'heat_pipe') {
img.zIndex = i === 0 ? -7 : -6
} else {
img.zIndex = 0
@ -142,7 +142,7 @@ export class EntityContainer extends PIXI.Container {
}
const entity = G.bp.entity(this.entity_number)
let otherEntity
if (G.currentMouseState === G.mouseStates.NONE && entity.type === 'underground-belt') {
if (G.currentMouseState === G.mouseStates.NONE && entity.type === 'underground_belt') {
otherEntity = G.bp.entityPositionGrid.findEntityWithSameNameAndDirection(
entity.name, entity.direction, entity.position,
entity.directionType === 'input' ? entity.direction : (entity.direction + 4) % 8,
@ -189,7 +189,7 @@ export class EntityContainer extends PIXI.Container {
entity.name,
{ x: this.position.x / 32, y: this.position.y / 32 },
entity.direction,
entity.directionType === 'output' || entity.name === 'pipe-to-ground' ? (entity.direction + 4) % 8 : entity.direction
entity.directionType === 'output' || entity.name === 'pipe_to_ground' ? (entity.direction + 4) % 8 : entity.direction
)
}
@ -247,7 +247,7 @@ export class EntityContainer extends PIXI.Container {
const entity = G.bp.entity(this.entity_number)
entity.recipe = recipeName
this.redrawEntityInfo()
if (entity.name === 'chemical-plant' || entity.assemblerCraftsWithFluid || G.bp.entity(this.entity_number).assemblerCraftsWithFluid) {
if (entity.name === 'chemical_plant' || entity.assemblerCraftsWithFluid || G.bp.entity(this.entity_number).assemblerCraftsWithFluid) {
this.redraw()
this.redrawSurroundingEntities()
}
@ -277,10 +277,10 @@ export class EntityContainer extends PIXI.Container {
redrawEntityInfo() {
const entity = G.bp.entity(this.entity_number)
if (entity.entityData.module_specification || entity.type === 'splitter' ||
entity.entityData.crafting_categories || entity.type === 'mining-drill' ||
entity.entityData.crafting_categories || entity.type === 'mining_drill' ||
entity.type === 'boiler' || entity.type === 'generator' ||
entity.name === 'pump' || entity.name === 'offshore-pump' ||
entity.name === 'arithmetic-combinator' || entity.name === 'decider-combinator'
entity.name === 'pump' || entity.name === 'offshore_pump' ||
entity.name === 'arithmetic_combinator' || entity.name === 'decider_combinator'
) {
if (this.entityInfo) this.entityInfo.destroy()
this.entityInfo = G.BPC.overlayContainer.createEntityInfo(this.entity_number, this.position)
@ -329,9 +329,9 @@ export class EntityContainer extends PIXI.Container {
if (newCursorPos.x !== G.gridCoords16.x || newCursorPos.y !== G.gridCoords16.y) {
const entity = G.bp.entity(this.entity_number)
switch (entity.name) {
case 'straight-rail':
case 'curved-rail':
case 'train-stop':
case 'straight_rail':
case 'curved_rail':
case 'train_stop':
this.x = newPosition.x - (newPosition.x + G.railMoveOffset.x * 32) % 64 + 32
this.y = newPosition.y - (newPosition.y + G.railMoveOffset.y * 32) % 64 + 32
break
@ -398,7 +398,7 @@ export class EntityContainer extends PIXI.Container {
for (const updateGroup of updateGroups) {
const j = updateGroup.is.indexOf(entity.name)
if (j !== -1) {
if (entity.name === 'straight-rail') {
if (entity.name === 'straight_rail') {
G.bp.entityPositionGrid.foreachOverlap(entity.getArea(), (entnr: number) => {
const ent = G.bp.entity(entnr)
if (ent.name === 'gate' && !redrawnEntities.includes(entnr)) {

View File

@ -1,4 +1,4 @@
import inventoryBundle from '../bundles/inventoryBundle.json'
import inventoryBundle from 'factorio-data/data/prototypes/inventoryLayout'
import factorioData from '../factorio-data/factorioData'
import { AdjustmentFilter } from '@pixi/filter-adjustment'
import util from '../util'
@ -136,7 +136,7 @@ export class InventoryContainer extends PIXI.Container {
})
}
img.on('pointerover', () => {
this.itemTooltip.text = item.name.split('-').map((s: any) => s.charAt(0).toUpperCase() + s.slice(1)).join(' ')
this.itemTooltip.text = item.name.split('_').map((s: any) => s.charAt(0).toUpperCase() + s.slice(1)).join(' ')
this.createRecipeVisualization(item.name)
})
img.on('pointerout', () => {

View File

@ -30,10 +30,10 @@ export class OverlayContainer extends PIXI.Container {
const entity = G.bp.entity(entity_number)
const entityInfo = new PIXI.Container()
if (entity.recipe && entity.recipe !== 'rocket-part') {
if (entity.recipe && entity.recipe !== 'rocket_part') {
const recipeInfo = new PIXI.Container()
createIconWithBackground(recipeInfo, entity.recipe)
const S = entity.name === 'oil-refinery' ? 1.5 : 0.9
const S = entity.name === 'oil_refinery' ? 1.5 : 0.9
recipeInfo.scale.set(S, S)
recipeInfo.position.set(0, -10)
entityInfo.addChild(recipeInfo)
@ -42,7 +42,7 @@ export class OverlayContainer extends PIXI.Container {
const recipeData = factorioData.getRecipe(entity.recipe)
const rD = recipeData.normal ? recipeData.normal : recipeData
switch (recipeData.category) {
case 'oil-processing':
case 'oil_processing':
case 'chemistry':
const inputPositions: IPoint[] = []
const outputPositions: IPoint[] = []
@ -74,7 +74,7 @@ export class OverlayContainer extends PIXI.Container {
createIconsForType('input')
if (rD.results) createIconsForType('output')
break
case 'crafting-with-fluid':
case 'crafting_with_fluid':
function createIconForType(type: string) {
for (const io of type === 'input' ? rD.ingredients : rD.results) {
if (io.type === 'fluid') {
@ -179,7 +179,7 @@ export class OverlayContainer extends PIXI.Container {
entityInfo.addChild(filterInfo)
}
if (entity.name === 'arithmetic-combinator' || entity.name === 'decider-combinator') {
if (entity.name === 'arithmetic_combinator' || entity.name === 'decider_combinator') {
const arrows = new PIXI.Container()
arrows.addChild(createArrow({ x: 0, y: -48 }), createArrow({ x: 0, y: 48 }))
arrows.rotation = entity.direction * Math.PI * 0.25
@ -187,7 +187,7 @@ export class OverlayContainer extends PIXI.Container {
entityInfo.addChild(arrows)
}
if (entity.type === 'mining-drill' && entity.name !== 'pumpjack') {
if (entity.type === 'mining_drill' && entity.name !== 'pumpjack') {
const arrows = new PIXI.Container()
arrows.addChild(createArrow({
x: entity.entityData.vector_to_place_result[0] * 64,
@ -198,8 +198,8 @@ export class OverlayContainer extends PIXI.Container {
entityInfo.addChild(arrows)
}
if (entity.name === 'pumpjack' || entity.name === 'pump' || entity.name === 'offshore-pump' || entity.type === 'boiler' ||
entity.type === 'generator' || entity.name === 'oil-refinery' || entity.name === 'chemical-plant' || entity.assemblerCraftsWithFluid
if (entity.name === 'pumpjack' || entity.name === 'pump' || entity.name === 'offshore_pump' || entity.type === 'boiler' ||
entity.type === 'generator' || entity.name === 'oil_refinery' || entity.name === 'chemical_plant' || entity.assemblerCraftsWithFluid
) {
const arrows = new PIXI.Container()
if (entity.entityData.fluid_boxes) {
@ -210,7 +210,7 @@ export class OverlayContainer extends PIXI.Container {
y: c.pipe_connections[0].position[1]
})
} else {
const dontConnectOutput = entity.name === 'chemical-plant' && entity.chemicalPlantDontConnectOutput
const dontConnectOutput = entity.name === 'chemical_plant' && entity.chemicalPlantDontConnectOutput
for (const c of entity.entityData.fluid_boxes) {
// fluid_boxes are reversed
if (!(c.production_type === 'input' && dontConnectOutput)) {
@ -228,7 +228,7 @@ export class OverlayContainer extends PIXI.Container {
f({
x: p.position[0],
y: p.position[1]
}, entity.entityData.fluid_box.production_type === 'input-output' ? 2 : 1)
}, entity.entityData.fluid_box.production_type === 'input_output' ? 2 : 1)
}
}
if (entity.entityData.output_fluid_box) {
@ -242,7 +242,7 @@ export class OverlayContainer extends PIXI.Container {
}
function f(position: IPoint, type = 1) {
const offset = 0.5
if (entity.name === 'offshore-pump') position.y -= 2
if (entity.name === 'offshore_pump') position.y -= 2
const dir = Math.abs(position.x) > Math.abs(position.y) ?
(Math.sign(position.x) === 1 ? 2 : 6) :
(Math.sign(position.y) === 1 ? 4 : 0)
@ -261,7 +261,7 @@ export class OverlayContainer extends PIXI.Container {
arrows.addChild(arrow)
}
if (entity.name !== 'pumpjack') {
arrows.rotation = (entity.name === 'oil-refinery' || entity.name === 'pump' || entity.type === 'boiler' ?
arrows.rotation = (entity.name === 'oil_refinery' || entity.name === 'pump' || entity.type === 'boiler' ?
entity.direction : (entity.direction + 4) % 8) * Math.PI * 0.25
}
arrows.scale.set(0.5, 0.5)
@ -347,11 +347,11 @@ export class OverlayContainer extends PIXI.Container {
updateUndergroundLines(name: string, position: IPoint, direction: number, searchDirection: number) {
const fd = factorioData.getEntity(name)
if (fd.type === 'underground-belt' || name === 'pipe-to-ground') {
if (fd.type === 'underground_belt' || name === 'pipe_to_ground') {
this.undergroundLines.removeChildren()
const otherEntity = G.bp.entityPositionGrid.findEntityWithSameNameAndDirection(
name,
name === 'pipe-to-ground' ? searchDirection : direction,
name === 'pipe_to_ground' ? searchDirection : direction,
position,
searchDirection,
fd.max_distance || 10
@ -359,13 +359,13 @@ export class OverlayContainer extends PIXI.Container {
if (otherEntity) {
const oE = G.bp.entity(otherEntity)
// Return if directionTypes are the same
if (fd.type === 'underground-belt' &&
if (fd.type === 'underground_belt' &&
(oE.directionType === 'input' ? oE.direction : (oE.direction + 4 % 8)) === searchDirection) return
const distance = searchDirection % 4 === 0 ? Math.abs(oE.position.y - position.y) :
Math.abs(oE.position.x - position.x)
const sign = searchDirection === 0 || searchDirection === 6 ? -1 : 1
for (let i = 1; i < distance; i++) {
const s = PIXI.Sprite.fromFrame('extra-icon:underground-lines-' + (name === 'pipe-to-ground' ? '0' : '1'))
const s = PIXI.Sprite.fromFrame('extra-icon:underground-lines-' + (name === 'pipe_to_ground' ? '0' : '1'))
s.rotation = direction * Math.PI * 0.25
s.scale.set(0.5, 0.5)
s.anchor.set(0.5, 0.5)

View File

@ -69,7 +69,7 @@ export class PaintContainer extends PIXI.Container {
updateUndergroundBeltRotation() {
const fd = factorioData.getEntity(this.name)
if (fd.type === 'underground-belt') {
if (fd.type === 'underground_belt') {
const otherEntity = G.bp.entityPositionGrid.findEntityWithSameNameAndDirection(
this.name, (this.direction + 4) % 8, {
x: this.x / 32,
@ -93,7 +93,7 @@ export class PaintContainer extends PIXI.Container {
this.name,
{ x: this.position.x / 32, y: this.position.y / 32 },
this.directionType === 'input' ? this.direction : (this.direction + 4) % 8,
this.name === 'pipe-to-ground' ? (this.direction + 4) % 8 : this.direction
this.name === 'pipe_to_ground' ? (this.direction + 4) % 8 : this.direction
)
}
@ -164,9 +164,9 @@ export class PaintContainer extends PIXI.Container {
if (this.holdingRightClick) this.removeContainer()
switch (this.name) {
case 'straight-rail':
case 'curved-rail':
case 'train-stop':
case 'straight_rail':
case 'curved_rail':
case 'train_stop':
this.position.set(
newPosition.x - (newPosition.x + G.railMoveOffset.x * 32) % 64 + 32,
newPosition.y - (newPosition.y + G.railMoveOffset.y * 32) % 64 + 32
@ -226,7 +226,7 @@ export class PaintContainer extends PIXI.Container {
return
}
const isUB = fd.type === 'underground-belt'
const isUB = fd.type === 'underground_belt'
const res = G.bp.createEntity(this.name, position,
isUB && this.directionType === 'output' ? (this.direction + 4) % 8 : this.direction,
isUB ? this.directionType : undefined
@ -243,7 +243,7 @@ export class PaintContainer extends PIXI.Container {
G.BPC.entities.addChild(ec)
ec.redrawSurroundingEntities()
if (isUB || this.name === 'pipe-to-ground') {
if (isUB || this.name === 'pipe_to_ground') {
this.direction = (this.direction + 4) % 8
this.redraw()
G.BPC.overlayContainer.hideUndergroundLines()

View File

@ -18,7 +18,7 @@ export class UnderlayContainer extends PIXI.Container {
color: [0x83D937, undoBlendModeColorShift(0xFF8800, 0x83D937, 0.25)]
}
}
if (type === 'electric-pole') {
if (type === 'electric_pole') {
return {
type: 'poles',
rKey: 'supply_area_distance',
@ -32,7 +32,7 @@ export class UnderlayContainer extends PIXI.Container {
color: 0xD9C037
}
}
if (name === 'electric-mining-drill') {
if (name === 'electric_mining_drill') {
return {
type: 'drills',
rKey: 'resource_searching_radius',
@ -79,7 +79,7 @@ export class UnderlayContainer extends PIXI.Container {
const ed = factorioData.getEntity(entityName)
const data = UnderlayContainer.getDataForVisualizationArea(entityName)
if (data) if (isArray(data.type)) this.active.push(...data.type); else this.active.push(data.type)
if (ed.type === 'logistic-container') this.active.push('logistics0', 'logistics1')
if (ed.type === 'logistic_container') this.active.push('logistics0', 'logistics1')
if (ed.energy_source && ed.energy_source.type === 'electric') this.active.push('poles')
if (ed.module_specification) this.active.push('beacons')

View File

@ -43,7 +43,12 @@ export default {
decode: (str: string) => {
let data
try {
data = JSON.parse(zlib.inflateSync(Buffer.from(str.slice(1), 'base64')).toString('utf8'))
data = JSON.parse(
zlib
.inflateSync(Buffer.from(str.slice(1), 'base64'))
.toString('utf8')
.replace(/("[^,]{3,}?")/g, (_, capture) => capture.replace(/-/g, '_'))
)
} catch (e) {
return { error: e }
}
@ -63,5 +68,9 @@ export default {
if (data.blueprint_book === undefined) return new Blueprint(data.blueprint)
return new Book(data)
},
encode: (bPOrBook: any) => ('0' + zlib.deflateSync(JSON.stringify(bPOrBook.toObject())).toString('base64'))
encode: (bPOrBook: any) => ('0' +
zlib.deflateSync(JSON.stringify(bPOrBook.toObject()))
.toString('base64')
.replace(/(".+?")/g, (_, capture) => capture.replace(/_/g, '-'))
)
}

View File

@ -251,7 +251,7 @@ export class Blueprint {
}
getFirstRail() {
const fR = this.rawEntities.find(v => v.get('name') === 'straight-rail' || v.get('name') === 'curved-rail')
const fR = this.rawEntities.find(v => v.get('name') === 'straight_rail' || v.get('name') === 'curved_rail')
return fR ? fR.toJS() : undefined
}

View File

@ -45,7 +45,7 @@ export class Book {
return {
blueprint_book: {
blueprints,
item: 'blueprint-book',
item: 'blueprint_book',
active_index: this.active_index,
version: 0
}

View File

@ -29,9 +29,9 @@ export default (BP: Blueprint) => {
map.setIn([this.entity_number, 'recipe'], recipeName)
const modules = this.modules
if (modules && recipeName && !factorioData.getItem('productivity-module').limitation.includes(recipeName)) {
if (modules && recipeName && !factorioData.getItem('productivity_module').limitation.includes(recipeName)) {
for (const k in modules) {
if (k.includes('productivity-module')) delete modules[k]
if (k.includes('productivity_module')) delete modules[k]
}
map.setIn([this.entity_number, 'items'], Object.keys(modules).length ? Immutable.fromJS(modules) : undefined)
}
@ -47,8 +47,8 @@ export default (BP: Blueprint) => {
for (const k in recipes) {
if (cc.includes(recipes[k].category) || (cc.includes('crafting') && !recipes[k].category)) {
const recipe = (recipes[k].normal ? recipes[k].normal : recipes[k])
if (!((this.name === 'assembling-machine-1' && recipe.ingredients.length > 2) ||
(this.name === 'assembling-machine-2' && recipe.ingredients.length > 4))
if (!((this.name === 'assembling_machine_1' && recipe.ingredients.length > 2) ||
(this.name === 'assembling_machine_2' && recipe.ingredients.length > 4))
) {
acceptedRecipes.push(k)
}
@ -60,11 +60,11 @@ export default (BP: Blueprint) => {
get acceptedModules() {
if (!this.entityData.module_specification) return
const ommitProductivityModules = this.name === 'beacon' ||
(this.recipe && !factorioData.getItem('productivity-module').limitation.includes(this.recipe))
(this.recipe && !factorioData.getItem('productivity_module').limitation.includes(this.recipe))
const items = factorioData.getItems()
const acceptedModules: string[] = []
for (const k in items) {
if (items[k].type === 'module' && !(k.includes('productivity-module') && ommitProductivityModules)) acceptedModules.push(k)
if (items[k].type === 'module' && !(k.includes('productivity_module') && ommitProductivityModules)) acceptedModules.push(k)
}
return acceptedModules
},
@ -165,12 +165,12 @@ export default (BP: Blueprint) => {
}
// TODO: Optimize this
if (this.type === 'electric-pole') {
if (this.type === 'electric_pole') {
const copperConn: any[] = []
BP.rawEntities.forEach((v, k) => {
const entity = v.toJS()
if (entity.name === 'power-switch' && entity.connections) {
if (entity.name === 'power_switch' && entity.connections) {
if (entity.connections.Cu0 && entity.connections.Cu0[0].entity_id === this.entity_number) {
copperConn.push({ entity_id: k })
}
@ -219,11 +219,11 @@ export default (BP: Blueprint) => {
},
get operator() {
if (this.name === 'decider-combinator') {
if (this.name === 'decider_combinator') {
const cb = rawEntity.get('control_behavior')
if (cb) return cb.getIn(['decider_conditions', 'comparator'])
}
if (this.name === 'arithmetic-combinator') {
if (this.name === 'arithmetic_combinator') {
const cb = rawEntity.get('control_behavior')
if (cb) return cb.getIn(['arithmetic_conditions', 'operation'])
}
@ -261,19 +261,19 @@ export default (BP: Blueprint) => {
rotate(notMoving: boolean, offset?: IPoint, pushToHistory = true, otherEntity?: number) {
if (!this.assemblerCraftsWithFluid &&
(this.name === 'assembling-machine-2' || this.name === 'assembling-machine-3')) return false
(this.name === 'assembling_machine_2' || this.name === 'assembling_machine_3')) return false
if (notMoving && BP.entityPositionGrid.sharesCell(this.getArea())) return false
const pr = this.entityData.possible_rotations
if (!pr) return false
const newDir = pr[(pr.indexOf(this.direction) +
(notMoving && (this.size.x !== this.size.y || this.type === 'underground-belt') ? 2 : 1)
(notMoving && (this.size.x !== this.size.y || this.type === 'underground_belt') ? 2 : 1)
) % pr.length
]
if (newDir === this.direction) return false
BP.operation(otherEntity ? [this.entity_number, otherEntity] : this.entity_number, 'Rotated entity',
entities => entities.withMutations(map => {
map.setIn([this.entity_number, 'direction'], newDir)
if (notMoving && this.type === 'underground-belt') {
if (notMoving && this.type === 'underground_belt') {
map.updateIn([this.entity_number, 'type'], directionType =>
directionType === 'input' ? 'output' : 'input'
)
@ -306,9 +306,9 @@ export default (BP: Blueprint) => {
get assemblerCraftsWithFluid() {
return this.recipe &&
factorioData.getRecipe(this.recipe).category === 'crafting-with-fluid' &&
factorioData.getRecipe(this.recipe).category === 'crafting_with_fluid' &&
this.entityData.crafting_categories &&
this.entityData.crafting_categories.includes('crafting-with-fluid')
this.entityData.crafting_categories.includes('crafting_with_fluid')
},
get assemblerPipeDirection() {
@ -339,13 +339,13 @@ export default (BP: Blueprint) => {
return e.output_connection_points[this.direction / 2].wire[color]
}
if (this.name === 'power-switch' && color === 'copper') {
if (this.name === 'power_switch' && color === 'copper') {
return e[(side === 1 ? 'left' : 'right') + '_wire_connection_point'].wire.copper
}
if (e.circuit_wire_connection_point) return e.circuit_wire_connection_point.wire[color]
if (this.type === 'transport-belt') {
if (this.type === 'transport_belt') {
return e.circuit_wire_connection_points[
factorioData.getBeltConnections2(BP, this.position, this.direction) * 4
].wire[color]
@ -353,7 +353,7 @@ export default (BP: Blueprint) => {
if (e.circuit_wire_connection_points.length === 8) {
return e.circuit_wire_connection_points[this.direction].wire[color]
}
if (this.name === 'constant-combinator') {
if (this.name === 'constant_combinator') {
return e.circuit_wire_connection_points[this.direction / 2].wire[color]
}
return e.circuit_wire_connection_points[this.direction / 2].wire[color]

View File

@ -1,7 +1,7 @@
import itemBundle from '../bundles/itemBundle.json'
import recipeBundle from '../bundles/recipeBundle.json'
import entityBundle from '../bundles/entityBundle.json'
import tileBundle from '../bundles/tileBundle.json'
import itemBundle from 'factorio-data/data/prototypes/items'
import recipeBundle from 'factorio-data/data/prototypes/recipes'
import entityBundle from 'factorio-data/data/prototypes/entities'
import tileBundle from 'factorio-data/data/prototypes/tiles'
import { Area } from './positionGrid'
import util from '../util'
import { Blueprint } from './blueprint'
@ -46,7 +46,7 @@ function hasPipeCoverFeature(e: any) {
}
function hasWireConnectionFeature(e: any) {
if (e.type === 'transport-belt') return false
if (e.type === 'transport_belt') return false
if (e.connection_points ||
e.input_connection_points ||
e.circuit_wire_connection_point ||
@ -171,7 +171,7 @@ function getAll(name: string) {
function getItemTypeForBp(name: string) {
const type = getItem(name).type
if (type === 'virtual-signal') return 'virtual'
if (type === 'virtual_signal') return 'virtual'
if (type === 'fluid') return 'fluid'
return 'item'
}
@ -211,7 +211,7 @@ function generateConnection(e: any, data: any, out: any[]) {
function generateCovers(e: any, data: IEntityData, out: any[]) {
if (e.name === 'pipe' ||
((e.name === 'assembling-machine-2' || e.name === 'assembling-machine-3') &&
((e.name === 'assembling_machine_2' || e.name === 'assembling_machine_3') &&
!data.assemblerCraftsWithFluid)
) return
@ -224,7 +224,7 @@ function generateCovers(e: any, data: IEntityData, out: any[]) {
(Math.sign(connection.y) === 1 ? 4 : 0)
function needsCover() {
if (e.name === 'chemical-plant' && data.chemicalPlantDontConnectOutput &&
if (e.name === 'chemical_plant' && data.chemicalPlantDontConnectOutput &&
data.dir === (dir + 4) % 8) return true
const pos = {
@ -235,11 +235,11 @@ function generateCovers(e: any, data: IEntityData, out: any[]) {
const ent = data.bp.entity(data.bp.entityPositionGrid.getCellAtPosition(pos))
if (!ent) return true
if (ent.name === 'chemical-plant' && ent.chemicalPlantDontConnectOutput &&
if (ent.name === 'chemical_plant' && ent.chemicalPlantDontConnectOutput &&
ent.direction === dir) return true
if (ent.name === 'pipe' ||
ent.name === 'pipe-to-ground' ||
ent.name === 'pipe_to_ground' ||
ent.entityData.fluid_box ||
ent.entityData.output_fluid_box ||
ent.entityData.fluid_boxes) {
@ -263,7 +263,7 @@ function generateCovers(e: any, data: IEntityData, out: any[]) {
}
if (!data.bp || needsCover()) {
let temp = getPipeCovers(e)[dir].layers[0]
let temp = getPipeCovers(e)[util.intToDir(dir)].layers[0]
temp = util.add_to_shift(connection, util.duplicate(temp))
if (dir === 4) {
out.push(temp)
@ -281,7 +281,7 @@ function getPipeConnectionPoints(e: any, dir: number, assemblerPipeDirection: st
return [...e.fluid_box.pipe_connections, ...e.output_fluid_box.pipe_connections]
}
if (e.fluid_box) {
if (e.name === 'pipe-to-ground') {
if (e.name === 'pipe_to_ground') {
return [e.fluid_box.pipe_connections[0]]
}
return e.fluid_box.pipe_connections
@ -306,7 +306,7 @@ function getPipeConnectionPoints(e: any, dir: number, assemblerPipeDirection: st
// tslint:disable-next-line:prefer-switch
if (e.name === 'pumpjack') {
positions.push({ x: connections[0].positions[dir / 2][0], y: connections[0].positions[dir / 2][1] })
} else if (e.name === 'assembling-machine-2' || e.name === 'assembling-machine-3') {
} else if (e.name === 'assembling_machine_2' || e.name === 'assembling_machine_3') {
positions.push(util.rotatePointBasedOnDir(
connections[assemblerPipeDirection === 'input' ? 0 : 1].position, dir
))
@ -329,8 +329,8 @@ function getHeatConnections(position: IPoint, bp: Blueprint) {
return bp.entityPositionGrid.getSurroundingEntities(new Area(position), (entnr, _, X, Y) => {
const entity = bp.entity(entnr)
// tslint:disable-next-line:prefer-switch
if (entity.name === 'heat-pipe') return true
else if (entity.name === 'heat-exchanger' || entity.name === 'nuclear-reactor') {
if (entity.name === 'heat_pipe') return true
else if (entity.name === 'heat_exchanger' || entity.name === 'nuclear_reactor') {
const connections = getHeatConectionPoints(entity.entityData)
for (const connection of connections) {
const offset = util.rotatePointBasedOnDir(connection.position, entity.direction)
@ -344,9 +344,9 @@ function getHeatConnections(position: IPoint, bp: Blueprint) {
function getBeltConnections2(bp: Blueprint, position: IPoint, dir: number) {
const directions = bp.entityPositionGrid.getSurroundingEntities(new Area(position), entnr => {
const entity = bp.entity(entnr)
if (entity.type === 'transport-belt' ||
if (entity.type === 'transport_belt' ||
entity.type === 'splitter' ||
(entity.type === 'underground-belt' &&
(entity.type === 'underground_belt' &&
entity.directionType === 'output')) return entity.direction
}, dir)
@ -372,11 +372,11 @@ function generateGraphics(e: any) {
if (e.name.search('combinator') !== -1) {
return (data: IEntityData) => {
function getBaseSprite() { return e.sprites[data.dir].layers[0] }
function getBaseSprite() { return e.sprites[util.intToDir(data.dir)].layers[0] }
if (e.name === 'decider-combinator' || e.name === 'arithmetic-combinator') {
if (e.name === 'decider_combinator' || e.name === 'arithmetic_combinator') {
function mapSymbolToSpriteName() {
if (!data.operator) return e.name === 'decider-combinator' ? 'less' : 'multiply'
if (!data.operator) return e.name === 'decider_combinator' ? 'less' : 'multiply'
switch (data.operator) {
case '<': return 'less'
case '>': return 'greater'
@ -398,16 +398,16 @@ function generateGraphics(e: any) {
case 'XOR': return 'xor'
}
}
return [getBaseSprite(), e[mapSymbolToSpriteName() + '_symbol_sprites'][data.dir]]
return [getBaseSprite(), e[mapSymbolToSpriteName() + '_symbol_sprites'][util.intToDir(data.dir)]]
}
return [getBaseSprite()]
}
}
if (e.name.search('assembling-machine') !== -1) {
if (e.name.search('assembling_machine') !== -1) {
return (data: IEntityData) => {
if (
(e.name === 'assembling-machine-2' || e.name === 'assembling-machine-3') &&
(e.name === 'assembling_machine_2' || e.name === 'assembling_machine_3') &&
data.assemblerCraftsWithFluid
) {
const pipeDirection = data.assemblerPipeDirection === 'input' ? data.dir : (data.dir + 4) % 8
@ -415,7 +415,7 @@ function generateGraphics(e: any) {
e.animation.layers[0],
util.add_to_shift(
getPipeConnectionPoints(e, data.dir, data.assemblerPipeDirection)[0],
util.duplicate(e.fluid_boxes[0].pipe_picture[pipeDirection])
util.duplicate(e.fluid_boxes[0].pipe_picture[util.intToDir(pipeDirection)])
)
]
if (pipeDirection === 0) return [out[1], out[0]]
@ -427,24 +427,24 @@ function generateGraphics(e: any) {
switch (e.name) {
case 'accumulator': return () => [e.picture]
case 'solar-panel': return () => [e.picture.layers[0]]
case 'solar_panel': return () => [e.picture.layers[0]]
case 'radar': return () => [e.pictures.layers[0]]
case 'small-lamp': return () => [e.picture_off.layers[0]]
case 'land-mine': return () => [e.picture_set]
case 'programmable-speaker': return () => [e.sprite.layers[0]]
case 'power-switch': return () => [e.power_on_animation]
case 'small_lamp': return () => [e.picture_off.layers[0]]
case 'land_mine': return () => [e.picture_set]
case 'programmable_speaker': return () => [e.sprite.layers[0]]
case 'power_switch': return () => [e.power_on_animation]
case 'beacon': return () => [e.base_picture, e.animation]
case 'lab': return () => [e.off_animation.layers[0]]
case 'offshore-pump': return (data: IEntityData) => [e.picture[data.dir]]
case 'pipe-to-ground': return (data: IEntityData) => [e.pictures[data.dir]]
case 'burner-mining-drill': return (data: IEntityData) => [e.animations[data.dir].layers[0]]
case 'offshore_pump': return (data: IEntityData) => [e.picture[util.intToDir(data.dir)]]
case 'pipe_to_ground': return (data: IEntityData) => [e.pictures[util.intToDir(data.dir)]]
case 'burner_mining_drill': return (data: IEntityData) => [e.animations[util.intToDir(data.dir)].layers[0]]
case 'pumpjack': return (data: IEntityData) => [
util.duplicateAndSetPropertyUsing(e.base_picture.sheets[0], 'x', 'width', data.dir / 2),
e.animations[0].layers[0]
e.animations.north.layers[0]
]
case 'storage-tank': return (data: IEntityData) => [
case 'storage_tank': return (data: IEntityData) => [
e.pictures.window_background,
util.set_property_using(util.duplicate(e.pictures.picture.sheets[0]), 'x', data.dir === 2 ? 'width' : undefined)
]
@ -454,7 +454,7 @@ function generateGraphics(e: any) {
e.idle_animation.layers[4]
]
case 'roboport': return () => [e.base.layers[0], e.door_animation_up, e.door_animation_down, e.base_animation]
case 'rocket-silo': return () => [
case 'rocket_silo': return () => [
e.door_back_sprite,
e.door_front_sprite,
e.base_day_sprite,
@ -464,10 +464,10 @@ function generateGraphics(e: any) {
e.satellite_animation
]
case 'electric-mining-drill':
case 'pump': return (data: IEntityData) => [e.animations[data.dir]]
case 'boiler': return (data: IEntityData) => [e.structure[data.dir].layers[0]]
case 'heat-exchanger': return (data: IEntityData) => {
case 'electric_mining_drill':
case 'pump': return (data: IEntityData) => [e.animations[util.intToDir(data.dir)]]
case 'boiler': return (data: IEntityData) => [e.structure[util.intToDir(data.dir)].layers[0]]
case 'heat_exchanger': return (data: IEntityData) => {
let needsEnding = true
if (data.bp) {
const conn = getHeatConectionPoints(e)[0]
@ -481,40 +481,40 @@ function generateGraphics(e: any) {
if (needsEnding) {
return [
util.add_to_shift(util.rotatePointBasedOnDir([0, 1.5], data.dir),
util.duplicate(e.energy_source.pipe_covers[(data.dir + 4) % 8])
util.duplicate(e.energy_source.pipe_covers[util.intToDir((data.dir + 4) % 8)])
),
e.structure[data.dir].layers[0]
e.structure[util.intToDir(data.dir)].layers[0]
]
}
return [e.structure[data.dir].layers[0]]
return [e.structure[util.intToDir(data.dir)].layers[0]]
}
case 'oil-refinery':
case 'chemical-plant': return (data: IEntityData) => [e.animation[data.dir].layers[0]]
case 'steam-engine':
case 'steam-turbine': return (data: IEntityData) => [
case 'oil_refinery':
case 'chemical_plant': return (data: IEntityData) => [e.animation[util.intToDir(data.dir)].layers[0]]
case 'steam_engine':
case 'steam_turbine': return (data: IEntityData) => [
data.dir === 0 ? e.vertical_animation.layers[0] : e.horizontal_animation.layers[0]
]
case 'gun-turret':
case 'laser-turret': return (data: IEntityData) => [
case 'gun_turret':
case 'laser_turret': return (data: IEntityData) => [
...e.base_picture.layers,
util.duplicateAndSetPropertyUsing(e.folded_animation.layers[0], 'y', 'height', data.dir / 2),
util.duplicateAndSetPropertyUsing(e.folded_animation.layers[e.name === 'laser-turret' ? 2 : 1], 'y', 'height', data.dir / 2)
util.duplicateAndSetPropertyUsing(e.folded_animation.layers[e.name === 'laser_turret' ? 2 : 1], 'y', 'height', data.dir / 2)
]
case 'train-stop': return (data: IEntityData) => {
case 'train_stop': return (data: IEntityData) => {
const dir = data.dir
let ta = util.duplicate(e.top_animations[dir].layers[1])
let ta = util.duplicate(e.top_animations[util.intToDir(dir)].layers[1])
ta = util.set_property(ta, 'color', data.trainStopColor ? data.trainStopColor : e.color)
return [
e.rail_overlay_animations[dir],
e.animations[dir].layers[0],
e.top_animations[dir].layers[0],
e.rail_overlay_animations[util.intToDir(dir)],
e.animations[util.intToDir(dir)].layers[0],
e.top_animations[util.intToDir(dir)].layers[0],
ta,
e.light1.picture[dir],
e.light2.picture[dir]
e.light1.picture[util.intToDir(dir)],
e.light2.picture[util.intToDir(dir)]
]
}
case 'flamethrower-turret': return (data: IEntityData) => {
case 'flamethrower_turret': return (data: IEntityData) => {
const dir = data.dir
let pipe = entityBundle['pipe']
pipe = dir === 0 || dir === 4 ? pipe.pictures.straight_horizontal : pipe.pictures.straight_vertical
@ -523,13 +523,13 @@ function generateGraphics(e: any) {
return [
p1,
p2,
e.base_picture[dir].layers[0],
e.base_picture[dir].layers[1],
e.folded_animation[dir].layers[0],
e.folded_animation[dir].layers[1]
e.base_picture[util.intToDir(dir)].layers[0],
e.base_picture[util.intToDir(dir)].layers[1],
e.folded_animation[util.intToDir(dir)].layers[0],
e.folded_animation[util.intToDir(dir)].layers[1]
]
}
case 'artillery-turret': return (data: IEntityData) => {
case 'artillery_turret': return (data: IEntityData) => {
const d = data.dir * 2
e.cannon_base_pictures.layers[0].filename = e.cannon_base_pictures.layers[0].filenames[d]
e.cannon_base_pictures.layers[0].hr_version.filename = e.cannon_base_pictures.layers[0].hr_version.filenames[d]
@ -541,13 +541,13 @@ function generateGraphics(e: any) {
e.cannon_base_pictures.layers[0]
]
}
case 'straight-rail':
case 'curved-rail': return (data: IEntityData) => {
case 'straight_rail':
case 'curved_rail': return (data: IEntityData) => {
const dir = data.dir
function getBaseSprites() {
function getRailSpriteForDir() {
const p = e.pictures
if (e.name === 'straight-rail') {
if (e.name === 'straight_rail') {
switch (dir) {
case 0: return p.straight_rail_vertical
case 1: return p.straight_rail_diagonal_right_top
@ -581,7 +581,7 @@ function generateGraphics(e: any) {
]
}
if (data.bp && e.name === 'straight-rail' && (dir === 0 || dir === 2)) {
if (data.bp && e.name === 'straight_rail' && (dir === 0 || dir === 2)) {
const size = util.switchSizeBasedOnDirection(e.size, dir)
const gates = data.bp.entityPositionGrid.foreachOverlap(new Area({
x: data.position.x,
@ -622,12 +622,12 @@ function generateGraphics(e: any) {
}
return getBaseSprites()
}
case 'rail-signal':
case 'rail-chain-signal': return (data: IEntityData) => {
case 'rail_signal':
case 'rail_chain_signal': return (data: IEntityData) => {
const dir = data.dir
let rp = util.duplicateAndSetPropertyUsing(e.rail_piece, 'x', 'width', dir)
let a = util.duplicateAndSetPropertyUsing(e.animation, 'y', 'height', dir)
if (e.name === 'rail-chain-signal') {
if (e.name === 'rail_chain_signal') {
function getRightShift() {
switch (dir) {
case 0: return [1, 0]
@ -646,7 +646,7 @@ function generateGraphics(e: any) {
}
return [rp, a]
}
case 'nuclear-reactor': return (data: IEntityData) => {
case 'nuclear_reactor': return (data: IEntityData) => {
const conn = e.heat_buffer.connections
const patches = []
for (let i = 0; i < conn.length; i++) {
@ -666,7 +666,7 @@ function generateGraphics(e: any) {
}
return [...patches, e.lower_layer_picture, e.picture.layers[0]]
}
case 'stone-wall': return (data: IEntityData) => {
case 'stone_wall': return (data: IEntityData) => {
function getBaseSprite() {
function getRandomPic(type: string) {
if (e.pictures[type] instanceof Array) {
@ -677,7 +677,7 @@ function generateGraphics(e: any) {
if (data.bp) {
const conn = data.bp.entityPositionGrid.getSurroundingEntities(new Area(data.position), (entnr: number, D: number) => {
const entity = data.bp.entity(entnr)
if (entity.name === 'stone-wall' || (entity.name === 'gate' && entity.direction === D % 4)) return true
if (entity.name === 'stone_wall' || (entity.name === 'gate' && entity.direction === D % 4)) return true
})
if (conn[1] && conn[2] && conn[3]) return getRandomPic('t_up')
@ -713,7 +713,7 @@ function generateGraphics(e: any) {
height: size.y
}, true), (entnr: number) => {
const ent = data.bp.entity(entnr)
if (ent.name === 'straight-rail') return ent
if (ent.name === 'straight_rail') return ent
})
if (rail) {
if (dir === 0) {
@ -733,11 +733,11 @@ function generateGraphics(e: any) {
const out = getBaseSprites()
const conn = data.bp.entityPositionGrid.getSurroundingEntities(new Area(data.position), (entnr: any, D: number) => {
const entity = data.bp.entity(entnr)
if (entity.name === 'stone-wall' && dir === D % 4) return true
if (entity.name === 'stone_wall' && dir === D % 4) return true
})
for (let i = 0; i < conn.length; i++) {
if (conn[i]) {
const wp = entityBundle['gate'].wall_patch[(i * 2 + 4) % 8].layers[0]
const wp = entityBundle['gate'].wall_patch[util.intToDir((i * 2 + 4) % 8)].layers[0]
if (i === 0) {
out.unshift(wp)
} else {
@ -754,10 +754,10 @@ function generateGraphics(e: any) {
const conn = data.bp.entityPositionGrid.getSurroundingEntities(new Area(data.position), (entnr: any, D: number) => {
const entity = data.bp.entity(entnr)
if (entity.name === 'pipe') return true
if (entity.name === 'pipe-to-ground' && entity.direction === (D + 4) % 8) return true
if ((entity.name === 'assembling-machine-2' || entity.name === 'assembling-machine-3') &&
if (entity.name === 'pipe_to_ground' && entity.direction === (D + 4) % 8) return true
if ((entity.name === 'assembling_machine_2' || entity.name === 'assembling_machine_3') &&
!entity.assemblerCraftsWithFluid) return false
if (entity.name === 'chemical-plant' && entity.chemicalPlantDontConnectOutput &&
if (entity.name === 'chemical_plant' && entity.chemicalPlantDontConnectOutput &&
entity.direction === D) return false
const ed = entity.entityData
if (ed.fluid_box || ed.output_fluid_box || ed.fluid_boxes) {
@ -789,7 +789,7 @@ function generateGraphics(e: any) {
}
return [e.pictures.straight_vertical_single]
}
case 'heat-pipe': return (data: IEntityData) => {
case 'heat_pipe': return (data: IEntityData) => {
function getRandomPic(type: string) {
if (e.connection_sprites[type].length === 1) return [e.connection_sprites[type][0]]
return [e.connection_sprites[type][util.getRandomInt(0, e.connection_sprites[type].length - 1)]]
@ -817,17 +817,17 @@ function generateGraphics(e: any) {
}
switch (e.type) {
case 'electric-pole': return () => [e.pictures]
case 'electric_pole': return () => [e.pictures]
case 'furnace': return () => [e.animation.layers[0]]
case 'container':
case 'logistic-container': return () => [e.picture]
case 'logistic_container': return () => [e.picture]
case 'splitter': return (data: IEntityData) => {
const dir = data.dir
const nP = e.name.split('-')
const beltType = nP.length === 1 ? '' : nP[0] + '-'
const nP = e.name.split('_')
const beltType = nP.length === 1 ? '' : nP[0] + '_'
let belt = entityBundle[beltType + 'transport-belt']
let belt = entityBundle[beltType + 'transport_belt']
belt = dir === 0 || dir === 4 ? belt.belt_vertical : belt.belt_horizontal
belt = util.duplicate(belt)
@ -838,9 +838,9 @@ function generateGraphics(e: any) {
belt = util.add_to_shift(util.rotatePointBasedOnDir([-0.5, 0], dir), belt)
belt2 = util.add_to_shift(util.rotatePointBasedOnDir([0.5, 0], dir), belt2)
return [belt, belt2, e.structure[dir]]
return [belt, belt2, e.structure[util.intToDir(dir)]]
}
case 'underground-belt': return (data: IEntityData) => {
case 'underground_belt': return (data: IEntityData) => {
const dir = data.dir
let belt = dir === 0 || dir === 4 ? e.belt_vertical : e.belt_horizontal
@ -866,14 +866,14 @@ function generateGraphics(e: any) {
)
]
}
case 'transport-belt': return (data: IEntityData) => {
case 'transport_belt': return (data: IEntityData) => {
const dir = data.dir
function getBeltConnections() {
const directions = data.bp.entityPositionGrid.getSurroundingEntities(new Area(data.position), (entnr: number) => {
const entity = data.bp.entity(entnr)
if (entity.type === 'transport-belt' ||
if (entity.type === 'transport_belt' ||
entity.type === 'splitter' ||
(entity.type === 'underground-belt' &&
(entity.type === 'underground_belt' &&
entity.directionType === 'output')) {
return entity.direction
}
@ -909,7 +909,7 @@ function generateGraphics(e: any) {
const temp = res === 0 || res === 4
belt = util.set_property(belt, 'rot', (res + (temp ? 0 : 2)) / 2)
belt = util.set_property_using(belt, 'y', 'height',
(temp ? 11 : 8) * (data.hr && e.name !== 'transport-belt' ? 2 : 1))
(temp ? 11 : 8) * (data.hr && e.name !== 'transport_belt' ? 2 : 1))
if (res === (dir + 2) % 8) {
belt = util.set_property(belt, temp ? 'flipX' : 'flipY', true)
}
@ -953,7 +953,7 @@ function generateGraphics(e: any) {
}
const hbMod = { ...hoMod }
const am = 0.5
if (e.name === 'long-handed-inserter') {
if (e.name === 'long_handed_inserter') {
switch (dir) {
case 0:
hoMod.rot = 2

View File

@ -57,7 +57,7 @@ export class PositionGrid {
this.grid = this.grid.withMutations(map => {
for (const entity_number of entity_numbers) {
const entity = this.bp.entity(entity_number)
if (!entity.entityData.flags.includes('placeable-off-grid')) {
if (!entity.entityData.flags.includes('placeable_off_grid')) {
PositionGrid.tileDataAction(map, entity.getArea(), (key, cell) => {
if (cell) {
if (isNumber(cell)) {
@ -120,7 +120,7 @@ export class PositionGrid {
setTileData(entity_number: number) {
const entity = this.bp.entity(entity_number)
if (entity.entityData.flags.includes('placeable-off-grid')) return
if (entity.entityData.flags.includes('placeable_off_grid')) return
this.operation(grid => grid.withMutations(map => {
PositionGrid.tileDataAction(map, entity.getArea(), (key, cell) => {
if (cell) {
@ -180,8 +180,8 @@ export class PositionGrid {
if (!this.foreachOverlap(area, cell => {
switch (this.bp.entity(cell).name) {
case 'gate': gateEnt = cell; break
case 'curved-rail': curRailEnt = cell; break
case 'straight-rail': allStrRailEnt.push(cell); strRailEnt = cell; break
case 'curved_rail': curRailEnt = cell; break
case 'straight_rail': allStrRailEnt.push(cell); strRailEnt = cell; break
default: otherEntities = true
}
})) return true
@ -196,11 +196,11 @@ export class PositionGrid {
if (
(name === 'gate' && strRailEnt && allStrRailEnt.length === 1 && this.bp.entity(strRailEnt).direction !== direction && !gateEnt) ||
(name === 'straight-rail' && gateEnt && !strRailEnt && this.bp.entity(gateEnt).direction !== direction && !otherEntities) ||
(name === 'straight-rail' && strRailEnt && !sameDirStrRails && !gateEnt) ||
(name === 'curved-rail' && strRailEnt && !gateEnt) ||
(name === 'straight-rail' && curRailEnt) ||
(name === 'curved-rail' && curRailEnt && this.bp.entity(curRailEnt).direction !== direction)
(name === 'straight_rail' && gateEnt && !strRailEnt && this.bp.entity(gateEnt).direction !== direction && !otherEntities) ||
(name === 'straight_rail' && strRailEnt && !sameDirStrRails && !gateEnt) ||
(name === 'curved_rail' && strRailEnt && !gateEnt) ||
(name === 'straight_rail' && curRailEnt) ||
(name === 'curved_rail' && curRailEnt && this.bp.entity(curRailEnt).direction !== direction)
) return true
return false
@ -232,7 +232,7 @@ export class PositionGrid {
}
checkSameEntityAndDifferentDirection(name: string, direction: number, pos: IPoint) {
if (name === 'straight-rail') return false
if (name === 'straight_rail') return false
const fd = factorioData.getEntity(name)
const size = util.switchSizeBasedOnDirection(fd.size, direction)
const area = new Area({

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 MiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 519 KiB

View File

@ -3,32 +3,32 @@ import factorioData from './factorio-data/factorioData'
const updateGroups = [
{
is: [
'transport-belt',
'fast-transport-belt',
'express-transport-belt',
'transport_belt',
'fast_transport_belt',
'express_transport_belt',
'splitter',
'fast-splitter',
'express-splitter',
'underground-belt',
'fast-underground-belt',
'express-underground-belt'
'fast_splitter',
'express_splitter',
'underground_belt',
'fast_underground_belt',
'express_underground_belt'
],
updates: [
'transport-belt',
'fast-transport-belt',
'express-transport-belt'
'transport_belt',
'fast_transport_belt',
'express_transport_belt'
]
},
{
is: [
'heat-pipe',
'nuclear-reactor',
'heat-exchanger'
'heat_pipe',
'nuclear_reactor',
'heat_exchanger'
],
updates: [
'heat-pipe',
'nuclear-reactor',
'heat-exchanger'
'heat_pipe',
'nuclear_reactor',
'heat_exchanger'
]
},
{
@ -45,14 +45,14 @@ const updateGroups = [
},
{
is: [
'stone-wall',
'stone_wall',
'gate',
'straight-rail'
'straight_rail'
],
updates: [
'stone-wall',
'stone_wall',
'gate',
'straight-rail'
'straight_rail'
]
}
]

View File

@ -142,6 +142,15 @@ function findBPString(data: string) {
}
}
function intToDir(i: number) {
switch (i) {
case 0: return 'north'
case 2: return 'east'
case 4: return 'south'
case 6: return 'west'
}
}
export default {
findBPString,
duplicate,
@ -153,5 +162,6 @@ export default {
duplicateAndSetPropertyUsing,
rotatePointBasedOnDir,
transformConnectionPosition,
switchSizeBasedOnDirection
switchSizeBasedOnDirection,
intToDir
}