diff options
author | cheapie <no-email-for-you@example.com> | 2024-04-12 20:48:19 -0500 |
---|---|---|
committer | cheapie <no-email-for-you@example.com> | 2024-04-12 20:48:19 -0500 |
commit | 23826516cac0cfa6ab3d50828862544cfe1d9f6b (patch) | |
tree | 2f86377630871b32db747a1b655b4b605a5c7a01 | |
parent | dab488531aabe5918fcd965299c71b8e239c5ace (diff) | |
download | celevator-23826516cac0cfa6ab3d50828862544cfe1d9f6b.tar celevator-23826516cac0cfa6ab3d50828862544cfe1d9f6b.tar.gz celevator-23826516cac0cfa6ab3d50828862544cfe1d9f6b.tar.bz2 celevator-23826516cac0cfa6ab3d50828862544cfe1d9f6b.tar.xz celevator-23826516cac0cfa6ab3d50828862544cfe1d9f6b.zip |
Add COP
Still more things I want to add to it, but it works for now.
Should show up in existing cars (once they do something for the first time, for now)
-rw-r--r-- | car.lua | 25 | ||||
-rw-r--r-- | controller.lua | 6 | ||||
-rw-r--r-- | controllerfw.lua | 46 | ||||
-rw-r--r-- | drive_entity.lua | 29 | ||||
-rw-r--r-- | drive_null.lua | 4 | ||||
-rw-r--r-- | textures/celevator_car_wallpaper_2x.png | bin | 0 -> 8738 bytes | |||
-rw-r--r-- | textures/celevator_cop.png | bin | 0 -> 1556 bytes | |||
-rw-r--r-- | textures/celevator_copbutton_lit.png | bin | 0 -> 683 bytes | |||
-rw-r--r-- | textures/celevator_copbutton_unlit.png | bin | 0 -> 652 bytes |
9 files changed, 108 insertions, 2 deletions
@@ -118,7 +118,7 @@ local pieces = { tiles = { "celevator_cabinet_sides.png", "celevator_cabinet_sides.png", - "celevator_car_wallpaper.png", + "celevator_car_wallpaper_2x.png^celevator_cop.png", "celevator_cabinet_sides.png", }, }, @@ -344,6 +344,19 @@ for _,def in ipairs(pieces) do def.drawtype = "nodebox" def.description = "Car "..def._position def.light_source = 9 + def.on_receive_fields = function(pos,_,fields,player) + local meta = minetest.get_meta(pos) + local carid = meta:get_int("carid") + if carid == 0 then return end + local carinfo = minetest.deserialize(celevator.storage:get_string(string.format("car%d",carid))) + if not carinfo then return end + local event = { + type = "cop", + fields = fields, + player = player:get_player_name(), + } + celevator.controller.run(carinfo.controllerpos,event) + end minetest.register_node("celevator:car_"..def._position,def) end @@ -391,3 +404,13 @@ minetest.register_abm({ entity:set_pos(vector.add(pos,vector.multiply(fdir,0.44))) end, }) + +function celevator.car.updatecop(pos) + local copmeta = minetest.get_meta(pos) + local carid = copmeta:get_int("carid") + if carid == 0 then return end + local carinfo = minetest.deserialize(celevator.storage:get_string(string.format("car%d",carid))) + if not carinfo then return end + local controllermeta = minetest.get_meta(carinfo.controllerpos) + copmeta:set_string("formspec",controllermeta:get_string("copformspec")) +end diff --git a/controller.lua b/controller.lua index a36dee1..884f620 100644 --- a/controller.lua +++ b/controller.lua @@ -62,6 +62,8 @@ local function ondestruct(pos) end celevator.controller.equeue[minetest.hash_node_position(pos)] = nil celevator.storage:set_string("controller_equeue",minetest.serialize(celevator.controller.equeue)) + local carid = minetest.get_meta(pos):get_int("carid") + if carid ~= 0 then celevator.storage:set_string(string.format("car%d",carid),"") end end local function onrotate(controllerpos,node,user,mode,new_param2) @@ -490,6 +492,10 @@ function celevator.controller.finish(pos,mem,changedinterrupts) celevator.lantern.setlight(lantern.pos,"down",newlanterns[lantern.landing] == "down") end end + meta:set_string("copformspec",mem.copformspec) + if mem.copformspec ~= oldmem.copformspec and drivetype then + minetest.after(0.25,celevator.drives[drivetype].updatecopformspec,drivepos) + end meta:set_string("mem",minetest.serialize(mem)) if node.name == "celevator:controller_open" then meta:set_string("formspec",mem.formspec or "") end meta:set_string("formspec_hidden",mem.formspec or "") diff --git a/controllerfw.lua b/controllerfw.lua index a4efbec..e879175 100644 --- a/controllerfw.lua +++ b/controllerfw.lua @@ -439,6 +439,23 @@ elseif event.iid == "opentimeout" then fault("opentimeout",true) elseif event.iid == "closetimeout" then fault("closetimeout",true) +elseif event.type == "cop" then + local fields = event.fields + if mem.carstate == "normal" then + for k,v in pairs(fields) do + if string.sub(k,1,7) == "carcall" then + local landing = tonumber(string.sub(k,8,-1)) + if v and landing and landing >= 1 and landing <= #mem.params.floorheights then + mem.carcalls[landing] = true + end + end + end + if fields.close and mem.doorstate == "open" then + interrupt(0,"close") + elseif fields.open and mem.doorstate == "closed" and not (mem.carmotion or juststarted) then + open() + end + end end local oldstate = mem.carstate @@ -612,7 +629,7 @@ elseif mem.screenstate == "oobe_floortable" or mem.screenstate == "floortable" t fs(minetest.formspec_escape(string.format("%d - Height: %d - PI: %s",i,mem.params.floorheights[i],mem.params.floornames[i]))..(i==1 and "" or ",")) end fs(";"..tostring(#mem.params.floornames-mem.editingfloor+1)..";false]") - fs("button[8,2;2,1;add;New Floor]") + if #mem.params.floornames < 100 then fs("button[8,2;2,1;add;New Floor]") end fs("button[8,3.5;2,1;edit;Edit Floor]") if #mem.params.floornames > 2 then fs("button[8,5;2,1;remove;Remove Floor]") end if mem.editingfloor < #mem.params.floornames then fs("button[8,6.5;2,1;moveup;Move Up]") end @@ -775,4 +792,31 @@ if mem.carstate == "normal" and (mem.doorstate == "open" or mem.doorstate == "op mem.lanterns[getpos()] = mem.direction end +mem.copformspec = "formspec_version[7]" +local floorcount = #mem.params.floornames +local copcols = math.floor((floorcount-1)/10)+1 +local coprows = math.floor((floorcount-1)/copcols)+1 +local litimg = "celevator_copbutton_lit.png" +local unlitimg = "celevator_copbutton_unlit.png" +mem.copformspec = mem.copformspec..string.format("size[%f,%f]",copcols*1.25+2.5,coprows*1.25+4) +for i=1,floorcount,1 do + local row = math.floor((i-1)/copcols)+1 + local col = ((i-1)%copcols)+1 + local yp = (coprows-row+1)*1.25 + local xp = col*1.25 + local tex = mem.carcalls[i] and litimg or unlitimg + mem.copformspec = mem.copformspec..string.format("image_button[%f,%f;1,1;%s;carcall%d;%d;false;false;%s]",xp,yp,tex,i,i,litimg) +end + +local doxp = (copcols == 1) and 0.5 or 1.25 +mem.copformspec = mem.copformspec..string.format("image_button[%f,%f;1,1;%s;open;%s;false;false;%s]",doxp,coprows*1.25+1.5,unlitimg,minetest.formspec_escape("<|>"),litimg) + +local dcxp = 3.75 +if copcols == 1 then + dcxp = 2 +elseif copcols == 2 then + dcxp = 2.5 +end +mem.copformspec = mem.copformspec..string.format("image_button[%f,%f;1,1;%s;close;%s;false;false;%s]",dcxp,coprows*1.25+1.5,unlitimg,minetest.formspec_escape(">|<"),litimg) + return pos,mem,changedinterrupts diff --git a/drive_entity.lua b/drive_entity.lua index 62f0eda..2491e69 100644 --- a/drive_entity.lua +++ b/drive_entity.lua @@ -364,6 +364,7 @@ function celevator.drives.entity.step(dtime) celevator.car.spawncar(vector.round(vector.add(origin,vector.new(0,apos,0))),minetest.dir_to_yaw(minetest.fourdir_to_dir(carparam2)),carid) end apos = math.floor(apos+0.5) + minetest.after(0.25,celevator.drives.entity.updatecopformspec,pos) elseif dremain < 0.2 then vel = 0.2 elseif dremain < 2*maxvel and dremain < dmoved then @@ -404,6 +405,7 @@ function celevator.drives.entity.step(dtime) local carparam2 = meta:get_int("carparam2") celevator.car.spawncar(vector.round(vector.add(origin,vector.new(0,apos,0))),minetest.dir_to_yaw(minetest.fourdir_to_dir(carparam2)),carid) apos = math.floor(apos+0.5) + minetest.after(0.25,celevator.drives.entity.updatecopformspec,pos) elseif dremain < 0.2 then vel = 0.2 elseif dremain < 2*maxvel and dremain < dmoved then @@ -785,3 +787,30 @@ function celevator.drives.entity.sheavetonode(carid) param2 = minetest.dir_to_fourdir(dir), }) end + +function celevator.drives.entity.updatecopformspec(drivepos) + local entitydrives_running = minetest.deserialize(celevator.storage:get_string("entitydrives_running")) or {} + if entitydrives_running[minetest.hash_node_position(drivepos)] then return end + local drivemeta = minetest.get_meta(drivepos) + local carid = drivemeta:get_int("carid") + if carid == 0 then return end + local carinfo = minetest.deserialize(celevator.storage:get_string(string.format("car%d",carid))) + if not carinfo then return end + local formspec = minetest.get_meta(carinfo.controllerpos):get_string("copformspec") + local origin = minetest.string_to_pos(drivemeta:get_string("origin")) + if not origin then + minetest.log("error","[celevator] [entity drive] Invalid origin for drive at "..minetest.pos_to_string(drivepos)) + drivemeta:set_string("fault","badorigin") + return + end + local apos = tonumber(drivemeta:get_string("apos")) or 0 + local carpos = vector.add(origin,vector.new(0,apos,0)) + local carnodes = celevator.drives.entity.gathercar(carpos,minetest.dir_to_yaw(minetest.fourdir_to_dir(minetest.get_node(carpos).param2))) + for hash in pairs(carnodes) do + local piecepos = minetest.get_position_from_hash(hash) + local piece = minetest.get_node(piecepos) + if piece.name == "celevator:car_010" then + minetest.get_meta(piecepos):set_string("formspec",formspec) + end + end +end diff --git a/drive_null.lua b/drive_null.lua index 417d857..db4e394 100644 --- a/drive_null.lua +++ b/drive_null.lua @@ -230,3 +230,7 @@ function celevator.drives.null.resetfault(pos) --This drive has no possible faults at this time (drive communication faults are generated by the controller), but the controller expects to be able to call this minetest.get_meta(pos):set_string("fault","") end + +function celevator.drives.null.updatecopformspec() + --No car means no COP +end diff --git a/textures/celevator_car_wallpaper_2x.png b/textures/celevator_car_wallpaper_2x.png Binary files differnew file mode 100644 index 0000000..ed09932 --- /dev/null +++ b/textures/celevator_car_wallpaper_2x.png diff --git a/textures/celevator_cop.png b/textures/celevator_cop.png Binary files differnew file mode 100644 index 0000000..29f54d1 --- /dev/null +++ b/textures/celevator_cop.png diff --git a/textures/celevator_copbutton_lit.png b/textures/celevator_copbutton_lit.png Binary files differnew file mode 100644 index 0000000..c910883 --- /dev/null +++ b/textures/celevator_copbutton_lit.png diff --git a/textures/celevator_copbutton_unlit.png b/textures/celevator_copbutton_unlit.png Binary files differnew file mode 100644 index 0000000..7f27dc6 --- /dev/null +++ b/textures/celevator_copbutton_unlit.png |