Skip to content

Commit

Permalink
Added vertical switches
Browse files Browse the repository at this point in the history
A lot of things were tweaked and the code is a mess...
  • Loading branch information
theRustyKnife committed Oct 27, 2016
1 parent 3aee41f commit 9c2df7d
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 61 deletions.
27 changes: 16 additions & 11 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
##0.1.0##
+ Initial release

##0.1.1##
+ Added proper recipe and tech
+ Added locale
##0.1.5##
+ Added base dependency
+ Allowed rotation and added vertical sprites
* Reversed the order of changelog to prevent unnecessary scrolling

##0.1.2##
* Minor performance improvement
##0.1.4##
+ Added some sprites (bastardized deciders)
* Fixed a crash?

##0.1.3##
* Switches don't emit light when on anymore
* Reduced energy usage to 1kW to match the other combinators
* Performance improvement

##0.1.4##
+ Added some sprites (bastardized deciders)
* Fixed a crash?
##0.1.2##
* Minor performance improvement

##0.1.1##
+ Added proper recipe and tech
+ Added locale

##0.1.0##
+ Initial release
30 changes: 29 additions & 1 deletion data-updates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,32 @@ table.insert(data.raw["technology"]["circuit-network"].effects,
{
type = "unlock-recipe",
recipe = "circuit-network-switch"
})
})

local v_sprite = {
filename = "__circuit-network-switch__/graphics/switch/vertical-off.png",
width = 63,
height = 87,
frame_count = 1,
shift = {0.140625, 0.140625},
}

local h_sprite = {
filename = "__circuit-network-switch__/graphics/switch/horizontal-off.png",
width = 105,
height = 51,
frame_count = 1,
shift = {0.140625, 0.140625},
}

local place_proxy = util.table.deepcopy(data.raw["constant-combinator"]["constant-combinator"])
place_proxy.name = "circuit-network-switch-place-proxy"
place_proxy.sprites = {
north = v_sprite,
east = h_sprite,
south = v_sprite,
west = h_sprite
}
place_proxy.collision_box = {{-0.15, -1.15}, {0.15, 1.15}}

data:extend{place_proxy}
100 changes: 60 additions & 40 deletions data.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
local v_sprite = {
filename = "__circuit-network-switch__/graphics/switch/vertical-off.png",
width = 63,
height = 87,
frame_count = 1,
shift = {0.15, 0},
}
local v_sprite_on = util.table.deepcopy(v_sprite)
v_sprite_on.filename = "__circuit-network-switch__/graphics/switch/vertical-on.png"

local h_sprite = {
filename = "__circuit-network-switch__/graphics/switch/horizontal-off.png",
width = 105,
height = 51,
frame_count = 1,
scale = 0.95,
shift = {0.2, -0.05},
}
local h_sprite_on = util.table.deepcopy(h_sprite)
h_sprite_on.filename = "__circuit-network-switch__/graphics/switch/horizontal-on.png"

data:extend({
--proxies for the wires to be switched
{
Expand Down Expand Up @@ -111,13 +132,13 @@ data:extend({
{
shadow =
{
red = {0.15625, -0.28125},
green = {0.65625, -0.25}
red = {0.21875, -0.1},
green = {0.75, -0.1}
},
wire =
{
red = {-0.28125, -0.5625},
green = {0.21875, -0.5625},
red = {-0.35, -0.1},
green = {0.35, -0.1}
}
},
{
Expand All @@ -140,8 +161,8 @@ data:extend({
},
wire =
{
red = {0.28125, 0.15625},
green = {-0.21875, 0.15625}
red = {0.35, 0.15625},
green = {-0.35, 0.15625}
}
},
{
Expand Down Expand Up @@ -272,13 +293,13 @@ data:extend({
{
shadow =
{
red = {0.15625, -0.28125},
green = {0.65625, -0.25}
red = {0.25, 0},
green = {0.75, 0}
},
wire =
{
red = {-0.28125, -0.5625},
green = {0.21875, -0.5625},
red = {-0.25, -0.1},
green = {0.28125, -0.1},
}
},
{
Expand All @@ -296,13 +317,13 @@ data:extend({
{
shadow =
{
red = {0.75, 0.5625},
green = {0.21875, 0.5625}
red = {0.25, 0.2},
green = {0.75, 0.2}
},
wire =
{
red = {0.28125, 0.15625},
green = {-0.21875, 0.15625}
red = {-0.25, -0.15},
green = {0.28125, -0.15}
}
},
{
Expand All @@ -325,6 +346,7 @@ data:extend({
{
type = "lamp",
name = "circuit-network-switch",
order = "orderman",
icon = "__base__/graphics/icons/arithmetic-combinator.png",
flags = {"placeable-neutral", "player-creation"},
minable = {hardness = 0.2, mining_time = 0.5, result = "circuit-network-switch"},
Expand All @@ -340,30 +362,8 @@ data:extend({
},
energy_usage_per_tick = "1KW",

picture_off =
{
filename = "__circuit-network-switch__/graphics/switch/horizontal-off.png",
priority = "high",
width = 105,
height = 51,
frame_count = 1,
axially_symmetrical = false,
direction_count = 1,
scale = 0.9,
shift = {0.2, -0.1},
},
picture_on =
{
filename = "__circuit-network-switch__/graphics/switch/horizontal-on.png",
priority = "high",
width = 105,
height = 51,
frame_count = 1,
axially_symmetrical = false,
direction_count = 1,
scale = 0.9,
shift = {0.2, -0.1},
},
picture_off = h_sprite,
picture_on = h_sprite_on,

circuit_wire_connection_point =
{
Expand All @@ -387,7 +387,7 @@ data:extend({
flags = {"goes-to-quickbar"},
subgroup = "circuit-network",
order = "a[robot]-b[construction-robot]",
place_result = "circuit-network-switch",
place_result = "circuit-network-switch-place-proxy",
stack_size = 50
},
{
Expand All @@ -401,4 +401,24 @@ data:extend({
},
result = "circuit-network-switch"
},
})
})

local switch_v = util.table.deepcopy(data.raw["lamp"]["circuit-network-switch"])
switch_v.name = switch_v.name .. "-v"
switch_v.collision_box = {{-0.15, -1.15}, {0.15, 1.15}}
switch_v.picture_off = v_sprite
switch_v.picture_on = v_sprite_on
switch_v.circuit_wire_connection_point = {
shadow =
{
red = {0.734375, 0.578125},
green = {0.609375, 0.640625},
},
wire =
{
red = {-0.25, -0.4},
green = {0.25, -0.4},
}
}

data:extend{switch_v}
Binary file added graphics/switch/vertical-off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/switch/vertical-on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions info.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "circuit-network-switch",
"version": "0.1.4",
"version": "0.1.5",
"factorio_version": "0.14",
"title": "Circuit Network Switch",
"author": "TheRustyKnife",
"author": "theRustyKnife",
"description": "Like the power switch but with red and green wires. Now with sprites...",
"homepage": "http://mods.factorio.com/mods/theRustyKnife/circuit-network-switch",
"date": "09.10.2016",
"date": "27.10.2016",
"dependencies": ["base"]
}
3 changes: 3 additions & 0 deletions locale/cs/cs.cfg
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
[entity-description]
circuit-network-switch-proxy=Sem připojte síť
circuit-network-switch=Ovládání přepínače - zde nastavte podmínku
circuit-network-switch-v=Ovládání přepínače - zde nastavte podmínku

[entity-name]
circuit-network-switch-proxy=Proxy Přepínače
circuit-network-switch=Přepínač
circuit-network-switch-v=Přepínač
circuit-network-switch-place-proxy=Přepínač

[item-description]
circuit-network-switch=Umožňuje rozdělit a spojit dvě sítě podle podmínky
Expand Down
3 changes: 3 additions & 0 deletions locale/en/en.cfg
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
[entity-description]
circuit-network-switch-proxy=Connect your network to this
circuit-network-switch=Controls the switch - set your condition here
circuit-network-switch-v=Controls the switch - set your condition here

[entity-name]
circuit-network-switch-proxy=Switch proxy
circuit-network-switch=Circuit Network Switch
circuit-network-switch-v=Circuit Network Switch
circuit-network-switch-place-proxy=Circuit Network Switch

[item-description]
circuit-network-switch=Allows you to split and join two networks based on a circuit condition
Expand Down
27 changes: 22 additions & 5 deletions script/events.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
util = require "util"

function on_built(event)
if event.created_entity.name == "circuit-network-switch"then
if event.created_entity.name == "circuit-network-switch-place-proxy" then
local switch
if event.created_entity.direction % 4 == 0 then --vertical
switch = event.created_entity.surface.create_entity{
name = "circuit-network-switch-v",
position = event.created_entity.position,
force = event.created_entity.force
}
else --horizontal
switch = event.created_entity.surface.create_entity{
name = "circuit-network-switch",
position = event.created_entity.position,
force = event.created_entity.force
}
end

local res = {
switch = event.created_entity,
proxies = util.create_proxies(event.created_entity),
switch = switch,
proxies = util.create_proxies(switch, event.created_entity.direction % 4 == 0),
state = true,
control_behavior = event.created_entity.get_or_create_control_behavior()
control_behavior = switch.get_or_create_control_behavior()
}
table.insert(global.switches, res)

event.created_entity.destroy()
end
end

function on_destroyed(event)
if event.entity.name == "circuit-network-switch" then
if event.entity.name == "circuit-network-switch" or event.entity.name == "circuit-network-switch-v" then
local switch_index = util.find_switch_in_global(event.entity)

util.destroy_proxies(global.switches[switch_index])
Expand Down
11 changes: 10 additions & 1 deletion script/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ function util.destroy_proxies(switch)
end
end

function util.create_proxies(switch)
function util.create_proxies(switch, direction)
if direction then
return {
util.create_proxy(switch, {x = 0, y = 1}, defines.direction.south),
util.create_proxy(switch, {x = 0, y = -1}, defines.direction.north)
}
end
return {
util.create_proxy(switch, {x = 1, y = 0}, defines.direction.west),
util.create_proxy(switch, {x = -1, y = 0}, defines.direction.east)
Expand All @@ -32,6 +38,9 @@ function util.create_proxy(switch, offset, direction)
inner.destructible = false
inner.operable = false
inner.direction = defines.direction.south
if direction == defines.direction.north or direction == defines.direction.south then
inner.direction = defines.direction.north
end

inner.connect_neighbour{target_entity = out, wire = defines.wire_type.red}
inner.connect_neighbour{target_entity = out, wire = defines.wire_type.green}
Expand Down

0 comments on commit 9c2df7d

Please sign in to comment.