diff --git a/mesecons_autotools b/mesecons_autotools deleted file mode 160000 index 700e2e9..0000000 --- a/mesecons_autotools +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 700e2e90b5f3aef873721158c4dd09accf8341b7 diff --git a/mesecons_autotools_tmp/book/circuit.lua b/mesecons_autotools_tmp/book/circuit.lua new file mode 100644 index 0000000..3b8d958 --- /dev/null +++ b/mesecons_autotools_tmp/book/circuit.lua @@ -0,0 +1,405 @@ +dofile(minetest.get_modpath("mesecons_autotools").."/book/mx.lua"); +dofile(minetest.get_modpath("mesecons_autotools").."/book/m3.lua"); + +dofile(minetest.get_modpath("mesecons_autotools").."/book/formspec.lua"); +dofile(minetest.get_modpath("mesecons_autotools").."/book/image.lua"); + +dofile(minetest.get_modpath("mesecons_autotools").."/book/misc.lua"); +dofile(minetest.get_modpath("mesecons_autotools").."/book/stats.lua"); + +local esc = minetest.formspec_escape + + + + +local function show_dialog_new(user,direction) + + local pos1 = mesecons_autotools.get_pos(user,1) + local pos2 = mesecons_autotools.get_pos(user,2) + local sel = {pos1=pos1,pos2=pos2} + + if not mesecons_autotools.is_full_selection(user) then return end + + local nodes = selection_to_m3(pos1,pos2,direction) + local view = m3_to_mx(nodes) + + local db = { + title = "", + text = "", + nodes = nodes, + direction = direction, + view = view, + } + local formspec = fs_all(db) + + minetest.show_formspec(user, "mesecons_autotools:circuit_new", formspec) + +end + + +local function show_dialog_full(user,file) + local info = read_table_from_file(file) + local view = m3_to_mx(info.nodes) + + local db = { + title = info.title, + text = info.text, + nodes = info.nodes, + direction = info.direction, + view = view, + } + + local formspec = fs_all(db) + minetest.show_formspec(user, "mesecons_autotools:circuit_edit", formspec) +end + + + + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= "mesecons_autotools:circuit_new" then return end + + if (fields.save) or fields.key_enter_field == "title" then + + local user = player:get_player_name() + local file = generate_file_name(user) + local rad = player:get_look_horizontal() + local direction = radians_to_direction_looking_forward(rad) + + local stack = player:get_wielded_item() + local inv = player:get_inventory() + + local new_stack = nil + local info = {} + local data = {} + + if( stack:get_name() == "mesecons_autotools:circuit_empty" ) then + + new_stack = ItemStack("mesecons_autotools:circuit_full") + data.file = file + data.description = fields.title + new_stack:get_meta():from_table({ fields = data}) + + if inv:room_for_item("main", new_stack) then + inv:add_item("main", new_stack) + else + minetest.add_item(player:get_pos(), new_stack) + end + + -- standart info + info.title = fields.title + info.text = fields.text + + -- direction + info.direction = direction + + --info.direction = direction + + -- selection + + local pos1 = mesecons_autotools.get_pos(user,1) + local pos2 = mesecons_autotools.get_pos(user,2) + local nodes = selection_to_m3(pos1,pos2,direction) + + + info.nodes = nodes + save_table_to_file(file,info) + end + end + +end) + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= "mesecons_autotools:circuit_edit" then return end + + if (fields.save) or fields.key_enter_field == "title" then + local user = player:get_player_name() + local rad = player:get_look_horizontal() + local direction = radians_to_direction_looking_forward(rad) + + local stack = player:get_wielded_item() + local data = stack:get_meta():to_table().fields + --local inv = player:get_inventory() + + local info = {} + local file = data.file + + --[[ + info = read_table_from_file(file) + info.title = fields.title + info.text = fields.text + save_table_to_file(file,info) + ]]-- + + data.title = fields.title + data.text = fields.text + + + + data.description = fields.title + stack:get_meta():from_table({ fields = data}) + + + + + player:set_wielded_item(stack) + + end +end) + + +function rotate_direction_right(direction) + local d = {x=0,y=0,z=0} + if direction.z == 1 then + d.x = 1 + end + if direction.x == 1 then + d.z = -1 + end + if direction.z == -1 then + d.x = -1 + end + if direction.x == -1 then + d.z = 1 + end + return d +end + +function make_pos2(pos1,direction,sx,sy,sz) + + local right = rotate_direction_right(direction) + + local hv = vector.multiply(direction,sz-1) + local vv = vector.multiply(right,sx-1) + local uv = vector.multiply({x=0,y=1,z=0},sy-1) + local shift = vector.add(hv, vector.add(vv,uv)) + + local pos2 = vector.add(pos1, shift) + + return pos2 +end + +function get_all_corners_flat(sel) + local pos = {} + pos[1] = sel.pos1 + pos[2] = sel.pos2 + + local xmax = math.max(pos[1].x, pos[2].x) + local xmin = math.min(pos[1].x, pos[2].x) + + local ymax = math.max(pos[1].y, pos[2].y) + local ymin = math.min(pos[1].y, pos[2].y) + + local zmax = math.max(pos[1].z, pos[2].z) + local zmin = math.min(pos[1].z, pos[2].z) + + local pos00 = vector.new(xmin,ymin,zmin) + local pos11 = vector.new(xmax,ymin,zmax) + local pos10 = vector.new(xmax,ymin,zmin) + local pos01 = vector.new(xmin,ymin,zmax) + return {pos00=pos00,pos01=pos01,pos10=pos10,pos11=pos11} +end + + + +function get_corner00(sel,direction) + local crs = get_all_corners_flat(sel) + + + + if direction.z == 1 then + return crs.pos00 + end + if direction.x == 1 then + return crs.pos01 + end + if direction.z == -1 then + return crs.pos11 + end + if direction.x == -1 then + return crs.pos10 + end + + +end + +function add_vectors(a,b,c) + return vector.add(a,vector.add(b,c)) +end + + + + +function direction_to_number(direction) + if direction.z == 1 then return 0 end + if direction.x == 1 then return 1 end + if direction.z == -1 then return 2 end + if direction.x == - 1 then return 3 end +end + +function number_to_direction(nr) + if nr == 0 then return {x=0,y=0,z=1} end + if nr == 1 then return {x=1,y=0,z=0} end + if nr == 2 then return {x=0,y=0,z=-1} end + if nr == 3 then return {x=-1,y=0,z=0} end +end + + + + +function diff_directions(d1,d2) + local p1 = direction_to_number(d1) + local p2 = direction_to_number(d2) + + return number_to_direction( (p2-p1+4)%4 ) +end + +function flip(v) + if v == nil then return nil end + return vector.multiply(v,-1) +end + + +function paste_circuit(sel,file,direction) + if sel.pos1 == nil then return end + if sel.pos2 == nil then return end + + local info = read_table_from_file(file) + + --local rotate_direction = diff_directions(direction) + --local nodes = rotate_m3(info.nodes,direction) + local nodes = info.nodes + + + local sx = nodes.sx + local sy = nodes.sy + local sz = nodes.sz + + local right = rotate_direction_right(direction) + + local start_pos = get_corner00(sel,direction) + + for xi=1,sx do + for zi=1,sz do + for yi=1,sy do + local shift= add_vectors( + vector.multiply(right,xi-1), + vector.multiply(direction,zi-1), + vector.multiply({x=0,y=1,z=0},yi-1)) + + local pos = vector.add(start_pos, shift) + + if is_in_selection(sel,pos) then + + local node = m3_get(nodes,xi,yi,zi) + node = rotate_node(node,{x=0,y=0,z=1},direction) + --minetest.set_node(pos, node) + mesecons_autotools.set_node(pos,node,"paste_circuit") + end + + end + + end + end +end + + + +local function make_selection(user,file,direction,pos) + local info = read_table_from_file(file) + --local rotate_direction = diff_directions(info.direction,direction) + local rotate_direction= info.direction + + local nodes = info.nodes + local sx = nodes.sx + local sy = nodes.sy + local sz = nodes.sz + + + local pos2 = make_pos2(pos,direction,sx,sy,sz) + + -- Update + mesecons_autotools.set_pos(user,1,pos) + mesecons_autotools.set_pos(user,2,pos2) + mesecons_autotools.render(user) + mesecons_autotools.zero_stack_counter(user) + mesecons_autotools.zero_stack_direction(user) +end + +local function on_place_full_circuit(itemstack, player, pointed_thing) + local user = player:get_player_name() + local rad = player:get_look_horizontal() + local direction = radians_to_direction_looking_forward(rad) + local fields = itemstack:get_meta():to_table().fields + local file = fields.file + + if not mesecons_autotools.is_full_selection(user) then return nil end + local pos1 = mesecons_autotools.get_pos(user,1) + local pos2 = mesecons_autotools.get_pos(user,2) + local sel = {pos1=pos1,pos2=pos2} + paste_circuit(sel,file,direction) + +end + + +local function on_use_new_circuit(itemstack, player, pointed_thing) + local user = player:get_player_name() + local rad = player:get_look_horizontal() + local direction = radians_to_direction_looking_forward(rad) + + if not mesecons_autotools.is_full_selection(user) then + -- show dialog with info or chat info + return + end + show_dialog_new(user,direction) + + return nil +end + +local function on_use_full_circuit(itemstack, player, pointed_thing) + local user = player:get_player_name() + local rad = player:get_look_horizontal() + local direction = radians_to_direction_looking_forward(rad) + local fields = itemstack:get_meta():to_table().fields + local file = fields.file + + + if( pointed_thing.type == "node" ) then + make_selection(user,file,direction,pointed_thing.above) + else + show_dialog_full(user,file,player) + end + + return nil +end + +local function none(itemstack, player, pointed_thing) + return nil +end + + + +--minetest.register_craftitem("mesecons_autotools:circuit_empty", { +minetest.register_tool("mesecons_autotools:circuit_empty", { + description = "Circuit Empty", + inventory_image = "circuit_empty.png", + stack_max = 1, + + on_use = on_use_new_circuit, + on_place = none, + on_secondary_use = none, + + }) + +--minetest.register_craftitem("mesecons_autotools:circuit_full", { +minetest.register_tool("mesecons_autotools:circuit_full", { + description = "Circuit saved", + inventory_image = "circuit_full.png", + groups = {not_in_creative_inventory = 1}, + stack_max = 1, + on_use = on_use_full_circuit, + on_place = on_place_full_circuit, + --on_secondary_use = on_place_full_circuit, + + + }) diff --git a/mesecons_autotools_tmp/book/file.lua b/mesecons_autotools_tmp/book/file.lua new file mode 100644 index 0000000..7c4ac1c --- /dev/null +++ b/mesecons_autotools_tmp/book/file.lua @@ -0,0 +1,47 @@ +mesecons_autotools.rand = PcgRandom(2); + + +function generate_file_name(user) + local days = minetest.get_day_count() + local sec = minetest.get_gametime() + local rand = math.abs(mesecons_autotools.rand:next()) + local file = "circuit-"..user.."-"..sec.."-" .. rand + return file +end + +local path = minetest.get_worldpath() .. "/circuits/" + +function save_table_to_file(filename,tab) + minetest.mkdir(path) + local file, err = io.open(path .. filename, "wb") + if err ~= nil then + -- player_notify(name, "Could not save file to \"" .. filename .. "\"") + print ("mesecons_autotools: ERROR: file save error") + return + end + local result = minetest.serialize(tab) + + file:write(result) + file:flush() + file:close() +end + + +function read_table_from_file(filename) + minetest.mkdir(path) + local file, err = io.open(path .. filename, "rb") + if err ~= nil then + -- notify + print ("mesecons_autotools: ERROR: file read error") + return nil + end + + local value = file:read("*a") + file:close() + + local tab = minetest.deserialize(value) + return tab +end + + + diff --git a/mesecons_autotools_tmp/book/formspec.lua b/mesecons_autotools_tmp/book/formspec.lua new file mode 100644 index 0000000..64e0df1 --- /dev/null +++ b/mesecons_autotools_tmp/book/formspec.lua @@ -0,0 +1,88 @@ +local esc = minetest.formspec_escape + +function fs_all(db) + local info = fs_info(db.title,db.text,db) + local stats = fs_stats(db.nodes, db.direction) + local circuit = fs_circuit(db.view) + + local spec = info .. stats .. circuit + return spec +end + + + +function fs_info(title,text) + local formspec = + "formspec_version[3]".. + "size[32,25]".. + "field[0.5,1;8,1;title;".."Name"..";"..esc(title).."]".. + "label[15,0.7;Circuit Preview]".. + "textarea[0.5,3;8,15;text;" .. "Description:" .. ";" .. + esc(text) .. "]" .. + "button_exit[2.5,18;3,1;save;" .. "Save" .. "]" + + return formspec +end + + +function fs_circuit(mx_view) + local W = 20 + local H = 20 + local startx = 10 + local starty = 2 + + local imagew = W/(mx_view.w) + local imageh = H/(mx_view.h) + + if imageh > 1 then imageh = 1 end + if imagew > 1 then imagew = 1 end + + local minsize = math.min(imageh,imagew) + imageh = minsize + imagew = minsize + + local epsilon = 0.07 + + + local spec = "" + for ix=1,mx_view.w do + for iy=1,mx_view.h do + local n = mx_get(mx_view,ix,iy) + if n == nil then n = {name="air",param2=0} end + local img = node_to_image( n ) + + + spec = spec .. "image[".. + startx+ix*imagew .. "," .. + starty+(mx_view.h-iy+1)*imageh .. ";" .. + imagew +epsilon .. "," .. + imageh +epsilon .. ";" .. + img .. "]" + + end + end + + return spec + +end + +function fs_stats(nodes,direction) + local block, gate, wire = get_stats(nodes) + + + + + local sx = nodes.sx + local sy = nodes.sy + local sz = nodes.sz + + local stats = "size : " .. sx .. "x"..sy .. "x"..sz .. "(=".. sx*sy*sz .. ")\n" .. + "wires : " .. wire .. "\n" .. + "gates : " .. gate .. "\n" .. + "others : ".. block - wire - gate .. "\n" .. + "blocks: " .. block + local spec = "textarea[0.5,19;8,5;;;" .. esc(stats) .. "]" + return spec +end + + diff --git a/mesecons_autotools_tmp/book/image.lua b/mesecons_autotools_tmp/book/image.lua new file mode 100644 index 0000000..bded875 --- /dev/null +++ b/mesecons_autotools_tmp/book/image.lua @@ -0,0 +1,125 @@ + + +function node_to_image(node) + if node == nil then + return "empty.png" + end + + local name = node.name + local param2 = node.param2 or 0 + + + if( name == "air" ) then + return "empty.png" + end + + + if (name == "mesecons_insulated:insulated_off") or + (name == "mesecons_insulated:insulated_on" ) then + if( param2 % 2 == 0 ) then + return "wireh.png" + else + return "wirev.png" + end + end + + if (name == "mesecons_extrawires:crossover_off") or + (name == "mesecons_extrawires:crossover_on") or + (name == "mesecons_extrawires:crossover_01") or + (name == "mesecons_extrawires:crossover_10" ) then + return "corssover.png" + end + + if (name == "mesecons_extrawires:corner_off" ) or + (name == "mesecons_extrawires:corner_on" ) then + + return "corner"..param2 .. ".png" + end + + if (name == "mesecons_extrawires:tjunction_off" ) or + (name == "mesecons_extrawires:tjunction_on" ) then + + return "tjunction"..param2 .. ".png" + end + + if ( name == "mesecons_morewires:xjunction_off" ) or + ( name == "mesecons_morewires:xjunction_on" ) then + return "xjunction.png" + end + + + if( name == "mesecons_regs:flipflop_off" ) or ( name == "mesecons_regs:flipflop_on") then + return "ff"..param2..".png" + end + if( name == "mesecons_regs:latch_off" ) or ( name == "mesecons_regs:latch_on") then + return "latch"..param2..".png" + end + + + if( name == "mesecons_gates:and_off" ) or ( name =="mesecons_gates:and_on" )then + return "and".. param2 .. ".png" + end + if( name == "mesecons_gates:nand_off" ) or ( name =="mesecons_gates:nand_on" )then + return "nand".. param2 .. ".png" + end + + if( name == "mesecons_gates:nor_off" ) or ( name =="mesecons_gates:nor_on" )then + return "nor".. param2 .. ".png" + end + if( name == "mesecons_gates:or_off" ) or ( name =="mesecons_gates:or_on" )then + return "or".. param2 .. ".png" + end + if( name == "mesecons_gates:xor_off" ) or ( name =="mesecons_gates:xor_on" )then + return "xor".. param2 .. ".png" + end + + + if( name == "mesecons_gates:diode_off" ) or ( name =="mesecons_gates:diode_on" )then + return "diode".. param2 .. ".png" + end + + if( name == "mesecons_gates:not_off" ) or ( name =="mesecons_gates:not_on" )then + return "not".. param2 .. ".png" + end + + if( name == "mesecons_switch:mesecon_switch_off" ) or ( name =="mesecons_switch:mesecon_switch_on" )then + return "mesecons_switch_off.png" + end + + if ( name == "mesecons_lightstone:lightstone_white_off" ) or ( name == "mesecons_lightstone:lightstone_white_on" ) then + return "jeija_lightstone_white_on.png" + end + + if (name == "mesecons_walllever:wall_lever_off" ) or (name == "mesecons_walllever:wall_lever_on" ) then + + return "jeija_wall_lever_inv.png" + end + + if (name == "default:mese" ) or (name == "mesecons_extrawires:mese_powered" )then + return "default_mese_block.png" + end + + if (name == "mesecons_powerplant:power_plant") then + return "jeija_power_plant.png" + end + + + if (name == "mesecons_gates3:and3_off") or (name == "mesecons_gates3:and3_on" ) then + return "jeija_gate3_and3r"..param2..".png" + end + + + if (name == "mesecons_gates3:nand3_off") or (name == "mesecons_gates3:nand3_on" ) then + return "jeija_gate3_nand3r"..param2..".png" + end + + if (name == "mesecons_gates3:or3_off") or (name == "mesecons_gates3:or3_on" ) then + return "jeija_gate3_or3r"..param2..".png" + end + + if (name == "mesecons_gates3:nor3_off") or (name == "mesecons_gates3:nor3_on" ) then + return "jeija_gate3_nor3r"..param2..".png" + end + + return "unknown.png" +end diff --git a/mesecons_autotools_tmp/book/library.lua b/mesecons_autotools_tmp/book/library.lua new file mode 100644 index 0000000..507fdca --- /dev/null +++ b/mesecons_autotools_tmp/book/library.lua @@ -0,0 +1,220 @@ + + + +function render_circuit(circ,start_x,start_y) + circ.title = circ.title or "" + local spec = "button["..start_x..","..start_y..";10,1;".. "title_" .. circ.id .. ";"..circ.title.."]" + return spec,1 +end + + +function f_fold(id,x,y,folded) + local fold_sign + if folded == true then + fold_sign = "+" + else + fold_sign = "-" + end + + local spec = "button["..x..","..y..";1,1;".. "fold_" .. id ..";".. fold_sign.."]" + + return spec, 1, 0 +end + + +function render_lib(lib,start_x,start_y) + local xshift = 1 + local yshift = 1 + local total_yshift = 0 + local total_xshift = 0 + local id = lib.id + + lib.title = lib.title or "" + lib.folded = lib.folded or false + + + local spec = "" + + -- fold button + local ss,shx,shy = f_fold(id,start_x+total_xshift, start_y+total_yshift, lib.folded) + total_xshift = total_xshift+shx + total_yshift = total_yshift+shy + spec = spec .. ss + + + spec = spec .. + "button[".. start_x + total_xshift ..",".. start_y + total_yshift.. + ";10,1;".. "title_"..lib.id .. ";"..lib.title.."]" + total_xshift = start_x + 1 + total_yshift = total_yshift+1 + + + + + if lib.folded == false then + for _,v in ipairs(lib.list) do + if v.type == "library" then + local sp, ys = render_lib(v, start_x+total_xshift, start_y+total_yshift) + spec = spec .. sp + total_yshift = total_yshift + ys + elseif v.type == "circuit" then + local sp, ys = render_circuit(v,start_x+total_xshift, start_y+total_yshift) + spec = spec .. sp + total_yshift = total_yshift + ys + end + + end + end + + return spec, total_yshift + +end + +function traverse_list(list,action) + if list == nil then return end + + for _,v in ipairs(list) do + print("traverser.id =" .. v.id) + if v.type == "circuit" then + action(v) + elseif v.type == "library" then + action(v) + traverse_list(v.list,action) + end + + end + + +end + +function foreach_id(list,action) + if list == nil then return end + traverse_list(list, function(elem) + action(elem.id) + end) +end + +function get_elem_by_id(list,id) + local found + traverse_list(list,function(e) + if e.id == id then + found = e + end + + end) + return found +end + + + + + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= "mesecons_autotools:library_view" then return end + --print ("RECEIVE:=player="..dump(player) .. ", formname="..formname .. ".fiels="..dump(fields)) + local user = player:get_player_name() + local stack = player:get_wielded_item() + local data = stack:get_meta():to_table().fields + local lib = data.lib + + + print("lib="..dump(lib)) + if fields.quit then return end + --if lib == nil then return end + + -- print("DB2: " .. dump(data)) + -- print("FIELDS:"..dump(fields)) + + + + lib = lib or {} + -- print ("lib="..dump(lib)) + traverse_list(lib.list,function(elem) + print("#") + if fields["fold_".. elem.id] == true then + elem.folded = not elem.folded + end + end) + + -- print("libafger="..dump(lib)) + --[[ + if (fields.save) or fields.key_enter_field == "title" then + ]]-- + data.lib = lib + stack:get_meta():from_table({ fields = data}) + player:set_wielded_item(stack) + + local formspec = render_formspec(lib) + minetest.show_formspec(user, "mesecons_autotools:library_view", formspec) + +end) + +function render_formspec(lib) + local formspec = "formspec_version[3]".. + "size[32,25]" + + formspec = formspec .. render_lib(lib,1,1) + return formspec +end + + + lib = { + id = "l1", + title = "library bla bla ", + type = "library", + list = { + {id = "c1", type="circuit", title="somethign something"}, + {id = "c2", type="circuit", title="somethign something2"}, + {id = "l2", type="library", title="wooihoihoh/", folded = false, + list = { + {id = "c11", type="circuit", title="somethign something"}, + {id = "c21", type="circuit", title="somethign something2"}, + } + + }, + {id = "c111", type="circuit", title="circuit sak/32/d0"}, + } + } + + +function on_place_library(itemstack, player, pointed_thing) + local user = player:get_player_name() + local stack = player:get_wielded_item() + local data = stack:get_meta():to_table().fields + + + print("DU:"..dump(itemstack:get_meta():to_table())) + print("item stackc:" .. dump(itemstack)) + + if data.count == nil then data.count = 0 end + data.count = data.count + 1 + + + stack:get_meta():from_table({ fields = data}) + player:set_wielded_item(stack) + + + local formspec = render_formspec(lib) + -- print("formtspec="..formspec) + + + minetest.show_formspec(user, "mesecons_autotools:library_view", formspec) + +end + + + +minetest.register_tool("mesecons_autotools:library", { + description = "Library of Circuits", + inventory_image = "library.png", + stack_max = 1, + + + on_place = on_place_library, +--[[ + on_use = on_use_new_circuit, + + on_secondary_use = none, + ]]-- + }) + \ No newline at end of file diff --git a/mesecons_autotools_tmp/book/m3.lua b/mesecons_autotools_tmp/book/m3.lua new file mode 100644 index 0000000..cda6c53 --- /dev/null +++ b/mesecons_autotools_tmp/book/m3.lua @@ -0,0 +1,271 @@ + + +function m3_get(m,x,y,z) + if m == nil then return nil end + if m[x] == nil then return nil end + if m[x][y] == nil then return nil end + if m[x][y][z] == nil then return nil end + return m[x][y][z] +end + +function m3_set(m,x,y,z,value) + if m == nil then m = {} end + if m[x] == nil then m[x] = {} end + if m[x][y] == nil then m[x][y] = {} end + if m[x][y][z] == nil then m[x][y][z] = {} end + m[x][y][z] = value +end +--[[ +function m3_set_pos(m,pos1,pos2) + m.pos1 = pos1 + m.pos2 = pos2 +end +]]-- + +function m3_flip_xy(m) + local new_m = {} + for ix=1,m.sx do + for iz=1,m.sz do + for iy=1,m.sy do + m3_set(new_m,iz,iy,ix, m3_get(m,ix,iy,iz)) + end + end + end + --[[ + -- Rotate node + for ix=1,m.sx do + for iz=1,m.sz do + for iy=1,m.sy do + local node = m3_get(m,ix,iy,iz) + + local rotated_node = + rotate_node_to_direction(node,{x=1,y=0,z=0}) + m3_set(m,ix,iy,iz,rotated_node) + end + end + end + ]]-- + new_m.sx = m.sz + new_m.sz = m.sx + new_m.sy = m.sy + return new_m +end + +function m3_flip_x(m) + local new_m = {} + for ix=1,m.sx do + for iz=1,m.sz do + for iy=1,m.sy do + m3_set(new_m,ix,iy,m.sz-iz+1, m3_get(m,ix,iy,iz)) + end + end + end + + --[[ + for ix=1,m.sx do + for iz=1,m.sz do + for iy=1,m.sy do + local node = m3_get(m,ix,iy,iz) + + local rotated_node = + rotate_node_to_direction(node,{x=0,y=0,z=-1}) + m3_set(m,ix,iy,iz,rotated_node) + end + end + end + +]]-- + new_m.sx = m.sx + new_m.sz = m.sz + new_m.sy = m.sy + return new_m +end + + +function m3_rotate90(m) + return m3_flip_x( m3_flip_xy (m)) +end + +function m3_rotate180(m) + return m3_rotate90(m3_rotate90(m)) +end + +function m3_rotate270(m) + return m3_rotate90(m3_rotate90(m3_rotate90(m))) +end + +function rotate_m3(m,direction) + + if direction.x == 1 then + return m3_rotate270(m) + end + if direction.x == -1 then + return m3_rotate90(m) + end + if direction.z == 1 then + return m + end + if direction.z == -1 then + return m3_rotate180(m) + end + return m +end + + + +function m3_move_to_000(m) + local new_m = {} + + local pos1 = m.pos1 + local pos2 = m.pos2 + + local xmin = math.min(pos1.x,pos2.x) + local ymin = math.min(pos1.y,pos2.y) + local zmin = math.min(pos1.z,pos2.z) + + local xmax = math.max(pos1.x,pos2.x) + local ymax = math.max(pos1.y,pos2.y) + local zmax = math.max(pos1.z,pos2.z) + + + + local sx = xmax - xmin + 1 + local sy = ymax - ymin + 1 + local sz = zmax - zmin + 1 + + for x=1,sx,1 do + for y=1,sy,1 do + for z=1,sz,1 do + m3_set(new_m,x,y,z, + m3_get(m, x-1 + xmin, y-1 + ymin, z-1+zmin)) + end + end + end + + new_m.sx = sx + new_m.sy = sy + new_m.sz = sz + return new_m +end + + + + + +function selection_to_m3(pos1,pos2,direction) + local m = {} + iterate_selection(pos1,pos2,function(pos) + local node = minetest.get_node(pos) + m3_set(m,pos.x,pos.y,pos.z,node) + end) + m.pos1 = pos1 + m.pos2 = pos2 + + m = m3_move_to_000(m) + + m = rotate_m3(m,direction) + + for ix=1,m.sx do + for iz=1,m.sz do + for iy=m.sy,1,-1 do + local node = m3_get(m,ix,iy,iz) + local rotated_node = rotate_node_to_direction(node,direction) + m3_set(m,ix,iy,iz,rotated_node) + end + end + end + + + + return m +end + + +function m3_to_mx(m) + local mx={} + for ix=1,m.sx do + for iz=1,m.sz do + for iy=m.sy,1,-1 do + local pos = { x = ix, y=iy, z = iz } + local node = m3_get(m,ix,iy,iz) + + if node.name ~= "air" then + mx_set(mx,ix,iz,node) + break + end + + end + end + end + mx.w = m.sx + mx.h = m.sz + return mx +end + + +local function lmin(a,b) + if a == nil then + return b + else + if b == nil then + return a + else + return math.min(a,b) + end + end +end +local function lmax(a,b) + if a == nil then + return b + else + if b == nil then + return a + else + return math.max(a,b) + end + end +end + +function list_to_m3(list) + local m = {} + + local xmin,xmax,ymin,ymax,zmin,zmax + + for _,v in pairs(list) do + local pos = v.pos + local node = v.node + + m3_set(m,pos.x,pos.y,pos.z, node) + + xmin = lmin(xmin, pos.x) + ymin = lmin(ymin, pos.y) + zmin = lmin(zmin, pos.z) + + xmax = lmax(xmax, pos.x) + ymax = lmax(ymax, pos.y) + zmax = lmax(zmax, pos.z) + + + end + + m.pos1 = {x=xmin,y=ymin,z=zmin} + m.pos2 = {x=xmax,y=ymax,z=zmax} + return m +end + + +function iterate_m3(m,action) + for x=1,m.sx do + for y=1,m.sy do + for z=1,m.sz do + action(m3_get(m,x,y,z)) + end + end + end +end + + + + + + diff --git a/mesecons_autotools_tmp/book/misc.lua b/mesecons_autotools_tmp/book/misc.lua new file mode 100644 index 0000000..beeec48 --- /dev/null +++ b/mesecons_autotools_tmp/book/misc.lua @@ -0,0 +1,48 @@ +function rotate_node_to_direction(node,direction) + local add = 0 + if direction.x == 1 then add = 3 end + if direction.x == -1 then add = 1 end + if direction.z == 1 then add = 0 end + if direction.z == -1 then add = 2 end + + local param2 = node.param2 + + param2 = (param2+add)% 4 + + return { name = node.name , param2 = param2 } +end + +local function direction_to_number(direction) + if( direction.z == 1 ) then + return 1 + elseif( direction.x == 1 ) then + return 2 + elseif(direction.z == -1 )then + return 3 + else + return 4 + end + +end + + + +function rotate_node(node, saved_direction,direction) + + local values = + { + {0,1,2,3}, + {3,0,1,2}, + {2,3,0,1}, + {1,2,3,0} + } + + local rotate = + values[direction_to_number(saved_direction)][direction_to_number(direction)] + + local new_node = {} + new_node.name = node.name + new_node.param2 = (node.param2+rotate)%4 + + return new_node +end diff --git a/mesecons_autotools_tmp/book/mx.lua b/mesecons_autotools_tmp/book/mx.lua new file mode 100644 index 0000000..876d6e9 --- /dev/null +++ b/mesecons_autotools_tmp/book/mx.lua @@ -0,0 +1,109 @@ + + +function mx_get(m,x,y) + if m == nil then return nil end + if m[x] == nil then return nil end + if m[x][y] == nil then return nil end + return m[x][y] +end + +function mx_set(m,x,y,value) + if m == nil then m = {} end + if m[x] == nil then m[x] = {} end + if m[x][y] == nil then m[x][y] = {} end + m[x][y] = value +end + +function mx_flip_xy(m) + local new_m = {} + for i=1,m.w do + for k=1,m.h do + mx_set(new_m,k,i, mx_get(m,i,k)) + end + end + new_m.h = m.w + new_m.w = m.h + return new_m +end + +function mx_flip_y(m) + local new_m = {} + for i=1,m.w do + for k=1,m.h do + mx_set(new_m,m.w+1-i,k, mx_get(m,i,k)) + end + end + new_m.h = m.h + new_m.w = m.w + return new_m +end + +function mx_flip_x(m) + local new_m = {} + for i=1,m.w do + for k=1,m.h do + mx_set(new_m,i,m.h+1-k, mx_get(m,i,k)) + end + end + new_m.h = m.h + new_m.w = m.w + return new_m +end + + +function mx_rotate90(m) + return mx_flip_x( mx_flip_xy (m)) +end + +function mx_rotate180(m) + return mx_rotate90(mx_rotate90(m)) +end + +function mx_rotate270(m) + return mx_rotate90(mx_rotate90(mx_rotate90(m))) +end + +function rotate_mx(mx,direction) + + if direction.x == 1 then + return mx_rotate270(mx) + end + if direction.x == -1 then + return mx_rotate90(mx) + end + if direction.z == 1 then + return mx + end + if direction.z == -1 then + return mx_rotate180(mx) + end + return mx +end + + + +function move_mx_to_00(mx) + local new_mx = {} + + local xmax = mx.xmax + local xmin = mx.xmin + + local ymax = mx.ymax + local ymin = mx.ymin + + + local sx = xmax - xmin + 1 + local sy = ymax - ymin + 1 + + for x=1,sx,1 do + for y=1,sy,1 do + mx_set(new_mx,x,y, mx_get(mx, x-1 + xmin, y-1 + ymin)) + end + end + + new_mx.w = sx + new_mx.h = sy + return new_mx + +end + diff --git a/mesecons_autotools_tmp/book/stats.lua b/mesecons_autotools_tmp/book/stats.lua new file mode 100644 index 0000000..5196548 --- /dev/null +++ b/mesecons_autotools_tmp/book/stats.lua @@ -0,0 +1,71 @@ +function is_gate(node) + local gates = { + "mesecons_gates:and", + "mesecons_gates:or", + "mesecons_gates:xor", + "mesecons_gates:nand", + "mesecons_gates:nor", + "mesecons_gates:not", + "mesecons_gates:diode", + "mesecons_gates3:and3", + "mesecons_gates3:or3", + "mesecons_gates3:nor3", + "mesecons_gates3:nand3", + "mesecons_regs:flipflop", + "mesecons_regs:latch" + } + + local gates_with_states = {} + for _,v in ipairs(gates) do + table.insert(gates_with_states,v.."_on") + table.insert(gates_with_states,v.."_off") + end + + for _,v in ipairs(gates_with_states) do + if node.name == v then + return true + end + end + return false +end + +function is_wire_node(node) + local list = { + "mesecons_insulated:insulated_off", "mesecons_insulated:insulated_on", + "mesecons_extrawires:corner_off", "mesecons_extrawires:corner_on", + "mesecons_extrawires:tjunction_off", "mesecons_extrawires:tjunction_on", + "mesecons_extrawires:crossover_off", "mesecons_extrawires:crossover_on", + "mesecons_extrawires:crossover_10", "mesecons_extrawires:crossover_01", + "mesecons_morewires:xjunction_off", "mesecons_morewires:xjunction_on", + } + + local pos_name = node.name + for i,name in ipairs(list) do + if name == pos_name then + return true + end + end + return false +end + + + + +function get_stats(m) + local blocks,gates,wires = 0,0,0 + iterate_m3(m, function(node) + if is_wire_node(node) then + wires = wires + 1 + end + if is_gate(node) then + gates = gates+1 + end + if node.name ~= "air" then + blocks = blocks + 1 + end + + end) + + return blocks,gates,wires + +end diff --git a/mesecons_autotools_tmp/commands/all_commands.lua b/mesecons_autotools_tmp/commands/all_commands.lua new file mode 100644 index 0000000..e69de29 diff --git a/mesecons_autotools_tmp/debug.lua b/mesecons_autotools_tmp/debug.lua new file mode 100644 index 0000000..221f67c --- /dev/null +++ b/mesecons_autotools_tmp/debug.lua @@ -0,0 +1,16 @@ + +-- Debug + +function dump(o) + if type(o) == 'table' then + local s = '{ ' + for k,v in pairs(o) do + if type(k) ~= 'number' then k = '"'..k..'"' end + s = s .. '['..k..'] = ' .. dump(v) .. ',' + end + return s .. '} ' + else + return tostring(o) + end +end + diff --git a/mesecons_autotools_tmp/init.lua b/mesecons_autotools_tmp/init.lua new file mode 100644 index 0000000..a9bff3f --- /dev/null +++ b/mesecons_autotools_tmp/init.lua @@ -0,0 +1,353 @@ +dofile(minetest.get_modpath("mesecons_autotools").."/debug.lua"); + + +mesecons_autotools = {} +mesecons_autotools.users = {} +mesecons_autotools.actions = {} + + +-- Basic functions + +--[[ +mesecons_autotools = +{ + user_name = { + pos[1..2] = { x = number, y = number, z = number} + stack_direction = {x,y,z} + stack_counter = number + entities = + options = { + option1 = value1 + option2 = value2 + } + } + + user_name = ... +]]-- + +mesecons_autotools.set_pos = function(user,nr,pos) + if mesecons_autotools.users[user] == nil then + mesecons_autotools.users[user] = {} + end + if mesecons_autotools.users[user].pos == nil then + mesecons_autotools.users[user].pos = {} + end + if pos == nil then + mesecons_autotools.users[user].pos[nr] = nil + else + local p = vector.new(pos) + mesecons_autotools.users[user].pos[nr] = p + end +end + +mesecons_autotools.get_pos = function(user,nr) + if mesecons_autotools.users[user] == nil then + return nil + end + if mesecons_autotools.users[user].pos == nil then + return nil + end + if mesecons_autotools.users[user].pos[nr] == nil then + return nil + else + return vector.new(mesecons_autotools.users[user].pos[nr]) + end + + +end + +mesecons_autotools.get_stack_counter = function(user) + if mesecons_autotools.users[user] == nil then + mesecons_autotools.users[user] = {} + end + + if mesecons_autotools.users[user].stack_counter == nil then + mesecons_autotools.users[user].stack_counter = 0 + end + + return mesecons_autotools.users[user].stack_counter +end + +mesecons_autotools.inc_stack_counter = function(user) + -- get value and create structure if needed + local count = mesecons_autotools.get_stack_counter(user) + mesecons_autotools.users[user].stack_counter = count + 1 +end + +mesecons_autotools.dec_stack_counter = function(user) + -- get value and create structure if needed + local count = mesecons_autotools.get_stack_counter(user) + if count == 0 then return end + mesecons_autotools.users[user].stack_counter = count - 1 +end + +mesecons_autotools.zero_stack_counter = function(user) + -- get value and create structure if needed + local count = mesecons_autotools.get_stack_counter(user) + mesecons_autotools.users[user].stack_counter = 0 +end + +mesecons_autotools.zero_stack_direction = function(user) + if mesecons_autotools.users[user] == nil then + mesecons_autotools.users[user] = {} + end + mesecons_autotools.users[user].stack_direction = { x = 0, y = 0, z =0 } +end + +mesecons_autotools.set_stack_direction = function(user,direction) + -- get rid of nils + mesecons_autotools.zero_stack_direction(user) + mesecons_autotools.users[user].stack_direction = direction +end + +mesecons_autotools.get_stack_direction = function(user) + if mesecons_autotools.users[user] == nil then + mesecons_autotools.users[user] = {} + end + if mesecons_autotools.users[user].stack_direction == nil then + mesecons_autotools.users[user].stack_direction = { x = 0, y = 0, z =0 } + end + return mesecons_autotools.users[user].stack_direction +end + + +mesecons_autotools.set_option = function(user,field,value) + if mesecons_autotools.users[user] == nil then + mesecons_autotools.users[user] = {} + end + if mesecons_autotools.users[user].options == nil then + mesecons_autotools.users[user].options = {} + end + mesecons_autotools.users[user].options[field] = value +end + +mesecons_autotools.get_option = function(user,field) + if mesecons_autotools.users[user] == nil then + return nil + end + if mesecons_autotools.users[user].options == nil then + return nil + end + return mesecons_autotools.users[user].options[field] +end + +mesecons_autotools.is_full_selection = function(user) + if mesecons_autotools.get_pos(user,1) == nil then return false end + if mesecons_autotools.get_pos(user,2) == nil then return false end + return true +end + + +-- Actions/Callbacks ('user' clicked 'button' on 'pos' using 'tool') + +-- button = "left" | "right" +-- pos = { x = number, y = number, z = number } +-- tool = "black" | "red" | ... +-- type = "air" | "block" + +mesecons_autotools.execute_action = function(tool,button,type,user,pos,rad,under) +-- if user == nil then return end +-- if pos == nil then return end + if tool == nil then return end + if button == nil then return end + if type == nil then return end + if rad == nil then return end + -- under == nil can be nil + + if mesecons_autotools.actions[tool] == nil then return end + if mesecons_autotools.actions[tool][button] == nil then return end + if mesecons_autotools.actions[tool][button][type] == nil then return end + + + mesecons_autotools.actions[tool][button][type](user,pos,rad,under) + +end + + + +mesecons_autotools.register_action = function(tool,button,type,action) + if mesecons_autotools.actions[tool] == nil then + mesecons_autotools.actions[tool] = {} + end + if mesecons_autotools.actions[tool][button] == nil then + mesecons_autotools.actions[tool][button] = {} + end + if mesecons_autotools.actions[tool][button][type] == nil then + mesecons_autotools.actions[tool][button][type] = {} + end + mesecons_autotools.actions[tool][button][type] = action +end + + +function is_in_list(list,value) + + for _,v in ipairs(list) do + if v == value then return true end + + end + return false + +end + + + function ref_place(pos,node) + if minetest.get_item_group(node.name, "mesecon_needs_receiver") == 1 then + mesecon.receiver_place(pos) + end + end + + function ref_remove(pos,node) + if minetest.get_item_group(node.name, "mesecon_needs_receiver") == 1 then + mesecon.receiver_remove(pos) + end + end + + + + +mesecons_autotools.set_node = function(pos,node,why) + --[[ + if node.name == "air" then + local n = minetest.get_node(pos) + mesecon.on_dignode(pos,n) + ref_remove(pos,n) + minetest.set_node(pos,node) + -- ref_place ??? + else + local n = minetest.get_node(pos) + mesecon.on_dignode(pos,n) + ref_remove(pos,n) + minetest.set_node(pos,node) + mesecon.on_placenode(pos,node) + ref_place(pos,node) + end + + if true then return end + + local n = minetest.get_node(pos) + mesecon.on_dignode(pos,n) + ref_remove(pos,n) + + minetest.set_node(pos,node) + mesecon.on_placenode(pos,node) + ref_place(pos,node) + + + if true then return end + ]]-- + + + if why == nil then + minetest.set_node(pos,node) + else + + + if is_in_list({"start_node","middle_node"},why) then + minetest.set_node(pos,node) + mesecon.on_placenode(pos,node) + ref_place(pos,node) + end + + + + + + if is_in_list({"delete"},why) then + local n = minetest.get_node(pos) + mesecon.on_dignode(pos,n) + ref_remove(pos,n) + + minetest.set_node(pos,node) + mesecon.on_placenode(pos,node) + ref_place(pos,node) + + end + + + if is_in_list({"delete_crossover","delete_end"},why) then -- + local n = minetest.get_node(pos) + mesecon.on_dignode(pos,n) + ref_remove(pos,n) + + minetest.set_node(pos,node) + mesecon.on_placenode(pos,node) + ref_place(pos,node) + + + + end + + if is_in_list({"paste_circuit"},why) then + minetest.set_node(pos,node) + end + + if is_in_list({"add_wire"},why) then + minetest.set_node(pos,node) + end + + if is_in_list({"red"},why) then + local n = minetest.get_node(pos) + mesecon.on_dignode(pos,n) + ref_remove(pos,n) + + minetest.set_node(pos,node) + mesecon.on_placenode(pos,node) + ref_place(pos,node) + + end + + if is_in_list({"put_tail_wires"},why) then + minetest.set_node(pos,node) + end + + if is_in_list({"copy"},why) then + minetest.set_node(pos,node) + end + + if is_in_list({"paste_from_buffor"},why) then + minetest.set_node(pos,node) + end + + --[[ + if is_in_list({"delete_crossover"},why) then + minetest.set_node(pos,node) + mesecon.on_placenode(pos,node) + ref_remove(pos,node) + end + + if is_in_list({"delete_end"},why) then + minetest.set_node(pos,{name="air"}) + mesecon.on_dignode(pos,node) + ref_remove(pos,node) + --mesecon.on_dignode(pos,{name="air"}) + + --mesecon.receiver_remove(pos,node) + --minetest.set_node(pos,node) + --mesecon.on_placenode(pos,node) + end + ]]-- + + end + +end + + +-- Register Tools + +dofile(minetest.get_modpath("mesecons_autotools").."/tools.lua"); + + +-- Register Rendering + +dofile(minetest.get_modpath("mesecons_autotools").."/render.lua"); + +-- Regiser Circuit + +dofile(minetest.get_modpath("mesecons_autotools").."/book/circuit.lua"); +--dofile(minetest.get_modpath("mesecons_autotools").."/book/library.lua"); +dofile(minetest.get_modpath("mesecons_autotools").."/book/file.lua"); + +-- Register chatcommands + +dofile(minetest.get_modpath("mesecons_autotools").."/commands/all_commands.lua"); + diff --git a/mesecons_autotools_tmp/render.lua b/mesecons_autotools_tmp/render.lua new file mode 100644 index 0000000..56026dd --- /dev/null +++ b/mesecons_autotools_tmp/render.lua @@ -0,0 +1,156 @@ +-- Remove entities +local function clear_selection(user) + if mesecons_autotools.users[user] == nil then + mesecons_autotools.users[user] = {} + end + if mesecons_autotools.users[user].entities == nil then + mesecons_autotools.users[user].entities = {} + end + + + + for _,v in pairs(mesecons_autotools.users[user].entities) do + v:remove() + end + mesecons_autotools.users[user].entities = {} + + +end + + +-- Register entities +minetest.register_entity(":mesecons_autotools:pos1", { + initial_properties = { + visual = "cube", + visual_size = {x=1.11, y=1.11, }, + textures = {"pos1.png", "pos1.png", + "pos1.png", "pos1.png", + "pos1.png", "pos1.png"}, + collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55}, + physical = false, + static_save = false, + }, + on_activate = function(self, staticdata, dtime_s) + end, + + on_punch = function(self,hitter) + end, + on_blast = function(self, damage) + return false, false, {} -- don't damage or knockback + end, +}) +minetest.register_entity(":mesecons_autotools:pos2", { + initial_properties = { + visual = "cube", + visual_size = {x=1.1, y=1.1}, + textures = {"pos2.png", "pos2.png", + "pos2.png", "pos2.png", + "pos2.png", "pos2.png"}, + collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55}, + physical = false, + static_save = false, + }, + on_activate = function(self, staticdata, dtime_s) + end, + + on_punch = function(self,hitter) + end, + + on_blast = function(self, damage) + return false, false, {} -- don't damage or knockback + end, +}) +minetest.register_entity(":mesecons_autotools:wall", { + initial_properties = { + visual = "upright_sprite", + textures = {"wall.png"}, + visual_size = {x=10, y=10}, + physical = false, + static_save = false, + }, + on_activate = function(self, staticdata, dtime_s) + end, + + on_punch = function(self,hitter) + end, + + on_blast = function(self, damage) + return false, false, {} -- don't damage or knockback + end, +}) + +minetest.register_entity(":mesecons_autotools:pos", { + initial_properties = { + visual = "cube", + visual_size = {x=1.1, y=1.1}, + textures = {"pos.png", "pos.png", + "pos.png", "pos.png", + "pos.png", "pos.png"}, + collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55}, + physical = false, + static_save = false, + }, + on_activate = function(self, staticdata, dtime_s) + end, + + on_punch = function(self,hitter) + end, + + on_blast = function(self, damage) + return false, false, {} -- don't damage or knockback + end, +}) + +--[[ not used: TODO remove +local function generate_corners(user) + local pos = {} + pos[1] = mesecons_autotools.get_pos(user,1) + pos[2] = mesecons_autotools.get_pos(user,2) + + if pos[1] == nil then return end + if pos[2] == nil then return end + + + local list = {} + for xi = 1,2 do + for yi = 1,2 do + for zi = 1,2 do + local p = { x = pos[xi].x , y = pos[yi].y , z = pos[zi].z } + if not vector.equals(p,pos[1]) then + table.insert(list,p) + end + end + end + end + return list +end +]]-- + + +local function show_selection(user) + local pos1 = mesecons_autotools.get_pos(user,1) + local pos2 = mesecons_autotools.get_pos(user,2) + + if pos1 ~= nil then + local e1 = minetest.add_entity(pos1,"mesecons_autotools:pos1") + table.insert(mesecons_autotools.users[user].entities, e1) + end + + if pos2 ~= nil then + local e2 = minetest.add_entity(pos2,"mesecons_autotools:pos2") + table.insert(mesecons_autotools.users[user].entities, e2) + end + + + +end + + + +mesecons_autotools.render = function(user) + clear_selection(user) + show_selection(user) +end + + + diff --git a/mesecons_autotools_tmp/textures/circuit_empty.png b/mesecons_autotools_tmp/textures/circuit_empty.png new file mode 100644 index 0000000..1623d00 Binary files /dev/null and b/mesecons_autotools_tmp/textures/circuit_empty.png differ diff --git a/mesecons_autotools_tmp/textures/circuit_full.png b/mesecons_autotools_tmp/textures/circuit_full.png new file mode 100644 index 0000000..dd73759 Binary files /dev/null and b/mesecons_autotools_tmp/textures/circuit_full.png differ diff --git a/mesecons_autotools_tmp/textures/circuit_test.png b/mesecons_autotools_tmp/textures/circuit_test.png new file mode 100644 index 0000000..1b243d3 Binary files /dev/null and b/mesecons_autotools_tmp/textures/circuit_test.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/empty.png b/mesecons_autotools_tmp/textures/formspec/empty.png new file mode 100644 index 0000000..f0d00bc Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/empty.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/and0.png b/mesecons_autotools_tmp/textures/formspec/gate/and0.png new file mode 100644 index 0000000..fa450f7 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/and0.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/and1.png b/mesecons_autotools_tmp/textures/formspec/gate/and1.png new file mode 100644 index 0000000..2f1139d Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/and1.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/and2.png b/mesecons_autotools_tmp/textures/formspec/gate/and2.png new file mode 100644 index 0000000..28e8adb Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/and2.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/and3.png b/mesecons_autotools_tmp/textures/formspec/gate/and3.png new file mode 100644 index 0000000..4c7cadd Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/and3.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/diode0.png b/mesecons_autotools_tmp/textures/formspec/gate/diode0.png new file mode 100644 index 0000000..309ff3f Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/diode0.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/diode1.png b/mesecons_autotools_tmp/textures/formspec/gate/diode1.png new file mode 100644 index 0000000..eed69eb Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/diode1.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/diode2.png b/mesecons_autotools_tmp/textures/formspec/gate/diode2.png new file mode 100644 index 0000000..6c052c3 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/diode2.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/diode3.png b/mesecons_autotools_tmp/textures/formspec/gate/diode3.png new file mode 100644 index 0000000..69b3639 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/diode3.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/nand0.png b/mesecons_autotools_tmp/textures/formspec/gate/nand0.png new file mode 100644 index 0000000..88b2ba8 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/nand0.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/nand1.png b/mesecons_autotools_tmp/textures/formspec/gate/nand1.png new file mode 100644 index 0000000..0c659ee Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/nand1.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/nand2.png b/mesecons_autotools_tmp/textures/formspec/gate/nand2.png new file mode 100644 index 0000000..da3a280 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/nand2.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/nand3.png b/mesecons_autotools_tmp/textures/formspec/gate/nand3.png new file mode 100644 index 0000000..cfc7f3e Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/nand3.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/nor0.png b/mesecons_autotools_tmp/textures/formspec/gate/nor0.png new file mode 100644 index 0000000..e586690 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/nor0.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/nor1.png b/mesecons_autotools_tmp/textures/formspec/gate/nor1.png new file mode 100644 index 0000000..86aec63 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/nor1.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/nor2.png b/mesecons_autotools_tmp/textures/formspec/gate/nor2.png new file mode 100644 index 0000000..d6a9784 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/nor2.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/nor3.png b/mesecons_autotools_tmp/textures/formspec/gate/nor3.png new file mode 100644 index 0000000..c7de743 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/nor3.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/not0.png b/mesecons_autotools_tmp/textures/formspec/gate/not0.png new file mode 100644 index 0000000..9ba61fe Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/not0.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/not1.png b/mesecons_autotools_tmp/textures/formspec/gate/not1.png new file mode 100644 index 0000000..7a25956 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/not1.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/not2.png b/mesecons_autotools_tmp/textures/formspec/gate/not2.png new file mode 100644 index 0000000..e2ae188 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/not2.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/not3.png b/mesecons_autotools_tmp/textures/formspec/gate/not3.png new file mode 100644 index 0000000..6f65e95 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/not3.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/or0.png b/mesecons_autotools_tmp/textures/formspec/gate/or0.png new file mode 100644 index 0000000..87cd827 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/or0.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/or1.png b/mesecons_autotools_tmp/textures/formspec/gate/or1.png new file mode 100644 index 0000000..c008c92 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/or1.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/or2.png b/mesecons_autotools_tmp/textures/formspec/gate/or2.png new file mode 100644 index 0000000..895a46f Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/or2.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/or3.png b/mesecons_autotools_tmp/textures/formspec/gate/or3.png new file mode 100644 index 0000000..676c6d5 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/or3.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/xor0.png b/mesecons_autotools_tmp/textures/formspec/gate/xor0.png new file mode 100644 index 0000000..3f783e9 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/xor0.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/xor1.png b/mesecons_autotools_tmp/textures/formspec/gate/xor1.png new file mode 100644 index 0000000..224e98b Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/xor1.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/xor2.png b/mesecons_autotools_tmp/textures/formspec/gate/xor2.png new file mode 100644 index 0000000..b3e36c4 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/xor2.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate/xor3.png b/mesecons_autotools_tmp/textures/formspec/gate/xor3.png new file mode 100644 index 0000000..44059d0 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate/xor3.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate3/and3/jeija_gate3_and3r0.png b/mesecons_autotools_tmp/textures/formspec/gate3/and3/jeija_gate3_and3r0.png new file mode 100644 index 0000000..d502773 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate3/and3/jeija_gate3_and3r0.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate3/and3/jeija_gate3_and3r1.png b/mesecons_autotools_tmp/textures/formspec/gate3/and3/jeija_gate3_and3r1.png new file mode 100644 index 0000000..617150e Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate3/and3/jeija_gate3_and3r1.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate3/and3/jeija_gate3_and3r2.png b/mesecons_autotools_tmp/textures/formspec/gate3/and3/jeija_gate3_and3r2.png new file mode 100644 index 0000000..665e121 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate3/and3/jeija_gate3_and3r2.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate3/and3/jeija_gate3_and3r3.png b/mesecons_autotools_tmp/textures/formspec/gate3/and3/jeija_gate3_and3r3.png new file mode 100644 index 0000000..04c6a48 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate3/and3/jeija_gate3_and3r3.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate3/nand3/jeija_gate3_nand3r0.png b/mesecons_autotools_tmp/textures/formspec/gate3/nand3/jeija_gate3_nand3r0.png new file mode 100644 index 0000000..30e4c8a Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate3/nand3/jeija_gate3_nand3r0.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate3/nand3/jeija_gate3_nand3r1.png b/mesecons_autotools_tmp/textures/formspec/gate3/nand3/jeija_gate3_nand3r1.png new file mode 100644 index 0000000..623870d Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate3/nand3/jeija_gate3_nand3r1.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate3/nand3/jeija_gate3_nand3r2.png b/mesecons_autotools_tmp/textures/formspec/gate3/nand3/jeija_gate3_nand3r2.png new file mode 100644 index 0000000..3ac0fa6 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate3/nand3/jeija_gate3_nand3r2.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate3/nand3/jeija_gate3_nand3r3.png b/mesecons_autotools_tmp/textures/formspec/gate3/nand3/jeija_gate3_nand3r3.png new file mode 100644 index 0000000..77951be Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate3/nand3/jeija_gate3_nand3r3.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate3/nor3/jeija_gate3_nor3r0.png b/mesecons_autotools_tmp/textures/formspec/gate3/nor3/jeija_gate3_nor3r0.png new file mode 100644 index 0000000..a3a0c3a Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate3/nor3/jeija_gate3_nor3r0.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate3/nor3/jeija_gate3_nor3r1.png b/mesecons_autotools_tmp/textures/formspec/gate3/nor3/jeija_gate3_nor3r1.png new file mode 100644 index 0000000..b73a7cc Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate3/nor3/jeija_gate3_nor3r1.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate3/nor3/jeija_gate3_nor3r2.png b/mesecons_autotools_tmp/textures/formspec/gate3/nor3/jeija_gate3_nor3r2.png new file mode 100644 index 0000000..17f13d9 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate3/nor3/jeija_gate3_nor3r2.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate3/nor3/jeija_gate3_nor3r3.png b/mesecons_autotools_tmp/textures/formspec/gate3/nor3/jeija_gate3_nor3r3.png new file mode 100644 index 0000000..9a9dac0 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate3/nor3/jeija_gate3_nor3r3.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate3/nor3/jeija_gate_nor3.png b/mesecons_autotools_tmp/textures/formspec/gate3/nor3/jeija_gate_nor3.png new file mode 100644 index 0000000..774fa23 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate3/nor3/jeija_gate_nor3.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate3/or3/jeija_gate3_or3r0.png b/mesecons_autotools_tmp/textures/formspec/gate3/or3/jeija_gate3_or3r0.png new file mode 100644 index 0000000..e68caa6 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate3/or3/jeija_gate3_or3r0.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate3/or3/jeija_gate3_or3r1.png b/mesecons_autotools_tmp/textures/formspec/gate3/or3/jeija_gate3_or3r1.png new file mode 100644 index 0000000..8303af9 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate3/or3/jeija_gate3_or3r1.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate3/or3/jeija_gate3_or3r2.png b/mesecons_autotools_tmp/textures/formspec/gate3/or3/jeija_gate3_or3r2.png new file mode 100644 index 0000000..6197453 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate3/or3/jeija_gate3_or3r2.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/gate3/or3/jeija_gate3_or3r3.png b/mesecons_autotools_tmp/textures/formspec/gate3/or3/jeija_gate3_or3r3.png new file mode 100644 index 0000000..c788f2a Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/gate3/or3/jeija_gate3_or3r3.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/pink.png b/mesecons_autotools_tmp/textures/formspec/pink.png new file mode 100644 index 0000000..e03b52b Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/pink.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/regs/ff0.png b/mesecons_autotools_tmp/textures/formspec/regs/ff0.png new file mode 100644 index 0000000..66f2ae7 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/regs/ff0.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/regs/ff1.png b/mesecons_autotools_tmp/textures/formspec/regs/ff1.png new file mode 100644 index 0000000..fd8e005 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/regs/ff1.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/regs/ff2.png b/mesecons_autotools_tmp/textures/formspec/regs/ff2.png new file mode 100644 index 0000000..c5fb774 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/regs/ff2.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/regs/ff3.png b/mesecons_autotools_tmp/textures/formspec/regs/ff3.png new file mode 100644 index 0000000..92914aa Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/regs/ff3.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/regs/latch0.png b/mesecons_autotools_tmp/textures/formspec/regs/latch0.png new file mode 100644 index 0000000..089b64b Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/regs/latch0.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/regs/latch1.png b/mesecons_autotools_tmp/textures/formspec/regs/latch1.png new file mode 100644 index 0000000..f545b81 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/regs/latch1.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/regs/latch2.png b/mesecons_autotools_tmp/textures/formspec/regs/latch2.png new file mode 100644 index 0000000..f2ed048 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/regs/latch2.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/regs/latch3.png b/mesecons_autotools_tmp/textures/formspec/regs/latch3.png new file mode 100644 index 0000000..16f1ffe Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/regs/latch3.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/unknown.png b/mesecons_autotools_tmp/textures/formspec/unknown.png new file mode 100644 index 0000000..f91b9ea Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/unknown.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/wires/corner0.png b/mesecons_autotools_tmp/textures/formspec/wires/corner0.png new file mode 100644 index 0000000..1272d0c Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/wires/corner0.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/wires/corner1.png b/mesecons_autotools_tmp/textures/formspec/wires/corner1.png new file mode 100644 index 0000000..d0e64d4 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/wires/corner1.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/wires/corner2.png b/mesecons_autotools_tmp/textures/formspec/wires/corner2.png new file mode 100644 index 0000000..37e1d44 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/wires/corner2.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/wires/corner3.png b/mesecons_autotools_tmp/textures/formspec/wires/corner3.png new file mode 100644 index 0000000..550e5c2 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/wires/corner3.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/wires/corssover.png b/mesecons_autotools_tmp/textures/formspec/wires/corssover.png new file mode 100644 index 0000000..ef7e871 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/wires/corssover.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/wires/tjunction0.png b/mesecons_autotools_tmp/textures/formspec/wires/tjunction0.png new file mode 100644 index 0000000..5c5fa7b Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/wires/tjunction0.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/wires/tjunction1.png b/mesecons_autotools_tmp/textures/formspec/wires/tjunction1.png new file mode 100644 index 0000000..344126b Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/wires/tjunction1.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/wires/tjunction2.png b/mesecons_autotools_tmp/textures/formspec/wires/tjunction2.png new file mode 100644 index 0000000..9cb6201 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/wires/tjunction2.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/wires/tjunction3.png b/mesecons_autotools_tmp/textures/formspec/wires/tjunction3.png new file mode 100644 index 0000000..77ea415 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/wires/tjunction3.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/wires/wireh.png b/mesecons_autotools_tmp/textures/formspec/wires/wireh.png new file mode 100644 index 0000000..8a5d895 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/wires/wireh.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/wires/wirev.png b/mesecons_autotools_tmp/textures/formspec/wires/wirev.png new file mode 100644 index 0000000..c0fce22 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/wires/wirev.png differ diff --git a/mesecons_autotools_tmp/textures/formspec/wires/xjunction.png b/mesecons_autotools_tmp/textures/formspec/wires/xjunction.png new file mode 100644 index 0000000..f123fa5 Binary files /dev/null and b/mesecons_autotools_tmp/textures/formspec/wires/xjunction.png differ diff --git a/mesecons_autotools_tmp/textures/library.png b/mesecons_autotools_tmp/textures/library.png new file mode 100644 index 0000000..4f7508d Binary files /dev/null and b/mesecons_autotools_tmp/textures/library.png differ diff --git a/mesecons_autotools_tmp/textures/pos.png b/mesecons_autotools_tmp/textures/pos.png new file mode 100644 index 0000000..8dcf687 Binary files /dev/null and b/mesecons_autotools_tmp/textures/pos.png differ diff --git a/mesecons_autotools_tmp/textures/selection/pos1.png b/mesecons_autotools_tmp/textures/selection/pos1.png new file mode 100644 index 0000000..4c304aa Binary files /dev/null and b/mesecons_autotools_tmp/textures/selection/pos1.png differ diff --git a/mesecons_autotools_tmp/textures/selection/pos2.png b/mesecons_autotools_tmp/textures/selection/pos2.png new file mode 100644 index 0000000..1502f16 Binary files /dev/null and b/mesecons_autotools_tmp/textures/selection/pos2.png differ diff --git a/mesecons_autotools_tmp/textures/test.png b/mesecons_autotools_tmp/textures/test.png new file mode 100644 index 0000000..961ecb9 Binary files /dev/null and b/mesecons_autotools_tmp/textures/test.png differ diff --git a/mesecons_autotools_tmp/textures/tools/black.png b/mesecons_autotools_tmp/textures/tools/black.png new file mode 100644 index 0000000..2f1ee62 Binary files /dev/null and b/mesecons_autotools_tmp/textures/tools/black.png differ diff --git a/mesecons_autotools_tmp/textures/tools/blue.png b/mesecons_autotools_tmp/textures/tools/blue.png new file mode 100644 index 0000000..6869edf Binary files /dev/null and b/mesecons_autotools_tmp/textures/tools/blue.png differ diff --git a/mesecons_autotools_tmp/textures/tools/orange.png b/mesecons_autotools_tmp/textures/tools/orange.png new file mode 100644 index 0000000..e0195bd Binary files /dev/null and b/mesecons_autotools_tmp/textures/tools/orange.png differ diff --git a/mesecons_autotools_tmp/textures/tools/orange_up.png b/mesecons_autotools_tmp/textures/tools/orange_up.png new file mode 100644 index 0000000..56ff087 Binary files /dev/null and b/mesecons_autotools_tmp/textures/tools/orange_up.png differ diff --git a/mesecons_autotools_tmp/textures/tools/red.png b/mesecons_autotools_tmp/textures/tools/red.png new file mode 100644 index 0000000..43cf848 Binary files /dev/null and b/mesecons_autotools_tmp/textures/tools/red.png differ diff --git a/mesecons_autotools_tmp/textures/tools/refresh.png b/mesecons_autotools_tmp/textures/tools/refresh.png new file mode 100644 index 0000000..ac12fa1 Binary files /dev/null and b/mesecons_autotools_tmp/textures/tools/refresh.png differ diff --git a/mesecons_autotools_tmp/textures/tools/white.png b/mesecons_autotools_tmp/textures/tools/white.png new file mode 100644 index 0000000..e4bc23e Binary files /dev/null and b/mesecons_autotools_tmp/textures/tools/white.png differ diff --git a/mesecons_autotools_tmp/textures/tools/white_down (copy).png b/mesecons_autotools_tmp/textures/tools/white_down (copy).png new file mode 100644 index 0000000..ac3ea7d Binary files /dev/null and b/mesecons_autotools_tmp/textures/tools/white_down (copy).png differ diff --git a/mesecons_autotools_tmp/textures/tools/white_down.png b/mesecons_autotools_tmp/textures/tools/white_down.png new file mode 100644 index 0000000..a1b1f6e Binary files /dev/null and b/mesecons_autotools_tmp/textures/tools/white_down.png differ diff --git a/mesecons_autotools_tmp/textures/tools/white_up.png b/mesecons_autotools_tmp/textures/tools/white_up.png new file mode 100644 index 0000000..f1660a6 Binary files /dev/null and b/mesecons_autotools_tmp/textures/tools/white_up.png differ diff --git a/mesecons_autotools_tmp/textures/tools/yellow.png b/mesecons_autotools_tmp/textures/tools/yellow.png new file mode 100644 index 0000000..0ea6524 Binary files /dev/null and b/mesecons_autotools_tmp/textures/tools/yellow.png differ diff --git a/mesecons_autotools_tmp/textures/tools/yellow_updown.png b/mesecons_autotools_tmp/textures/tools/yellow_updown.png new file mode 100644 index 0000000..62f51cd Binary files /dev/null and b/mesecons_autotools_tmp/textures/tools/yellow_updown.png differ diff --git a/mesecons_autotools_tmp/textures/wall.png b/mesecons_autotools_tmp/textures/wall.png new file mode 100644 index 0000000..fde36a8 Binary files /dev/null and b/mesecons_autotools_tmp/textures/wall.png differ diff --git a/mesecons_autotools_tmp/tools.lua b/mesecons_autotools_tmp/tools.lua new file mode 100644 index 0000000..88de35a --- /dev/null +++ b/mesecons_autotools_tmp/tools.lua @@ -0,0 +1,133 @@ +-- Common functions +-- a bit of a weld (TODO: fix that) +function is_circuit_element(pos) + local node = minetest.get_node(pos) + local name = node.name + + local m = string.match(name,"^mesecons_") + if m ~= nil then + return true + end + + m = string.match(name,"^mesecons:") + if m ~= nil then + return true + end + + if name == "default:mese" then + return true + end + + + return false +end + + + + +-- Register all tools and callbacks + +local tool_list = { + {"black", "Auto Wire Tool"}, + {"blue", "Selection Tool"}, + {"white_up", "Selection Top Edge Tool"}, + {"white_down", "Selection Bottom Edge Tool"}, + {"white", "Selection Right Edge Tool"}, + {"orange", "Stack Right Tool"}, + {"orange_up", "Stack Up Tool"}, + {"red", "Delete Tool"}, + {"yellow", "Move Horizontal Tool"}, + {"yellow_updown", "Move Vertical Tool"}, + {"refresh", "Refresh Tool"} + } +for _,t in pairs(tool_list) do + local tool = t[1] + local description = t[2] + + minetest.register_tool("mesecons_autotools:" .. tool , { + description = description, + inventory_image = tool .. ".png", + stack_max = 1, + groups = { tool =1 }, + + on_use = function(itemstack, player, pointed_thing) + local pos = pointed_thing.under + local player_pos = vector.round(player:get_pos()) + local player_name = player:get_player_name() + local rad = player:get_look_horizontal() + + if pointed_thing.type == "node" then + if (is_circuit_element(pos)) then + pos = pointed_thing.under + mesecons_autotools.execute_action(tool,"left","block", player_name, pos, rad, pointed_thing.under); + else + pos = pointed_thing.above + mesecons_autotools.execute_action(tool,"left","block", player_name, pos, rad, pointed_thing.under); + end + + elseif pointed_thing.type == "nothing" then + if (is_circuit_element(player_pos)) then + pos = pointed_thing.under + mesecons_autotools.execute_action(tool,"left","air", player_name, player_pos, rad); + else + pos = pointed_thing.above + mesecons_autotools.execute_action(tool,"left","air", player_name, player_pos, rad); + end + end + + end, + + on_place = function(itemstack, player, pointed_thing) + local pos = pointed_thing.under + local player_pos = vector.round(player:get_pos()) + local player_name = player:get_player_name() + local rad = player:get_look_horizontal() + + if pointed_thing.type == "node" then + if (is_circuit_element(pos)) then + pos = pointed_thing.under + mesecons_autotools.execute_action(tool,"right","block", player_name, pos, rad, pointed_thing.under); + else + pos = pointed_thing.above + mesecons_autotools.execute_action(tool,"right","block", player_name, pos, rad, pointed_thing.under); + end + end + + + end, + on_secondary_use = function(itemstack, player, pointed_thing) + local pos = pointed_thing.under + local player_pos = vector.round(player:get_pos()) + local player_name = player:get_player_name() + local rad = player:get_look_horizontal() + + if pointed_thing.type == "nothing" then + if (is_circuit_element(player_pos)) then + pos = pointed_thing.under + mesecons_autotools.execute_action(tool,"right","air", player_name, player_pos, rad); + else + pos = pointed_thing.above + mesecons_autotools.execute_action(tool,"right","air", player_name, player_pos, rad); + end + + end + + end + + + }) + + + + -- Implementations + dofile(minetest.get_modpath("mesecons_autotools").."/tools/" .. tool .. "/".. tool .. ".lua"); + + +end + +dofile(minetest.get_modpath("mesecons_autotools").."/tools/selection.lua"); +dofile(minetest.get_modpath("mesecons_autotools").."/tools/direction.lua"); +dofile(minetest.get_modpath("mesecons_autotools").."/tools/wire.lua"); +dofile(minetest.get_modpath("mesecons_autotools").."/tools/bundle.lua"); + + diff --git a/mesecons_autotools_tmp/tools/black/black.lua b/mesecons_autotools_tmp/tools/black/black.lua new file mode 100644 index 0000000..a8fa1fa --- /dev/null +++ b/mesecons_autotools_tmp/tools/black/black.lua @@ -0,0 +1,63 @@ + + + + +mesecons_autotools.register_action("black","left","air", function(user,pos,rad) + -- Unselect pos + mesecons_autotools.set_pos(user,1,nil); + mesecons_autotools.set_pos(user,2,nil); + + -- Update + mesecons_autotools.render(user) + mesecons_autotools.zero_stack_counter(user) + mesecons_autotools.zero_stack_direction(user) + +end) +mesecons_autotools.register_action("black","left","block", function(user,pos,rad) + mesecons_autotools.set_pos(user,1,pos) + mesecons_autotools.set_pos(user,2,pos) + + -- Update + mesecons_autotools.render(user) + mesecons_autotools.zero_stack_counter(user) + mesecons_autotools.zero_stack_direction(user) +end) + +mesecons_autotools.register_action("black","right","block", function(user,pos,rad) + local pos1 = mesecons_autotools.get_pos(user,1) + local pos2 = mesecons_autotools.get_pos(user,2) + local sel = {} + sel.pos1 = pos1 + sel.pos2 = pos2 + + if not mesecons_autotools.is_full_selection(user) then return end + + local done = false + done = create_bundle_straight_wire(sel ,pos) + if done == true then + local direction = tunel_direction(sel,pos) + local distance = distance_to_selection(sel,pos,direction) -1 + + -- set new selection + local front_wall = tunel_front_wall(sel,pos) + mesecons_autotools.set_pos(user,1,front_wall.pos1) + mesecons_autotools.set_pos(user,2,front_wall.pos2) + shift_selection(user, vector.multiply(direction,distance)) + + -- Update + mesecons_autotools.render(user) + mesecons_autotools.zero_stack_counter(user) + mesecons_autotools.zero_stack_direction(user) + end + + + +end) + +mesecons_autotools.register_action("black","right","air", function(user,pos,rad) + +end) + + + + \ No newline at end of file diff --git a/mesecons_autotools_tmp/tools/blue/blue.lua b/mesecons_autotools_tmp/tools/blue/blue.lua new file mode 100644 index 0000000..5d093c4 --- /dev/null +++ b/mesecons_autotools_tmp/tools/blue/blue.lua @@ -0,0 +1,30 @@ + + +local function select_pos(user,pos,nr) + mesecons_autotools.set_pos(user,nr,pos); + + + -- Update + mesecons_autotools.render(user) + mesecons_autotools.zero_stack_counter(user) +end + + + + +mesecons_autotools.register_action("blue","left","air", function(user,pos,rad) + select_pos(user,pos,1) +end) +mesecons_autotools.register_action("blue","left","block", function(user,pos,rad) + select_pos(user,pos,1) +end) + +mesecons_autotools.register_action("blue","right","block", function(user,pos,rad) + select_pos(user,pos,2) +end) + +mesecons_autotools.register_action("blue","right","air", function(user,pos,rad) + select_pos(user,pos,2) +end) + + \ No newline at end of file diff --git a/mesecons_autotools_tmp/tools/bundle.lua b/mesecons_autotools_tmp/tools/bundle.lua new file mode 100644 index 0000000..3ff7f3f --- /dev/null +++ b/mesecons_autotools_tmp/tools/bundle.lua @@ -0,0 +1,599 @@ + +function is_in_selection(sel,p) + local pos = {} + pos[1] = sel.pos1 + pos[2] = sel.pos2 + + if pos[1] == nil then return false end + if pos[2] == nil then return false end + + local xmax = math.max(pos[1].x, pos[2].x) + local xmin = math.min(pos[1].x, pos[2].x) + + local ymax = math.max(pos[1].y, pos[2].y) + local ymin = math.min(pos[1].y, pos[2].y) + + local zmax = math.max(pos[1].z, pos[2].z) + local zmin = math.min(pos[1].z, pos[2].z) + + local x = p.x + local y = p.y + local z = p.z + + if (xmin<=p.x) and (p.x<=xmax) and + (ymin<=p.y) and (p.y<=ymax) and + (zmin<=p.z) and (p.z<=zmax) then + return true + end + return false +end + +function is_in_layer(sel,p) + local pos = {} + pos[1] = sel.pos1 + pos[2] = sel.pos2 + + local ymax = math.max(pos[1].y, pos[2].y) + local ymin = math.min(pos[1].y, pos[2].y) + + if (p.y > ymax) or (p.y< ymin) then return false end + return true + +end + +function is_in_tube(sel,p) + if is_in_selection(sel,p) then return false end + if not is_in_layer(sel,p) then return false end + local pos = {} + pos[1] = sel.pos1 + pos[2] = sel.pos2 + + local xmax = math.max(pos[1].x, pos[2].x) + local xmin = math.min(pos[1].x, pos[2].x) + + local ymax = math.max(pos[1].y, pos[2].y) + local ymin = math.min(pos[1].y, pos[2].y) + + local zmax = math.max(pos[1].z, pos[2].z) + local zmin = math.min(pos[1].z, pos[2].z) + + local x = p.x + local y = p.y + local z = p.z + + if (xmin <=x ) and (x<=xmax) then return true end + if (zmin <=z) and (z<=zmax) then return true end + return false + +end +--[[ +function is_in_wings(sel,p) + if is_in_selection(sel,p) then return false end + if not is_in_layer(sel,p) then return false end + if is_in_tube(sel,p) then return false end + return true +end +]]-- + + +function front_wall_tube(sel,p) + local pos = {} + pos[1] = sel.pos1 + pos[2] = sel.pos2 + + local xmax = math.max(pos[1].x, pos[2].x) + local xmin = math.min(pos[1].x, pos[2].x) + + local ymax = math.max(pos[1].y, pos[2].y) + local ymin = math.min(pos[1].y, pos[2].y) + + local zmax = math.max(pos[1].z, pos[2].z) + local zmin = math.min(pos[1].z, pos[2].z) + + local x = p.x + local y = p.y + local z = p.z + + local new_sel = {} + local new_pos1 = vector.new(pos[1]) + local new_pos2 = vector.new(pos[2]) + local direction = {} + + + if (xmin<=x) and (x<=xmax) then + if (z > zmax) then + direction.x = 0 + direction.y = 0 + direction.z = 1 + + new_pos1.z = zmax + new_pos2.z = zmax + else + direction.x = 0 + direction.y = 0 + direction.z = -1 + + new_pos1.z = zmin + new_pos2.z = zmin + end + end + if (zmin<=z) and (z<=zmax) then + if( x > xmax) then + direction.x = 1 + direction.y = 0 + direction.z = 0 + + new_pos1.x = xmax + new_pos2.x = xmax + else + direction.x = -1 + direction.y = 0 + direction.z = 0 + + new_pos1.x = xmin + new_pos2.x = xmin + + end + + end + + + new_sel.pos1 = new_pos1 + new_sel.pos2 = new_pos2 + + return new_sel,direction +end + +function tunel_direction(sel,pos) + local wall,dir = front_wall_tube(sel,pos) + return dir +end + +function tunel_front_wall(sel,pos) + local wall,dir = front_wall_tube(sel,pos) + return wall +end + + + + +function is_dir_vertical(direction) + if direction.z ~= 0 then return true end + return false +end + +function is_look_vertical(rad) + local dir = radians_to_direction_looking_forward(rad) + return is_dir_vertical(dir) +end + +--[[ +function is_dir_horizontal(direction) + if direction.x ~= then return true end + return false +end +]]-- + +function front_wall_by_direction(sel,direction) + local pos = {} + pos[1] = sel.pos1 + pos[2] = sel.pos2 + + local xmax = math.max(pos[1].x, pos[2].x) + local xmin = math.min(pos[1].x, pos[2].x) + + local ymax = math.max(pos[1].y, pos[2].y) + local ymin = math.min(pos[1].y, pos[2].y) + + local zmax = math.max(pos[1].z, pos[2].z) + local zmin = math.min(pos[1].z, pos[2].z) + + + local new_sel = {} + local new_pos1 = vector.new(pos[1]) + local new_pos2 = vector.new(pos[2]) + + if direction.x == 1 then + new_pos1.x = xmax + new_pos2.x = xmax + end + if direction.x == -1 then + new_pos1.x = xmin + new_pos2.x = xmin + end + if direction.z == 1 then + new_pos1.z = zmax + new_pos2.z = zmax + end + if direction.z == -1 then + new_pos1.z = zmin + new_pos2.z = zmin + end + if direction.y == 1 then + new_pos1.y = ymax + new_pos2.y = ymax + end + if direction.y == -1 then + new_pos1.y = ymin + new_pos2.y = ymin + end + + new_sel.pos1 = new_pos1 + new_sel.pos2 = new_pos2 + + return new_sel +end +--[[ +function get_wing_cords(sel,p) + local zero = {x =0,z=0} + local cord + if is_in_selection(sel,p) then return zero end + if not is_in_layer(sel,p) then return zero end + + local pos = {} + pos[1] = sel.pos1 + pos[2] = sel.pos2 + + local xmax = math.max(pos[1].x, pos[2].x) + local xmin = math.min(pos[1].x, pos[2].x) + + local ymax = math.max(pos[1].y, pos[2].y) + local ymin = math.min(pos[1].y, pos[2].y) + + local zmax = math.max(pos[1].z, pos[2].z) + local zmin = math.min(pos[1].z, pos[2].z) + + local x = p.x + local y = p.y + local z = p.z + + if (x>xmax) and (z>zmax) then + cord = { x = 1, z = 1} + end + if (xzmax) then + cord = {x = -1 , z = 1} + end + if (zxmax) then + cord = { x = 1 , z = -1 } + end + if (z < zmin) and (x < xmin) then + cord = { x -1 ,z = -1 } + end + + return cord +end +]]-- +--[[ +function front_wall_wing(sel,p,rad) + local cord = get_wing_cords(sel,p) + + local wall_dir + wall_dir.y = 0 + + if cord.x == 1 and cord.z == 1 then + if is_look_vertical(rad) then + wall_dir = {x=1,z=0} + else + wall_dir = {x=0,z=1} + end + end + + if cord.x == -1 and cord.z == 1 then + if is_look_vertical(rad) then + wall_dir = {x=-1,z=0} + else + wall_dir = {x=0,z=1} + end + end + + if cord.x == 1 and cord.z == -1 then + if is_look_vertical(rad) then + wall_dir = {x=1,z=0} + else + wall_dir = {x=0,z=-1} + end + end + + if cord.x == -1 and cord.z == -1 then + if is_look_vertical(rad) then + wall_dir = {x=-1,z=0} + else + wall_dir = {x=0,z=-1} + end + end + + local wall = front_wall_by_direction(wall_dir) + + return wall,wall_dir +end + +]]-- +function distance_to_selection(sel,p,direction) + local dist = 0 + local pos = {} + pos[1] = sel.pos1 + pos[2] = sel.pos2 + + if not is_in_layer(sel,p) then return dist end + + --local direction = tunel_direction(sel,p) + + + local xmax = math.max(pos[1].x, pos[2].x) + local xmin = math.min(pos[1].x, pos[2].x) + + local ymax = math.max(pos[1].y, pos[2].y) + local ymin = math.min(pos[1].y, pos[2].y) + + local zmax = math.max(pos[1].z, pos[2].z) + local zmin = math.min(pos[1].z, pos[2].z) + + if direction.x ~= 0 then + if direction.x == 1 then + dist = math.abs(p.x - xmax) + elseif direction.x == -1 then + dist = math.abs(xmin-p.x) + end + + elseif direction.z ~= 0 then + if direction.z == 1 then + dist = math.abs(p.z - zmax) + elseif direction.z == -1 then + dist = math.abs(zmin - p.z) + end + + end + + return dist + 1 + +end + +--[[ +function direction_to_pins(direction) + local pin = {0,0,0,0} + if direction.x == -1 then + pin[1] = 1 + end + if direction.x == 1 then + pin[3] = 1 + end + if direction.z == 1 then + pin[2] = 1 + end + if direction.z == -1 then + pin[4] == 1 + end + return pin +end +]]-- +function direction_to_pin(direction) + if direction.x == -1 then + return 1 + end + if direction.x == 1 then + return 3 + end + if direction.z == 1 then + return 2 + end + if direction.z == -1 then + return 4 + end +end + + +function pos_to_connect(wall,direction) + local list = {} + iterate_selection(wall.pos1,wall.pos2, function(pos) + local pins = get_pins_from_pos(pos) + local dpin = direction_to_pin(direction) + if pins[dpin] == 1 then + table.insert(list,pos) + end + end) + return list +end + +function _is_block_type(pos,direction) + local node = minetest.get_node(pos) + local name = node.name + + if name == "air" then + return "buildable" + end + + if name == "mesecons_insulated:insulated_off" or + name == "mesecons_insulated:insulated_on" then + + local param2 = node.param2 + local pin = direction_to_pin(direction) + + if (param2==0 or param2==2) and (pin==2 or pin==4) then + return "buildable" + end + if (param2==1 or param2==3) and (pin==1 or pin==3) then + return "buildable" + end + return "last" + end + + + local pos_pins = get_pins_from_pos(pos) + local dir_pin = flip_pin(direction_to_pin(direction)) + if pos_pins[dir_pin] ==1 then + return "last" + end + return "cancel" +end + + +function is_block_type(pos,direction) + local res = _is_block_type(pos,direction) + local node = minetest.get_node(pos) + local name = node.name + + + return res +end + + +function is_block_cancel(pos,direction) + if is_block_type(pos,direction) == "cancel" then + return true + else + return false + end +end + +function is_block_last(pos,direction) + if is_block_type(pos,direction) == "last" then + return true + else + return false + end +end + +function is_block_buildable(pos,direction) + if is_block_type(pos,direction) == "buildable" then + return true + else + return false + end +end + + + +function _can_build_wire(pos,direction,size) + local current = { x=pos.x , y =pos.y, z=pos.z} + + local flag = false + for i=1,size,1 do + + if is_block_cancel(current,direction) then + return false + end + if is_block_last(current,direction) then + return true + end + + current = vector.add(current,direction) + end + return flag +end + +function can_build_wire(pos,direction,size) + return _can_build_wire(pos,direction,size) +end + + +function add_wire(pos,direction) + local node = minetest.get_node(pos) + local name = node.name + + if name == "air" then + local pins = get_pins_from_pos(pos) + local dpin = direction_to_pin(direction) + + pins[dpin] = 1 + pins[flip_pin(dpin)] = 1 + + local nnode = get_node_from_pins(pins) + + --minetest.set_node(pos,nnode) + mesecons_autotools.set_node(pos,nnode,"add_wire") + else + local nnode = { name = "mesecons_extrawires:crossover_off" } + --minetest.set_node(pos, nnode) + mesecons_autotools.set_node(pos,nnode,"add_wire") + + end + + + +end +--[[ not used +function add_last_wire(pos,direction) + local pins = get_pins_from_pos(pos) + local dpin = direction_to_pin(direction) + + pins[flip_pin(dpin)] = 1 + + local node = get_node_from_pins(pins) + + minetest.set_node(pos,node) + +end +]]-- + +function build_wire_inside(pos,direction,size) + local current = { x=pos.x , y =pos.y, z=pos.z} + + if not can_build_wire(pos,direction,size) then return end + + for i=1,size,1 do + if is_block_cancel(current,direction) then + return + elseif is_block_buildable(current,direction) then + add_wire(current,direction) + elseif is_block_last(current,direction) then + break + end + current = vector.add(current,direction) + end +end + + + +function create_wires_inside_selection(sel,wall,direction) + local size = size_by_direction(sel.pos1,sel.pos2,direction) + local back_direction = vector.multiply(direction,-1) + + + iterate_selection(wall.pos1,wall.pos2,function(pos) + build_wire_inside(pos,back_direction,size) + end) + +end + + +function create_bundle_straight_wire(sel,pos) + local pos1 = sel.pos1 + local pos2 = sel.pos2 + + + if not is_in_tube(sel,pos) then return false end + + + local wall,direction = front_wall_tube(sel,pos) + + + local distance = distance_to_selection(sel,pos,direction) + + if is_one_block(pos1,pos2) or + is_empty_selection(pos1,pos2) or + is_tower_selection(pos1,pos2) then + + iterate_selection(sel.pos1, sel.pos2, function(pos) + create_straight_wire_n(pos,direction,distance) + end) + else + + + + create_wires_inside_selection(sel,wall,direction) + + + local wire_list = pos_to_connect(wall,direction) + iterate_list(wire_list,function(pos) + create_straight_wire_n(pos,direction,distance) + end) + + end + return true + +end + + + + + diff --git a/mesecons_autotools_tmp/tools/direction.lua b/mesecons_autotools_tmp/tools/direction.lua new file mode 100644 index 0000000..86e10a1 --- /dev/null +++ b/mesecons_autotools_tmp/tools/direction.lua @@ -0,0 +1,28 @@ +function radians_to_vectors(rad) + local pi = math.pi + if (rad>=0) and (rad<=pi/4) or (rad<=2*pi) and (rad>=(3/2+1/4)*pi) then + return {left = {x=-1,z=0,y=0},right = { x=1, z = 0,y=0 } } + elseif (rad >= 1/4*pi) and (rad <= (1/2+1/4)*pi) then + return { left = {x = 0 ,z=-1,y=0}, right = { x = 0, z = 1 ,y=0} } + elseif (rad >= (1-1/4)*pi ) and (rad <= (3/2-1/4)*pi ) then + return { left = { x = 1, z =0 ,y=0}, right = { x = -1, z = 0 ,y=0} } + else + return { left = { z =1, x = 0 ,y=0} , right = { z = -1 , x = 0,y=0 }} + end +end + + +function radians_to_direction_looking_forward(rad) + if rad == nil then return {x=1,z=0,y=0} end + local pi = math.pi + if (rad>=0) and (rad<=pi/4) or (rad<=2*pi) and (rad>=(3/2+1/4)*pi) then + return {x=0, z =1 ,y=0} + elseif (rad >= 1/4*pi) and (rad <= (1/2+1/4)*pi) then + return {x=-1,z=0,y=0} + elseif (rad >= (1-1/4)*pi ) and (rad <= (3/2-1/4)*pi ) then + return {x=0,z=-1,y=0} + else + return {x=1,z=0,y=0} + end +end + diff --git a/mesecons_autotools_tmp/tools/orange/orange.lua b/mesecons_autotools_tmp/tools/orange/orange.lua new file mode 100644 index 0000000..1c1f449 --- /dev/null +++ b/mesecons_autotools_tmp/tools/orange/orange.lua @@ -0,0 +1,106 @@ +local function stack_right(user,rad) + local dir = radians_to_vectors(rad) + local left = dir.left + local right = dir.right + + local pos = {} + pos[1] = mesecons_autotools.get_pos(user,1) + pos[2] = mesecons_autotools.get_pos(user,2) + + + if pos[1] == nil then return end + if pos[2] == nil then return end + + + -- compute shift vector + + local shift_vector = {} + if right.x ~= 0 then + shift_vector.x = right.x * (math.abs(pos[2].x - pos[1].x)+1) + shift_vector.z = 0 + shift_vector.y = 0 + elseif right.z ~= 0 then + shift_vector.x = 0 + shift_vector.y = 0 + shift_vector.z = right.z * (math.abs(pos[2].z - pos[1].z)+1) + end + + copy(pos[1],pos[2],shift_vector) + shift_selection(user,shift_vector) + + -- Update + mesecons_autotools.render(user) + + + local old_stack_direction = mesecons_autotools.get_stack_direction(user) + if not vector.equals(old_stack_direction,right) then + mesecons_autotools.set_stack_direction(user,right) + mesecons_autotools.zero_stack_counter(user) + end + mesecons_autotools.inc_stack_counter(user) + + +end + + +local function stack_remove(user,rad) + local dir = radians_to_vectors(rad) + local left = dir.left + local right = dir.right + + local pos = {} + pos[1] = mesecons_autotools.get_pos(user,1) + pos[2] = mesecons_autotools.get_pos(user,2) + + + if pos[1] == nil then return end + if pos[2] == nil then return end + + if not vector.equals(mesecons_autotools.get_stack_direction(user),right) then return end + if mesecons_autotools.get_stack_counter(user) == 0 then return end + + -- compute shift vector + local shift_vector = {} + if right.x ~= 0 then + shift_vector.x = - right.x * (math.abs(pos[2].x - pos[1].x)+1) + shift_vector.z = 0 + shift_vector.y = 0 + elseif right.z ~= 0 then + shift_vector.x = 0 + shift_vector.y = 0 + shift_vector.z = - right.z * (math.abs(pos[2].z - pos[1].z)+1) + end + + delete(pos[1],pos[2]) + shift_selection(user,shift_vector) + + mesecons_autotools.dec_stack_counter(user) + + + -- Update + mesecons_autotools.render(user) + + +end + + + + + +mesecons_autotools.register_action("orange","left","air", function(user,pos,rad) + stack_remove(user,rad) +end) +mesecons_autotools.register_action("orange","left","block", function(user,pos,rad) + stack_remove(user,rad) +end) + +mesecons_autotools.register_action("orange","right","block", function(user,pos,rad) + stack_right(user,rad) +end) + +mesecons_autotools.register_action("orange","right","air", function(user,pos,rad) + stack_right(user,rad) +end) + + + \ No newline at end of file diff --git a/mesecons_autotools_tmp/tools/orange_up/orange_up.lua b/mesecons_autotools_tmp/tools/orange_up/orange_up.lua new file mode 100644 index 0000000..8731e25 --- /dev/null +++ b/mesecons_autotools_tmp/tools/orange_up/orange_up.lua @@ -0,0 +1,92 @@ + + + + + +local function stack_up(user) + if not mesecons_autotools.is_full_selection(user) then return end + + + local pos = {} + pos[1] = mesecons_autotools.get_pos(user,1) + pos[2] = mesecons_autotools.get_pos(user,2) + + + + local ymax = math.max(pos[1].y,pos[2].y) + local ymin = math.min(pos[1].y,pos[2].y) + local shift_up = ymax - ymin + 1 + local shift_vector = { x= 0, y = shift_up , z= 0 } + copy(pos[1],pos[2],shift_vector) + shift_selection(user,shift_vector) + + + if not vector.equals(mesecons_autotools.get_stack_direction(user),{x=0,y=1,z=0}) then + mesecons_autotools.zero_stack_counter(user); + end + + + mesecons_autotools.inc_stack_counter(user) + mesecons_autotools.set_stack_direction(user, { x=0,y=1,z=0 } ) + + + -- Update + mesecons_autotools.render(user) + + + +end + + +local function stack_remove(user) + if not mesecons_autotools.is_full_selection(user) then return end + + + local pos = {} + pos[1] = mesecons_autotools.get_pos(user,1) + pos[2] = mesecons_autotools.get_pos(user,2) + + + + local ymax = math.max(pos[1].y,pos[2].y) + local ymin = math.min(pos[1].y,pos[2].y) + local shift_down = ymax - ymin + 1 + local shift_vector = { x= 0, y = -shift_down , z= 0 } + + if mesecons_autotools.get_stack_counter(user) == 0 then + return + end + + if not vector.equals(mesecons_autotools.get_stack_direction(user),{x=0,y=1,z=0}) then return end + + delete(pos[1],pos[2]) + shift_selection(user,shift_vector) + + mesecons_autotools.dec_stack_counter(user) + + + + -- Update + mesecons_autotools.render(user) +end + + + + +mesecons_autotools.register_action("orange_up","left","air", function(user,pos,rad) + stack_remove(user) +end) +mesecons_autotools.register_action("orange_up","left","block", function(user,pos,rad) + stack_remove(user) +end) + +mesecons_autotools.register_action("orange_up","right","block", function(user,pos,rad) + stack_up(user) +end) + +mesecons_autotools.register_action("orange_up","right","air", function(user,pos,rad) + stack_up(user) +end) + + + \ No newline at end of file diff --git a/mesecons_autotools_tmp/tools/red/red.lua b/mesecons_autotools_tmp/tools/red/red.lua new file mode 100644 index 0000000..d5bffbf --- /dev/null +++ b/mesecons_autotools_tmp/tools/red/red.lua @@ -0,0 +1,43 @@ + + + + +mesecons_autotools.register_action("red","left","air", function(user,pos,rad) + + +end) +mesecons_autotools.register_action("red","left","block", function(user,pos,rad,under) + --minetest.set_node(under,{name="air"}) + mesecons_autotools.set_node(under,{name="air"},"red") +end) + +mesecons_autotools.register_action("red","right","block", function(user,pos,rad,under) + local sel = {} + sel.pos1 = mesecons_autotools.get_pos(user,1) + sel.pos2 = mesecons_autotools.get_pos(user,2) + if is_in_selection(sel,under) then + iterate_selection(sel.pos1,sel.pos2,function(p) + delete_node(p) + end) + else + if is_circuit_element(under) then + delete_node(under) + end + + end + + +end) + +mesecons_autotools.register_action("red","right","air", function(user,pos,rad) + if not mesecons_autotools.is_full_selection(user) then return end + + local pos = {} + pos[1] = mesecons_autotools.get_pos(user,1) + pos[2] = mesecons_autotools.get_pos(user,2) + + delete(pos[1],pos[2]) +end) + + + \ No newline at end of file diff --git a/mesecons_autotools_tmp/tools/refresh/refresh.lua b/mesecons_autotools_tmp/tools/refresh/refresh.lua new file mode 100644 index 0000000..b0bef77 --- /dev/null +++ b/mesecons_autotools_tmp/tools/refresh/refresh.lua @@ -0,0 +1,105 @@ + + +function is_mese(node) + if node.name == "default:mese" or + node.name == "mesecons_extrawires:mese_powered" then + return true + else + return false + end + +end + +function mese_off(node) + local n = {} + if is_mese(node) then + n.name = "default:mese" + n.param2 = node.param2 + return n + else + return node + end +end + + + + +function wire_off(node) + local n = {} + local name = node.name + n.param2 = node.param2 + + if is_wire_node(node) then + if string.match(name, "^mesecons_extrawires:crossover_") ~= nil then + n.name = "mesecons_extrawires:crossover_off" + return n + else + local base,state = string.match(name, "^(.*)_([^_]+)$") + base = base or "" + state = state or "" + + local name_off = base .. "_" .. "off" + n.name = name_off + return n + end + + else + return node + end +end + + + +local function refresh_selection(pos1,pos2) + iterate_selection(pos1,pos2, function(pos) + -- mesecon.on_placenode(pos,minetest.get_node(pos)) + + local node = minetest.get_node(pos) + local new_node = wire_off(node) + + + + local cur_node = minetest.get_node(pos) + mesecon.on_dignode(pos,cur_node) + ref_remove(pos,cur_node) + + minetest.set_node(pos,new_node) + mesecon.on_placenode(pos,new_node) + ref_place(pos,new_node) + + end) + +end + + + +mesecons_autotools.register_action("refresh","left","air", function(user,pos,rad) + + +end) +mesecons_autotools.register_action("refresh","left","block", function(user,pos,rad) + --mesecon.on_placenode(pos, minetest.get_node(pos)) + refresh_selection(pos,pos) +end) + +mesecons_autotools.register_action("refresh","right","block", function(user,pos,rad) + if not mesecons_autotools.is_full_selection(user) then return end + + local pos1 = mesecons_autotools.get_pos(user,1) + local pos2 = mesecons_autotools.get_pos(user,2) + refresh_selection(pos1,pos2) + +end) + +mesecons_autotools.register_action("refresh","right","air", function(user,pos,rad) + if not mesecons_autotools.is_full_selection(user) then return end + + local pos1 = mesecons_autotools.get_pos(user,1) + local pos2 = mesecons_autotools.get_pos(user,2) + refresh_selection(pos1,pos2) +end) + + + + + \ No newline at end of file diff --git a/mesecons_autotools_tmp/tools/selection.lua b/mesecons_autotools_tmp/tools/selection.lua new file mode 100644 index 0000000..42271f8 --- /dev/null +++ b/mesecons_autotools_tmp/tools/selection.lua @@ -0,0 +1,135 @@ +function iterate_selection(pos1,pos2,action) + local xmin = math.min(pos1.x,pos2.x) + local ymin = math.min(pos1.y,pos2.y) + local zmin = math.min(pos1.z,pos2.z) + + local xmax = math.max(pos1.x,pos2.x) + local ymax = math.max(pos1.y,pos2.y) + local zmax = math.max(pos1.z,pos2.z) + + + for ix = xmin,xmax,1 do + for iy = ymin,ymax,1 do + for iz = zmin,zmax,1 do + action({x=ix,y=iy,z=iz}) + end + end + end + +end + +function iterate_list(list,action) + for _,v in ipairs(list) do + action(v) + end +end + + +-- not tested, not used +function copy_safe(pos1,pos2,shift_vector) + local buffor = {} + copy_to_buffor(pos1,pos2,buffor) + paste_from_buffor(shift_vector,buffor) +end + + +function copy(pos1,pos2, shift_vector) + iterate_selection(pos1,pos2, function(pos) + local node = minetest.get_node(pos) + local new_pos = vector.add(pos,shift_vector) + --minetest.set_node(new_pos, node) + mesecons_autotools.set_node(new_pos, node,"copy") + end) +end + +function copy_to_buffor(pos1,pos2,buffor) + iterate_selection(pos1,pos2, function(pos) + local node = minetest.get_node(pos) + table.insert(buffor, { pos = pos, node = node } ) + end) + +end + +function paste_from_buffor(shift_vector,buffor) + for _,v in pairs(buffor) do + local pos = v.pos + local node = v.node + + local new_pos = vector.add(pos,shift_vector) + + --minetest.set_node(new_pos,node) + mesecons_autotools.set_node(new_pos,node,"paste_from_buffor") + end + +end + + + +function delete(pos1,pos2) + iterate_selection(pos1,pos2, function(pos) + minetest.set_node(pos,{ name = "air" } ) + end) + +end + + + +function shift_selection(user,shift_vector) + if not mesecons_autotools.is_full_selection(user) then return end + + local pos = {} + pos[1] = mesecons_autotools.get_pos(user,1) + pos[2] = mesecons_autotools.get_pos(user,2) + + + mesecons_autotools.set_pos(user,1, vector.add(pos[1],shift_vector)) + mesecons_autotools.set_pos(user,2, vector.add(pos[2],shift_vector)) + + + +end + +function is_one_block(pos1,pos2) + if (pos1.x ~= pos2.x ) then return false end + if pos1.y ~= pos2.y then return false end + if pos1.z ~= pos2.z then return false end + return true +end + +function is_empty_selection(pos1,pos2) + local list = {} + iterate_selection(pos1,pos2, function(pos) + local node = minetest.get_node(pos) + local name = node.name + if name ~= "air" then + table.insert(list,1) + end + end) + for _,v in ipairs(list) do + if v == 1 then + return false + end + end + return true + +end + +function is_tower_selection(pos1,pos2) + if pos1.x == pos2.x and pos1.z == pos2.z then return true end + return false +end + + +function size_by_direction(pos1,pos2,direction) + local dx = math.abs(pos1.x - pos2.x) +1 + local dy = math.abs(pos1.y - pos2.y) +1 + local dz = math.abs(pos1.z - pos2.z) +1 + + if direction.x ~= 0 then return dx end + if direction.y ~= 0 then return dy end + if direction.z ~= 0 then return dz end + + return 0 +end + + diff --git a/mesecons_autotools_tmp/tools/test/test.lua b/mesecons_autotools_tmp/tools/test/test.lua new file mode 100644 index 0000000..8d2d9f9 --- /dev/null +++ b/mesecons_autotools_tmp/tools/test/test.lua @@ -0,0 +1,23 @@ + +mesecons_autotools.register_action("test","left","air", function(user,pos,rad) + +end) +mesecons_autotools.register_action("test","left","block", function(user,pos,rad) + local node = minetest.get_node(pos) + print ("rules[" .. dump(mesecon.get_any_rules(node)) .. "]" ) +end) + +mesecons_autotools.register_action("test","right","block", function(user,pos,rad) + +end) + +mesecons_autotools.register_action("test","right","air", function(user,pos,rad) + local pos1 = mesecons_autotools.get_pos(user,1) + local pos2 = mesecons_autotools.get_pos(user,2) + + print ("D=pos1="..dump(pos1) .. ", pos2="..dump(pos2)) +end) + + + + \ No newline at end of file diff --git a/mesecons_autotools_tmp/tools/white/white.lua b/mesecons_autotools_tmp/tools/white/white.lua new file mode 100644 index 0000000..2813b9a --- /dev/null +++ b/mesecons_autotools_tmp/tools/white/white.lua @@ -0,0 +1,151 @@ + +local function get_right_nr(user,rad) + local dir = radians_to_vectors(rad) + local left = dir.left + local right = dir.right + + local lpos = {} + lpos[1] = mesecons_autotools.get_pos(user,1) + lpos[2] = mesecons_autotools.get_pos(user,2) + local posrigth_number + + if lpos[1] == nil then return end + if lpos[2] == nil then return end + + + + + if right.x == 1 then + if lpos[1].x > lpos[2].x then + posrigth_number = 1 + else + posrigth_number = 2 + end + elseif right.x == -1 then + if lpos[1].x > lpos[2].x then + posrigth_number = 2 + else + posrigth_number = 1 + end + elseif right.z == 1 then + if lpos[1].z > lpos[2].z then + posrigth_number = 1 + else + posrigth_number =2 + end + elseif right.z == -1 then + if lpos[1].z > lpos[2].z then + posrigth_number = 2 + else + posrigth_number = 1 + end + + end + + return posrigth_number + +end + + +local function move_right(user,rad) + local dir = radians_to_vectors(rad) + local left = dir.left + local right = dir.right + + local right_nr = get_right_nr(user,rad) + local lpos = {} + lpos[1] = mesecons_autotools.get_pos(user,1) + lpos[2] = mesecons_autotools.get_pos(user,2) + + + if right == nil then return end + if right_nr == nil then return end + if lpos[1] == nil then return end + if lpos[2] == nil then return end + + + local new_pos = vector.add(lpos[right_nr], right) + mesecons_autotools.set_pos(user,right_nr, new_pos) + + -- Update + mesecons_autotools.render(user) + mesecons_autotools.zero_stack_counter(user) +end + +local function can_shrink(user,right) + local lpos = {} + lpos[1] = mesecons_autotools.get_pos(user,1) + lpos[2] = mesecons_autotools.get_pos(user,2) + + if right == nil then return end + if lpos[1] == nil then return end + if lpos[2] == nil then return end + + if right.x ~= 0 then + if lpos[1].x == lpos[2].x then + return false + else + return true + end + end + + if right.z ~= 0 then + if lpos[1].z == lpos[2].z then + return false + else + return true + end + end +end + + +local function move_left(user,rad) + local dir = radians_to_vectors(rad) + local left = dir.left + local right = dir.right + + + if can_shrink(user,right) == false then return end + + + local right_nr = get_right_nr(user,rad) + local lpos = {} + lpos[1] = mesecons_autotools.get_pos(user,1) + lpos[2] = mesecons_autotools.get_pos(user,2) + + + if left == nil then return end + if lpos[1] == nil then return end + if lpos[2] == nil then return end + + + + local new_pos = vector.add(lpos[right_nr], left) + mesecons_autotools.set_pos(user,right_nr, new_pos) + + -- Update + mesecons_autotools.render(user) + mesecons_autotools.zero_stack_counter(user) + +end + + +mesecons_autotools.register_action("white","left","air", function(user,pos,rad) + move_left(user,rad) + + +end) +mesecons_autotools.register_action("white","left","block", function(user,pos,rad) + move_left(user,rad) +end) + +mesecons_autotools.register_action("white","right","block", function(user,pos,rad) + move_right(user,rad) +end) + +mesecons_autotools.register_action("white","right","air", function(user,pos,rad) + move_right(user,rad) +end) + + + \ No newline at end of file diff --git a/mesecons_autotools_tmp/tools/white_down/white_down.lua b/mesecons_autotools_tmp/tools/white_down/white_down.lua new file mode 100644 index 0000000..9ee2f33 --- /dev/null +++ b/mesecons_autotools_tmp/tools/white_down/white_down.lua @@ -0,0 +1,72 @@ + +local function move_up(user) + local vector_up = vector.new(0,1,0) + + + local lpos = {} + lpos[1] = mesecons_autotools.get_pos(user,1) + lpos[2] = mesecons_autotools.get_pos(user,2) + local posdown_number + + if lpos[1] == nil then return end + if lpos[2] == nil then return end + + if lpos[1].y == lpos[2].y then return end + + if lpos[1].y < lpos[2].y then + posdown_number = 1 + else + posdown_number = 2 + end + + local new_pos = vector.add(lpos[posdown_number], vector_up) + mesecons_autotools.set_pos(user,posdown_number, new_pos) + + -- Update + mesecons_autotools.render(user) + mesecons_autotools.zero_stack_counter(user) + +end + +local function move_down(user) + local vector_up = vector.new(0,-1,0) + + + local lpos = {} + lpos[1] = mesecons_autotools.get_pos(user,1) + lpos[2] = mesecons_autotools.get_pos(user,2) + local posdown_number + + if lpos[1] == nil then return end + if lpos[2] == nil then return end + + + + if lpos[1].y < lpos[2].y then + posdown_number = 1 + else + posdown_number = 2 + end + + local new_pos = vector.add(lpos[posdown_number], vector_up) + mesecons_autotools.set_pos(user,posdown_number, new_pos) + + -- Update + mesecons_autotools.render(user) + mesecons_autotools.zero_stack_counter(user) +end + +mesecons_autotools.register_action("white_down","left","air", function(user,pos,rad) + move_down(user); +end) +mesecons_autotools.register_action("white_down","left","block", function(user,pos,rad) + move_down(user); +end) + +mesecons_autotools.register_action("white_down","right","block", function(user,pos,rad) + move_up(user); +end) + +mesecons_autotools.register_action("white_down","right","air", function(user,pos,rad) + move_up(user); +end) diff --git a/mesecons_autotools_tmp/tools/white_up/white_up.lua b/mesecons_autotools_tmp/tools/white_up/white_up.lua new file mode 100644 index 0000000..92cb15d --- /dev/null +++ b/mesecons_autotools_tmp/tools/white_up/white_up.lua @@ -0,0 +1,73 @@ + +local function move_up(user) + local vector_up = vector.new(0,1,0) + + + local lpos = {} + lpos[1] = mesecons_autotools.get_pos(user,1) + lpos[2] = mesecons_autotools.get_pos(user,2) + local posup_number + + + + + if lpos[1] == nil then return end + if lpos[2] == nil then return end + + if lpos[1].y > lpos[2].y then + posup_number = 1 + else + posup_number = 2 + end + + local new_pos = vector.add(lpos[posup_number], vector_up) + mesecons_autotools.set_pos(user,posup_number, new_pos) + + -- Update + mesecons_autotools.render(user) + mesecons_autotools.zero_stack_counter(user) + +end + +local function move_down(user) + local vector_up = vector.new(0,-1,0) + + + local lpos = {} + lpos[1] = mesecons_autotools.get_pos(user,1) + lpos[2] = mesecons_autotools.get_pos(user,2) + local posup_number + + if lpos[1] == nil then return end + if lpos[2] == nil then return end + + if lpos[1].y == lpos[2].y then return end + + if lpos[1].y > lpos[2].y then + posup_number = 1 + else + posup_number = 2 + end + + local new_pos = vector.add(lpos[posup_number], vector_up) + mesecons_autotools.set_pos(user,posup_number, new_pos) + + -- Update + mesecons_autotools.render(user) + mesecons_autotools.zero_stack_counter(user) +end + +mesecons_autotools.register_action("white_up","left","air", function(user,pos,rad) + move_down(user); +end) +mesecons_autotools.register_action("white_up","left","block", function(user,pos,rad) + move_down(user); +end) + +mesecons_autotools.register_action("white_up","right","block", function(user,pos,rad) + move_up(user); +end) + +mesecons_autotools.register_action("white_up","right","air", function(user,pos,rad) + move_up(user); +end) diff --git a/mesecons_autotools_tmp/tools/wire.lua b/mesecons_autotools_tmp/tools/wire.lua new file mode 100644 index 0000000..eec7a8e --- /dev/null +++ b/mesecons_autotools_tmp/tools/wire.lua @@ -0,0 +1,445 @@ + + +function get_node_from_pins(pins) + local t = "mesecons_extrawires:tjunction_off" + local c = "mesecons_extrawires:corner_off" + local w = "mesecons_insulated:insulated_off" + local a = "air" + local x = "mesecons_morewires:xjunction_off" + + -- {left,up,right,down node_name, rotation} + local list = { + -- empty + {0,0,0,0,a,0}, + + -- wire + {1,0,1,0,w,0}, + {0,1,0,1,w,1}, + + -- corner + {1,0,0,1,c,0}, + {1,1,0,0,c,1}, + {0,1,1,0,c,2}, + {0,0,1,1,c,3}, + + -- tjunction + {1,0,1,1,t,0}, + {1,1,0,1,t,1}, + {1,1,1,0,t,2}, + {0,1,1,1,t,3}, + + -- xjunction + {1,1,1,1,x,0}, + + -- starting wire + {1,0,0,0,w,0}, + {0,1,0,0,w,1}, + {0,0,1,0,w,0}, + {0,0,0,1,w,1}, + } + + local node_name = "air" + local rotate = 0 + for _,v in ipairs(list) do + if (pins[1] == v[1]) and + (pins[2] == v[2]) and + (pins[3] == v[3]) and + (pins[4] == v[4]) then + + node_name = v[5] + rotate = v[6] + + end + + end + + return { name = node_name, param2 = rotate } + + +end + +function get_pins_from_pos(pos,type) + local node = minetest.get_node(pos) + + local rs = {} + if type == "input" then + rs = mesecon.get_any_inputrules(node) + elseif type == "output" then + rs = mesecon.get_any_outputrules(node) + else + rs = mesecon.get_any_rules(node) + end + if rs == nil then + rs = {} + else + rs = mesecon.flattenrules (rs) + end + + + -- Filter only y=0 + local list = {} + for _,v in pairs(rs) do + if v.y == 0 then + if v.x ~= 0 and v.z == 0 then + table.insert(list,v) + end + if v.z ~= 0 and v.x == 0 then + table.insert(list,v) + end + + end + end + + -- constructiong pin structure + + local pins = {0,0,0,0} + for _,v in pairs(list) do + if v.x == 1 then pins[3] = 1 end + if v.x == -1 then pins[1] = 1 end + if v.z == 1 then pins[2] = 1 end + if v.z == -1 then pins[4] = 1 end + end + return pins +end + + + +local function dir_to_inx(d) + if d.x == 1 then return 3 end + if d.x == -1 then return 1 end + if d.z == 1 then return 2 end + if d.z == -1 then return 4 end + return 1 +end + +function get_pin_from_direction(direction) + return dir_to_inx(direction) +end + + + +local function neighbours_pins(pos) + local npins = {0,0,0,0} + for _,ix in ipairs({1,-1}) do + + local shift = { x=ix,y=0,z=0 } + local neigh = vector.add(pos,shift) + + local pins = get_pins_from_pos(neigh) + npins[ dir_to_inx( shift) ] = pins [ dir_to_inx( vector.multiply(shift,-1) ) ] + end + for _,iz in ipairs({1,-1}) do + + local shift = { x=0,y=0,z=iz } + local neigh = vector.add(pos,shift) + + local pins = get_pins_from_pos(neigh) + npins[ dir_to_inx( shift) ] = pins [ dir_to_inx( vector.multiply(shift,-1) ) ] + end + return npins +end + + +local function pins_and(pins1,pins2) + local pout = {} + for i=1,4,1 do + pout[i] = pins1[i] * pins2[i] + end + return pout + +end + + +local function start_node(pos,direction) + + local node = minetest.get_node(pos) + local name = node.name + + -- Only wires changed + local list = { + "mesecons_insulated:insulated_off","mesecons_insulated:insulated_on", + "mesecons_extrawires:corner_off","mesecons_extrawires:corner_on", + "mesecons_extrawires:tjunction_off", "mesecons_extrawires:tjunction_on", + "air" + } + + if not is_in_list(list,name) then return end + + + local npins = neighbours_pins(pos) + local mypins = get_pins_from_pos(pos) + local compins = pins_and(npins,mypins) + + -- adding wire + + if direction.x == 1 then + compins[3] = 1 + end + if direction.x == -1 then + compins[1] = 1 + end + + if direction.z == 1 then + compins[2] = 1 + end + if direction.z == -1 then + compins[4] = 1 + end + + --merge_wire(pos,direction) + local new_node = get_node_from_pins(compins) + + --minetest.set_node(pos,new_node) + mesecons_autotools.set_node(pos,new_node,"start_node") +end + +local function end_node(pos,direction) + --merge_wire(pos, vector.multiply(direction, -1)) + start_node(pos, vector.multiply(direction,-1)) +end + + +local function middle_node(pos, direction) + local node = minetest.get_node(pos) + local name = node.name + local param2 = node.param2 + + --minetest.set_node(pos,{name = "default:dirt"}) + --if true then return end + + if name ~= "mesecons_insulated:insulated_off" and + name ~= "mesecons_insulated:insulated_on" and + name ~= "air" then + return + end + + -- do crossing + if name == "air" then + local prm2 = 0 + if direction.z ~= 0 then + prm2 = 1 + end + if direction.x ~= 0 then + prm2 = 0 + end + --minetest.set_node(pos, { name ="mesecons_insulated:insulated_off", param2= 1 } ) + mesecons_autotools.set_node(pos, + {name ="mesecons_insulated:insulated_off", param2= prm2 }, + "middle_node") + + else + -- if nothing to do + if (direction.x ~= 0 ) and + ( param2 == 0 or param2 == 2 ) then + return + end + if (direction.z ~= 0 ) and + (param2 == 1 or param2 == 3 ) then + return + end + + --minetest.set_node(pos,{ name ="mesecons_extrawires:crossover_off" } ) + mesecons_autotools.set_node(pos, + { name ="mesecons_extrawires:crossover_off" }, + "middle_node") + + end +end + + +function create_straight_wire_n(pos,direction,size) + local current = pos + + -- first + start_node(current,direction) + current = vector.add(current,direction) + + -- middle + for i = 2, size-1, 1 do + middle_node(current,direction) + current = vector.add(current,direction) + + end + + -- last + end_node(current,direction) +end + +local function distance_taxi_metric(pos1,pos2) + local x1 = pos1.x + local x2 = pos2.x + + local dx = math.abs(x2-x1) + + local z1 = pos1.z + local z2 = pos2.z + + local dz = math.abs(z2-z1) + + return dz+dx+1 +end + + +function create_straight_wire(pos1,pos2) + + -- Check if straight line + if pos1.y ~= pos2.y then return end + if (pos1.x ~= pos2.x ) and (pos1.z ~= pos2.z) then return end + + + + -- Compute direction + local direction = { x =0,y=0,z=0} + if pos1.x == pos2.x then + if pos1.z < pos2.z then + direction.z = 1 + else + direction.z = -1 + end + end + if pos1.z == pos2.z then + if pos1.x < pos2.x then + direction.x = 1 + else + direction.x = -1 + end + end + + + -- Compute size + local size = distance_taxi_metric(pos1,pos2) + + + create_straight_wire_n(pos1,direction,size) + return true +end + +function hop_pos(pos,pin) + local new_pos = { x = pos.x, y = pos.y, z = pos.z } + + if pin == 1 then + new_pos.x = pos.x - 1 + end + if pin == 2 then + new_pos.z = pos.z + 1 + end + if pin == 3 then + new_pos.x = pos.x + 1 + end + if pin == 4 then + new_pos.z = pos.z -1 + end + + return new_pos +end + +function flip_pin(pin) + if pin == 1 then return 3 end + if pin == 2 then return 4 end + if pin == 3 then return 1 end + if pin == 4 then return 2 end +end + +-- TODO: refactor +function hop_pin(pin) + if pin == 1 then return 3 end + if pin == 2 then return 4 end + if pin == 3 then return 1 end + if pin == 4 then return 2 end +end + + + +local function delete(p,pin) + local node = minetest.get_node(p) + local name = node.name + + if name == "mesecons_insulated:insulated_off" or + name == "mesecons_insulated:insulated_on" or + name == "mesecons_extrawires:corner_off" or + name == "mesecons_extrawires:corner_on" + then + + -- continue deleting + local node_pins = get_pins_from_pos(p) + + -- not connected to anything + if node_pins[pin] == 0 then return end + + node_pins[pin] = 0 + for i=1,4,1 do + if node_pins[i] == 1 then + --minetest.set_node(p,{name="air"}) + mesecons_autotools.set_node(p,{name="air"},"delete") + delete(hop_pos(p,i),hop_pin(i)) + end + end + + + + elseif name == "mesecons_extrawires:crossover_off" or + name == "mesecons_extrawires:crossover_on" or + name == "mesecons_extrawires:crossover_10" or + name == "mesecons_extrawires:crossover_01" then + + -- continue deleting + + local node_pins = get_pins_from_pos(p) + node_pins[pin] = 0 + node_pins[hop_pin(pin)] = 0 + + local new_node = get_node_from_pins(node_pins) + -- minetest.set_node(p,new_node) + mesecons_autotools.set_node(p,new_node,"delete_crossover") + delete(hop_pos(p,hop_pin(pin)),pin) + + + + elseif name == "mesecons_extrawires:tjunction_off" or + name == "mesecons_extrawires:tjunction_on" or + name == "mesecons_morewires:xjunction_off" or + name == "mesecons_morewires:xjunction_on" then + + -- end of wire + + local node_pins = get_pins_from_pos(p) + + -- not connected to anything + if node_pins[pin] == 0 then return end + + node_pins[pin] = 0 + local new_node = get_node_from_pins(node_pins) + --minetest.set_node(p,new_node) + mesecons_autotools.set_node(p,new_node,"delete_end") + + + + else + -- do nothing (other blocks) + end +end + + +function delete_node(pos) + local node = minetest.get_node(pos) + + local pins = get_pins_from_pos(pos) + + --minetest.set_node(pos,{name="air"}) + mesecons_autotools.set_node(pos,{name="air"},"delete") + + for i=1,4,1 do + if pins[i] == 1 then + delete(hop_pos(pos,i),hop_pin(i)) + end + end + + +end + + + + + + + diff --git a/mesecons_autotools_tmp/tools/yellow/yellow.lua b/mesecons_autotools_tmp/tools/yellow/yellow.lua new file mode 100644 index 0000000..5b16542 --- /dev/null +++ b/mesecons_autotools_tmp/tools/yellow/yellow.lua @@ -0,0 +1,218 @@ + +function can_move_into(sel,direction) + local front_wall = front_wall_by_direction(sel,direction) + + local pos1 = vector.new(front_wall.pos1) + local pos2 = vector.new(front_wall.pos2) + + pos1 = vector.add(pos1,direction) + pos2 = vector.add(pos2,direction) + + local shifted ={pos1=pos1,pos2=pos2} + + local result = {} + iterate_selection(pos1,pos2, function(pos) + local node = minetest.get_node(pos) + local name = node.name + + if name == "air" then + return + end + if + name == "mesecons_insulated:insulated_off" or + name == "mesecons_insulated:insulated_on" then + + local pins = get_pins_from_pos(pos) + local dpin = get_pin_from_direction(direction) + if pins[dpin] == 1 then + return + else + table.insert(result,false) + return + end + + + end + return table.insert(result,false) + end) + + for _,v in pairs(result) do + if v == false then + return false + end + end + + return true +end + + +function is_pos_connected(pos,direction) + local node = minetest.get_node(pos) + + local pins = get_pins_from_pos(pos) + local dpin = get_pin_from_direction(direction) + + -- no sticking out + if pins[dpin] == 0 then return false end + + + local neigh_pos + local neigh_pins + local connect_pin + + -- checking pos[out] <-> neigh[in] + + pins = get_pins_from_pos(pos,"output") + dpin = get_pin_from_direction(direction) + neigh_pos = hop_pos(pos,dpin) + neigh_pins = get_pins_from_pos(neigh_pos,"input") + connect_pin = neigh_pins[ hop_pin(dpin) ] + + if connect_pin == 1 then + return true + end + + -- checking pos[in] <-> neidth[out] + + pins = get_pins_from_pos(pos,"input") + dpin = get_pin_from_direction(direction) + neigh_pos = hop_pos(pos,dpin) + neigh_pins = get_pins_from_pos(neigh_pos,"output") + connect_pin = neigh_pins[ hop_pin(dpin) ] + + if connect_pin == 1 then + return true + end + + + + return false + + + +--[[ + local neigh_pos = hop_pos(pos,dpin) + local neigh_pins = get_pins_from_pos(neigh_pos) + local connect_pin = neigh_pins[ hop_pin(dpin) ] + + if connect_pin == 1 then + return true + else + return false + end +]]-- +end + + +function generate_tail_wires(back_wall,direction) + local pos1 = back_wall.pos1 + local pos2 = back_wall.pos2 + + local back_direction = vector.multiply(direction,-1) + local bd_pin = get_pin_from_direction(back_direction) + + + local list_pos = {} + iterate_selection(pos1,pos2, function(pos) + if is_pos_connected(pos,back_direction) then + table.insert(list_pos,pos) + end + end) + return list_pos +end + +function put_tail_wires(list,direction) + local node = {} + node.name = "mesecons_insulated:insulated_off" + node.param2 = 0 + for _,pos in ipairs(list) do + if direction.x ~= 0 then + node.param2 = 0 + else + node.param2 = 1 + end + --minetest.set_node(pos,node) + mesecons_autotools.set_node(pos,node,"put_tail_wires") + + end + +end + + +function get_back_wall(sel,direction) + return front_wall_by_direction(sel, vector.multiply(direction,-1)) +end + + + + +local function move_selection(user,rad,click) + local dir = radians_to_vectors(rad) + local left = dir.left + local right = dir.right + + local pos = {} + pos[1] = mesecons_autotools.get_pos(user,1) + pos[2] = mesecons_autotools.get_pos(user,2) + + + if pos[1] == nil then return end + if pos[2] == nil then return end + + + -- compute shift vector + + local direction = {} + if click == "left" then + direction = left + else + direction = right + end + + local buffor = {} + local tail = {} + local sel = { pos1=pos[1], pos2=pos[2]} + local back_wall = get_back_wall(sel,direction) + + if not can_move_into(sel,direction) then return end + + copy_to_buffor(pos[1],pos[2],buffor) + tail = generate_tail_wires(back_wall,direction) + + + delete(pos[1],pos[2]) + paste_from_buffor(direction,buffor) + put_tail_wires(tail,direction) + + shift_selection(user,direction) + + + -- Update + mesecons_autotools.render(user) + mesecons_autotools.zero_stack_counter(user) + mesecons_autotools.zero_stack_direction(user) +end + + + + + + +mesecons_autotools.register_action("yellow","left","air", function(user,pos,rad) + move_selection(user,rad,"left") +end) +mesecons_autotools.register_action("yellow","left","block", function(user,pos,rad) + move_selection(user,rad,"left") +end) + +mesecons_autotools.register_action("yellow","right","block", function(user,pos,rad) + move_selection(user,rad,"right") +end) + +mesecons_autotools.register_action("yellow","right","air", function(user,pos,rad) + move_selection(user,rad,"right") +end) + + + + \ No newline at end of file diff --git a/mesecons_autotools_tmp/tools/yellow_updown/yellow_updown.lua b/mesecons_autotools_tmp/tools/yellow_updown/yellow_updown.lua new file mode 100644 index 0000000..6765274 --- /dev/null +++ b/mesecons_autotools_tmp/tools/yellow_updown/yellow_updown.lua @@ -0,0 +1,73 @@ + + + + +local function move_selection(user,rad,click) + local pos = {} + pos[1] = mesecons_autotools.get_pos(user,1) + pos[2] = mesecons_autotools.get_pos(user,2) + + + if pos[1] == nil then return end + if pos[2] == nil then return end + + + -- compute shift vector + + local shift_vector = {} + if click == "up" then + shift_vector = {x=0,y=1,z=0} + else + shift_vector = {x=0,y=-1,z=0} + end + + local new_pos1 = vector.add(pos[1],shift_vector) + local new_pos2 = vector.add(pos[2],shift_vector) + + + --[[ + if not is_empty_selection(new_pos1,new_pos2) then + return + end + ]]-- + local sel = { pos1=pos[1], pos2=pos[2]} + if not can_move_into(sel,shift_vector) then return end + + + local buffor = {} + copy_to_buffor(pos[1],pos[2],buffor) + delete(pos[1],pos[2]) + paste_from_buffor(shift_vector,buffor) + + shift_selection(user,shift_vector) + + + -- Update + mesecons_autotools.render(user) + mesecons_autotools.zero_stack_counter(user) + mesecons_autotools.zero_stack_direction(user) + + +end + + + + + + +mesecons_autotools.register_action("yellow_updown","left","air", function(user,pos,rad) + move_selection(user,rad,"down") +end) +mesecons_autotools.register_action("yellow_updown","left","block", function(user,pos,rad) + move_selection(user,rad,"down") +end) + +mesecons_autotools.register_action("yellow_updown","right","block", function(user,pos,rad) + move_selection(user,rad,"up") +end) + +mesecons_autotools.register_action("yellow_updown","right","air", function(user,pos,rad) + move_selection(user,rad,"up") +end) + + \ No newline at end of file