Skip to content

Commit

Permalink
Merge pull request #14 from mt-mods/upstream-merge
Browse files Browse the repository at this point in the history
Upstream merge
  • Loading branch information
S-S-X committed Feb 23, 2021
2 parents ccc26a5 + b2369b3 commit 72b9d32
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 32 deletions.
40 changes: 27 additions & 13 deletions controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ local players_on_controller = {}

local last_seen_inputs = {}

local function removeEntity(pos)
local entitiesNearby = minetest.get_objects_inside_radius(pos,0.5)
for _,i in pairs(entitiesNearby) do
if i:get_luaentity() and i:get_luaentity().name == "digistuff:controller_entity" then
i:remove()
end
end
end

local function process_inputs(pos)
local meta = minetest.get_meta(pos)
local hash = minetest.hash_node_position(pos)
Expand All @@ -36,14 +45,6 @@ local function process_inputs(pos)
players_on_controller[hash] = nil
return
end
local distance = vector.distance(pos,player:get_pos())
if distance > 1 then
digilines.receptor_send(pos,digiline_rules,meta:get_string("channel"),"player_left")
minetest.get_meta(pos):set_string("infotext","Digilines Game Controller Ready\n(right-click to use)")
player:set_physics_override({speed = 1,jump = 1,})
players_on_controller[hash] = nil
return
end
local inputs = player:get_player_control()
inputs.pitch = player:get_look_vertical()
inputs.yaw = player:get_look_horizontal()
Expand Down Expand Up @@ -71,11 +72,14 @@ end
local function release_player(pos)
local hash = minetest.hash_node_position(pos)
local player = minetest.get_player_by_name(players_on_controller[hash])
if player then
player:set_physics_override({speed = 1,jump = 1,})
player:set_pos(vector.add(pos,vector.new(0.25,0,0.25)))
if player and player:get_properties()._is_gamecontroller then
local parent = player:get_attach()
if parent then
player:set_detach()
end
minetest.chat_send_player(players_on_controller[hash],"You are now free to move.")
end
removeEntity(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext","Digilines Game Controller Ready\n(right-click to use)")
last_seen_inputs[players_on_controller[hash]] = nil
Expand All @@ -92,8 +96,8 @@ local function trap_player(pos,player)
return
else
players_on_controller[hash] = newname
player:set_pos(vector.add(pos,vector.new(0,-0.4,0)))
player:set_physics_override({speed = 0,jump = 0,})
local entity = minetest.add_entity(pos,"digistuff:controller_entity")
player:set_attach(entity,"",vector.new(0,0,0),vector.new(0,0,0))
minetest.chat_send_player(newname,"You are now using a digilines game controller. Right-click the controller again to be released.")
local meta = minetest.get_meta(pos)
meta:set_string("infotext","Digilines Game Controller\nIn use by: "..newname)
Expand Down Expand Up @@ -201,6 +205,16 @@ minetest.register_node("digistuff:controller_programmed", {
},
})

minetest.register_entity("digistuff:controller_entity",{
initial_properties = {
visual = "sprite",
physical = false,
collisionbox = {0,0,0,0,0,0,},
textures = {"digistuff_transparent.png",},
_is_gamecontroller = true,
},
})

local acc_dtime = 0

minetest.register_globalstep(function(dtime)
Expand Down
1 change: 0 additions & 1 deletion docs/game-controller.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ When a player leaves a controller, the string "player_left" is sent.
In addition to right-clicking the controller in use to stop using it, the following will also cause a player to stop using the controller:
* The controller is moved or removed
* The player leaves the game
* The player is teleported away from the controller
* The controller receives the string "release" on its digilines channel
14 changes: 14 additions & 0 deletions docs/gpu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Example:
{command="send",buffer=0,channel="example"}
}

Invalid commands or commands with missing/invalid parameters will be ignored.

Command: createbuffer
---------------------
Expand All @@ -33,6 +34,19 @@ Parameters:
buffer [integer 0-7]: The buffer to send the contents of.
channel [string]: The digilines channel to send the message on.

Command: sendregion
-------------------

Sends part of the contents of a buffer to a digiscreen, rgblightstone panel, or other digilines device.

Parameters:
buffer [integer 0-7]: The buffer to send part of the contents of.
channel [string]: The digilines channel to send the message on.
x1 [integer 1-64]: The X position of the left side of the region to send.
x2 [integer 1-64]: The X position of the right side of the region to send.
y1 [integer 1-64]: The Y position of the top side of the region to send.
y2 [integer 1-64]: The Y position of the bottom side of the region to send.

Command: drawrect
-----------------

Expand Down
27 changes: 27 additions & 0 deletions gpu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,33 @@ local function runcommand(pos,meta,command)
if type(buffer) == "table" then
digilines.receptor_send(pos,digilines.rules.default,command.channel,buffer)
end
elseif command.command == "sendregion" then
if type(command.buffer) ~= "number" or type(command.channel) ~= "string" then return end
local bufnum = math.floor(command.buffer)
if bufnum < 0 or bufnum > 7 then return end
local buffer = meta:get_string("buffer"..bufnum)
if string.len(buffer) == 0 then return end
buffer = minetest.deserialize(buffer)
if type(buffer) ~= "table" then return end
if type(command.x1) ~= "number" or type(command.x2) ~= "number" or type(command.y1) ~= "number" or type(command.x2) ~= "number" then return end
local x1 = math.min(64,math.floor(command.x1))
local y1 = math.min(64,math.floor(command.y1))
local x2 = math.min(64,math.floor(command.x2))
local y2 = math.min(64,math.floor(command.y2))
if x1 < 1 or y1 < 1 or x2 < 1 or y2 < 1 then return end
x2 = math.min(x2,buffer.xsize)
y2 = math.min(y2,buffer.ysize)
if x1 > x2 or y1 > y2 then return end
local tempbuf = {}
for y=y1,y2,1 do
local dsty = y-y1+1
tempbuf[dsty] = {}
for x=x1,x2,1 do
local dstx = x-x1+1
tempbuf[dsty][dstx] = buffer[y][x]
end
end
digilines:receptor_send(pos,digilines.rules.default,command.channel,tempbuf)
elseif command.command == "drawrect" then
if type(command.buffer) ~= "number" or type(command.x1) ~= "number" or type(command.y1) ~= "number" or type(command.x2) ~= "number" or type(command.y2) ~= "number" then return end
local bufnum = math.floor(command.buffer)
Expand Down
5 changes: 3 additions & 2 deletions mod.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name = digistuff
description = Adds random digilines devices
title = digistuff
description = Random digilines devices for Minetest
depends = digilines
optional_depends = default, mesecons, mesecons_mvps, screwdriver, pipeworks
optional_depends = default,mesecons,mesecons_mvps,screwdriver,pipeworks
2 changes: 1 addition & 1 deletion panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ digistuff.update_panel_formspec = function (pos,dispstr)
"image_button[3,6.5;1,1;digistuff_adwaita_emblem-default.png;enter;]"..
"field[6,5.75;2,1;channel;Channel;${channel}]"..
"button[8,5.5;1,1;savechan;Set]"
fs = fs:format(minetest.formspec_escape(dispstr)):gsub("|","\n")
fs = fs:format(minetest.colorize("#000000",minetest.formspec_escape(dispstr):gsub("|","\n")))
meta:set_string("formspec",fs)
meta:set_string("text",dispstr)
end
Expand Down
13 changes: 7 additions & 6 deletions piezo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,16 @@ minetest.register_node("digistuff:piezo", {
}
})

local crystal = "default:mese_crystal_fragment"
if minetest.get_modpath("quartz") then
crystal = "quartz:quartz_crystal_piece"
local crystal = "quartz:quartz_crystal_piece"

if not minetest.get_modpath("quartz") then
crystal = "default:mese_crystal_fragment"
end

minetest.register_craft({
output = "digistuff:piezo",
recipe = {
{crystal, "basic_materials:steel_strip"},
{"digilines:wire_std_00000000", "mesecons_luacontroller:luacontroller0000"},
}
{crystal,"basic_materials:steel_strip"},
{"digilines:wire_std_00000000","mesecons_luacontroller:luacontroller0000"},
},
})
Binary file added textures/digistuff_advts_front.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added textures/digistuff_transparent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 52 additions & 9 deletions touchscreen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ digistuff.update_ts_formspec = function (pos)
if meta:get_int("init") == 0 then
fs = fs.."field[3.75,3;3,1;channel;Channel;]"..
"button_exit[4,3.75;2,1;save;Save]"
elseif minetest.get_node(pos).name == "digistuff:advtouchscreen" then
fs = fs.."label[0,0;No data received yet]"
else
local data = minetest.deserialize(meta:get_string("data")) or {}
for _,field in pairs(data) do
Expand Down Expand Up @@ -252,19 +254,23 @@ digistuff.ts_on_digiline_receive = function (pos, node, channel, msg)
local meta = minetest.get_meta(pos)
local setchan = meta:get_string("channel")
if channel ~= setchan then return end
if type(msg) ~= "table" then return end
local data = minetest.deserialize(meta:get_string("data")) or {}
if msg.command then
data = digistuff.process_command(meta,data,msg)
if node.name == "digistuff:advtouchscreen" then
if type(msg) == "string" then meta:set_string("formspec",msg) end
else
for _,i in ipairs(msg) do
if type(i) == "table" and i.command then
data = digistuff.process_command(meta,data,i) or data
if type(msg) ~= "table" then return end
local data = minetest.deserialize(meta:get_string("data")) or {}
if msg.command then
data = digistuff.process_command(meta,data,msg)
else
for _,i in ipairs(msg) do
if type(i) == "table" and i.command then
data = digistuff.process_command(meta,data,i) or data
end
end
end
meta:set_string("data",minetest.serialize(data))
digistuff.update_ts_formspec(pos)
end
meta:set_string("data",minetest.serialize(data))
digistuff.update_ts_formspec(pos)
end

minetest.register_node("digistuff:touchscreen", {
Expand Down Expand Up @@ -304,6 +310,43 @@ minetest.register_node("digistuff:touchscreen", {
},
})

minetest.register_node("digistuff:advtouchscreen", {
description = "Advanced Digilines Touchscreen",
groups = {cracky=3},
on_construct = function(pos)
digistuff.update_ts_formspec(pos,true)
end,
drawtype = "nodebox",
tiles = {
"digistuff_panel_back.png",
"digistuff_panel_back.png",
"digistuff_panel_back.png",
"digistuff_panel_back.png",
"digistuff_panel_back.png",
"digistuff_advts_front.png"
},
paramtype = "light",
paramtype2 = "facedir",
node_box = {
type = "fixed",
fixed = {
{ -0.5, -0.5, 0.4, 0.5, 0.5, 0.5 }
}
},
_digistuff_channelcopier_fieldname = "channel",
_digistuff_channelcopier_onset = function(pos)
minetest.get_meta(pos):set_int("init",1)
digistuff.update_ts_formspec(pos)
end,
on_receive_fields = digistuff.ts_on_receive_fields,
digiline = {
receptor = {},
effector = {
action = digistuff.ts_on_digiline_receive
},
},
})

minetest.register_craft({
output = "digistuff:touchscreen",
recipe = {
Expand Down

0 comments on commit 72b9d32

Please sign in to comment.