From 6f8a1940421854bfb27a6a9b706857ef48da23b9 Mon Sep 17 00:00:00 2001 From: loosewheel <76670709+loosewheel@users.noreply.github.com> Date: Wed, 16 Feb 2022 01:49:12 +1000 Subject: [PATCH] Add files via upload --- camera.lua | 38 +++++++++++++++++++------------------- change.log | 6 ++++++ init.lua | 2 +- readme.txt | 2 +- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/camera.lua b/camera.lua index 023d82a..5eca200 100644 --- a/camera.lua +++ b/camera.lua @@ -140,9 +140,10 @@ local function camera_scan (pos, resolution, distance) tpos = vector.round ({ x = horz + pos.x, y = pos.y - vert, z = (dist * dir.z) + pos.z }) end - if last_pos and vector.equals (last_pos, tpos) then - image[y][x] = last_color + if last_color then + image[y][x] = last_color + end else local entity = get_entity (tpos) @@ -151,13 +152,11 @@ local function camera_scan (pos, resolution, distance) last_color = string.format ("00%02X00", color) image[y][x] = last_color - last_pos = tpos elseif entity == 2 then local color = (((distance - dist) / distance) * 98) + 30 last_color = string.format ("0000%02X", color) image[y][x] = last_color - last_pos = tpos else local node = utils.get_far_node (tpos) @@ -166,12 +165,13 @@ local function camera_scan (pos, resolution, distance) last_color = string.format ("%02X%02X%02X", color, color, color) image[y][x] = last_color - last_pos = tpos else - last_pos = nil + last_color = nil end end end + + last_pos = tpos end end end @@ -198,8 +198,6 @@ local function send_scan (pos) channel, image) end - - end end @@ -208,14 +206,14 @@ end local function after_place_node (pos, placer, itemstack, pointed_thing) local meta = minetest.get_meta (pos) local spec = - "formspec_version[3]\n".. - "size[8.5,5.5;true]\n".. - "field[1.0,1.0;4.0,0.8;channel;Channel;${channel}]\n".. - "button[5.5,1.0;2.0,0.8;setchannel;Set]\n".. - "field[1.0,2.5;4.0,0.8;distance;Distance;${distance}]\n".. - "button[5.5,2.5;2.0,0.8;setdistance;Set]\n".. - "field[1.0,4.0;4.0,0.8;resolution;Resolution;${resolution}]\n".. - "button[5.5,4.0;2.0,0.8;setresolution;Set]\n" + "formspec_version[3]".. + "size[8.5,5.5;true]".. + "field[1.0,1.0;4.0,0.8;channel;Channel;${channel}]".. + "button[5.5,1.0;2.0,0.8;setchannel;Set]".. + "field[1.0,2.5;4.0,0.8;distance;Distance;${distance}]".. + "button[5.5,2.5;2.0,0.8;setdistance;Set]".. + "field[1.0,4.0;4.0,0.8;resolution;Resolution;${resolution}]".. + "button[5.5,4.0;2.0,0.8;setresolution;Set]" meta:set_string ("formspec", spec) meta:set_string ("distance", "5") @@ -271,7 +269,7 @@ local function on_receive_fields (pos, formname, fields, sender) local meta = minetest.get_meta (pos) if meta then - local resolution = math.max (tonumber (fields.resolution) or 1, 1) + local resolution = math.min (math.max (tonumber (fields.resolution) or 1, 1), 128) fields.resolution = tostring (resolution) meta:set_string ("resolution", tostring (resolution)) @@ -375,10 +373,12 @@ local function digilines_support () send_scan (pos) elseif m[1] == "distance" then - meta:set_string ("distance", tostring (tonumber (m[2] or 5) or 5)) + local distance = math.min (math.max (tonumber (m[2] or 5) or 5, 1), 16) + meta:set_string ("distance", tostring (distance)) elseif m[1] == "resolution" then - meta:set_string ("resolution", tostring (tonumber (m[2] or 16) or 16)) + local resolution = math.min (math.max (tonumber (m[2] or 16) or 16, 1), 128) + meta:set_string ("resolution", tostring (resolution)) end end diff --git a/change.log b/change.log index de3d5b3..6aa74a1 100644 --- a/change.log +++ b/change.log @@ -96,9 +96,15 @@ v0.1.16 v0.1.17 * Fixed unintended global variable in pistons.lua. + v0.1.18 * Added mesecons through wire. v0.1.19 * Added camera. + + +v0.1.20 +* Valid distance and resolution for camera set by digilines message. +* Imposed maximum resolution of 128 for cameras. diff --git a/init.lua b/init.lua index 966794f..1d18fa1 100644 --- a/init.lua +++ b/init.lua @@ -1,4 +1,4 @@ -local version = "0.1.19" +local version = "0.1.20" local mod_storage = minetest.get_mod_storage () diff --git a/readme.txt b/readme.txt index 72b089d..319bd6f 100644 --- a/readme.txt +++ b/readme.txt @@ -13,7 +13,7 @@ CC BY-SA 3.0 Version ======= -0.1.19 +0.1.20 Minetest Version