From 10f4a0cd007a1f8e8d04b5a04ec00c7bdd84969f Mon Sep 17 00:00:00 2001 From: ExeVirus Date: Wed, 16 Dec 2020 21:53:26 -0500 Subject: [PATCH] Work from Home --- api.lua | 18 ++++++- formspecs.lua | 119 +++++++++++++++++++++++++++++++++++++------- register.lua | 4 ++ spawning.lua | 113 ++++++++++++++++++++--------------------- textures/clear.png | Bin 0 -> 708 bytes textures/next.png | Bin 0 -> 727 bytes textures/prev.png | Bin 0 -> 728 bytes textures/search.png | Bin 0 -> 1908 bytes 8 files changed, 176 insertions(+), 78 deletions(-) create mode 100644 textures/clear.png create mode 100644 textures/next.png create mode 100644 textures/prev.png create mode 100644 textures/search.png diff --git a/api.lua b/api.lua index a1a42aa..7cb09cc 100644 --- a/api.lua +++ b/api.lua @@ -106,9 +106,12 @@ function adv_core.take_from_player(name, fire, water, earth, air) end end +local num_pages = 0 +local num_objects = 0 + function adv_core.register_object(object_name, lfire, lwater, learth, lair) local objectTable = minetest.deserialize(adv_core.mod_storage:get_string("objectTable")) or {} - + if objectTable.num_objects == nil then objectTable.num_objects = 0 end --if object name is taken, Error out if objectTable.object_name ~= nil then minetest.log("Unable to add " .. object_name .. " to adventure core object list, name already taken") @@ -122,10 +125,23 @@ function adv_core.register_object(object_name, lfire, lwater, learth, lair) earth = learth, air = lair, } + objectTable.num_objects = objectTable.num_objects+1 + adv_core.mod_storage:set_string("objectTable", minetest.serialize(objectTable)) return true end +function adv_core.get_num_pages() + --get number of registered objects + num_pages = math.floor(num_objects / 6 / 12) + 1 + + return num_pages +end + +function adv_core.get_num_objects() + return num_objects +end + --"fire","water","earth","air" function adv_core.spawn_element(element_type, pos) if element_type == "fire" then diff --git a/formspecs.lua b/formspecs.lua index 619bad2..320d2d1 100644 --- a/formspecs.lua +++ b/formspecs.lua @@ -24,7 +24,7 @@ function adv_core.guide_formspec(name) "box[4.87,2.77;0.41,0.4;#00000030]", --air "image[2.8,5.2;0.5,0.5;fire.png]", "button[6.12,4.24;1.5,0.5;play;This Sound]", - "style[label;font=mono]", + "style_type[label;noclip=true]", "label[1,2;",black, "----------- Adventure Core is a discovery mod! -----------\n", black, "]", @@ -111,7 +111,12 @@ end function adv_core.store_formspec(name, page, search, selected) --how to sort: --https://stackoverflow.com/questions/17436947/how-to-iterate-through-table-in-lua - + local objectTable = minetest.deserialize(adv_core.mod_storage:get_string("objectTable")) or {} + local num_pages = adv_core.get_num_pages() + local num_objects = adv_core.get_num_objects() + + minetest.chat_send_all("Objects: " .. num_objects) + local formspec = { "formspec_version[3]", "size[16,12]", @@ -129,27 +134,105 @@ function adv_core.store_formspec(name, page, search, selected) "image[0.35,6.0;0.5,0.5;earth.png]", "image[0.35,7.4;0.5,0.5;air.png]", --Search Bar - "field[10.0,10;4,0.6;search;;]", - "image_button[14.1,10;0.6,0.6;magnify.png;do_search;]", - "image_button[14.8,10;0.6,0.6;reset.png;do_search;]", - } - -- Reset Search, bottom right corner - -- Grid of options. right half - -- Paging arrows <->, middle left and right of right half - -- Selected item, and cost, left half - -- Create Button, bottom middle of left half. - + "field[9.0,10;6,0.6;search;;]", + "image_button[14.1,10;0.6,0.6;search.png;do_search;]", + "image_button[14.8,10;0.6,0.6;clear.png;reset_search;]", + --Paging + "label[11,1;Page ", page , " of " , num_pages , "]", + "image_button[11.3,0.2;0.6,0.6;prev.png;next_page;]", + "image_button[12.3,0.2;0.6,0.6;next.png;previous_page;]", + } + + if num_objects > 0 then + local matched = {} + local unmatched = {} + if search ~= nil and search ~= "" then + --Separate + for object in pairs(objectTable) do + if string.find(object, search) == nil then + unmatched[#unmatched+1] = object + else + matched[#matched+1] = object + end + end + --Sort A-Z + table.sort(unmatched); + table.sort(matched); + + local num_matched = #matched + --Add unmatched to matched + for i = 1, #unmatched do + matched[#matched+1] = unmatched[i] + end + + local defs = minetest.registered_nodes + for i = (page-1)*72+1, math.min(page*72+1,#matched) do + local index = i - (page-1)*72-1 --index is for finding row-column + local row = math.floor(index / 6) + local column = index - row*6 + if i < (num_matched+2) then + --Display Blue + formspec[#formspec+1] = "item_image_button[column*0.6+9,row*0.6+2;0.5,0.5;" + formspec[#formspec+1] = matched[i] + formspec[#formspec+1] = ";select;" + formspec[#formspec+1] = matched[i] + formspec[#formspec+1] = ";]," + + else + --Display Normal + formspec[#formspec+1] = "item_image_button[column*0.6+9,row*0.6+2;0.5,0.5;" + formspec[#formspec+1] = matched[i] + formspec[#formspec+1] = ";select;" + formspec[#formspec+1] = matched[i] + formspec[#formspec+1] = ";]," + end + --table.concat(formspec, "image_button[row*0.6,column*0.6;0.5,0.5;" .. node_def[object].inv_img .. ";select;".. object .."],") + --table.concat(formspec, "tooltip[blah;blah],") + end + else --Display Normally + minetest.chat_send_all("Normal List") + for object in pairs(objectTable) do + minetest.chat_send_all(object) + unmatched[#unmatched+1] = object + end + table.sort(unmatched); + minetest.chat_send_all(#unmatched) + + for i = (page-1)*72+1, math.min(page*72+1,#unmatched) do + local index = i - (page-1)*72-1 --index is for finding row-column + minetest.chat_send_all(index) + local row = math.floor(index / 6) + local column = index - row*6 + --Display Normal + formspec[#formspec+1] = "item_image_button[column*0.6+9,row*0.6+2;0.5,0.5;" + formspec[#formspec+1] = matched[i] + formspec[#formspec+1] = ";select;" + formspec[#formspec+1] = matched[i] + formspec[#formspec+1] = ";]," + end + end + end + + + + + --Columns and Rows of objects + --Get object list + --Perform Search, if applicable. + --Recombine the matched and unmatched object groups after sorting a-z. + --Display current page of objects as from starting page value to either end of array or end of page value + + --Selected Item Display + if objectTable.selected ~= nil then + --Show item + --Show Cost + --Show "Create" button + end -- Number of pages is always the same, search function will separate them into -- a group of matched and the rest in unmatched. -- Then it will display *both* sets in alphabetical order, matching first. -- Matching are displayed with a light-blue background box around them. - - -- if stinrg.find("search") == nil then - --place in unmatched - -- else - --place in matched - -- end return table.concat(formspec, "") end diff --git a/register.lua b/register.lua index fddf053..8ebb801 100644 --- a/register.lua +++ b/register.lua @@ -1,5 +1,9 @@ -- REGISTER +adv_core.register_object("default:dirt", 0, 0, 1, 0) +adv_core.register_object("default:dirt_with_grass", 0, 1, 1, 0) +adv_core.register_object("default:water", 0, 1, 0, 0) + -- ---Register the round rock -- minetest.register_node("rocks:".. name .."_round", { -- description = "Round " .. name .. " Rock", diff --git a/spawning.lua b/spawning.lua index d687ac8..92e968b 100644 --- a/spawning.lua +++ b/spawning.lua @@ -101,71 +101,66 @@ local function spawn_element(player, with_biomes) end end - +local total_time = 0 minetest.register_globalstep(function(dtime) - local new_time = minetest.get_us_time() - local old_time = tonumber(adv_core.mod_storage:get_string("time")) - if old_time ~= nil then - --Every second: - if old_time + 1000000 < new_time then - for _,player in ipairs(minetest.get_connected_players()) do - local name = player:get_player_name() - local player_old_time = tonumber(adv_core.mod_storage:get_string(name .. "old_time")) - if player_old_time == nil then - adv_core.mod_storage:set_string(name .. "old_time", new_time) - player_old_time = new_time - end - local player_countdown = tonumber(adv_core.mod_storage:get_string(name .. "countdown")) or init_time - minetest.chat_send_all("old_time: " .. player_old_time .. "countdown: " .. player_countdown) - - if player_old_time + player_countdown < new_time then - minetest.chat_send_all("attempting spawn") - local spawned = nil - if biome_spawns and default_en then - spawned = spawn_element(player, true) - else - spawned = spawn_element(player, false) - end - if spawned then - minetest.chat_send_all("spawn_successful") - local countdown = time_between + math.random(-spread,spread) - local dist = vector.distance(player:get_pos(), spawn_point) - if dist > base_dist then - countdown = countdown - math.floor(base_dist / 1000) * dist_adjust - else - countdown = countdown + spawn_adjust - end - adv_core.mod_storage:set_string(name .. "countdown", 3000000)--math.max(countdown, min_time) * 1000000) - else - minetest.chat_send_all("spawn_unsuccessful") - adv_core.mod_storage:set_string(name .. "countdown", 1000000) -- try again in 1 seconds... - end - adv_core.mod_storage:set_string(name .. "old_time", new_time) - end + total_time = total_time + dtime + if total_time > 1 then -- every second + total_time = 0 + local new_time = minetest.get_us_time() + for _,player in ipairs(minetest.get_connected_players()) do + local name = player:get_player_name() + local player_old_time = tonumber(adv_core.mod_storage:get_string(name .. "old_time")) + if player_old_time == nil then + adv_core.mod_storage:set_string(name .. "old_time", new_time) + player_old_time = new_time + end + local player_countdown = tonumber(adv_core.mod_storage:get_string(name .. "countdown")) or init_time + minetest.chat_send_all("old_time: " .. player_old_time .. "countdown: " .. player_countdown) + + if player_old_time + player_countdown < new_time then + minetest.chat_send_all("attempting spawn") + local spawned = nil + if biome_spawns and default_en then + spawned = spawn_element(player, true) + else + spawned = spawn_element(player, false) + end + if spawned then + minetest.chat_send_all("spawn_successful") + local countdown = time_between + math.random(-spread,spread) + local dist = vector.distance(player:get_pos(), spawn_point) + if dist > base_dist then + countdown = countdown - math.floor(base_dist / 1000) * dist_adjust + else + countdown = countdown + spawn_adjust + end + adv_core.mod_storage:set_string(name .. "countdown", 3000000)--math.max(countdown, min_time) * 1000000) + else + minetest.chat_send_all("spawn_unsuccessful") + adv_core.mod_storage:set_string(name .. "countdown", 1000000) -- try again in 1 seconds... + end + adv_core.mod_storage:set_string(name .. "old_time", new_time) end - adv_core.mod_storage:set_string("time",tostring(new_time)) end - else - adv_core.mod_storage:set_string("time",tostring(new_time)) end end) ---Do players respawn/spawn with a guidebook and pouch? -if adv_core.setting("enable_starting_items", true) then - minetest.register_on_newplayer(function(playerRef) - local inv = player:get_inventory() - local main = inv:get_list("main") - --for loop through main stacks - --check if empty - --add guidebook - --break - --for loop though main stacks - --check if empty - --add pouch - --break - end - ) -end +-- --Do players respawn/spawn with a guidebook and pouch? +-- if adv_core.setting("enable_starting_items", true) then + -- minetest.register_on_newplayer(function(playerRef) + -- local inv = player:get_inventory() + -- local main = inv:get_list("main") + -- --for loop through main stacks + -- --check if empty + -- --add guidebook + -- --break + -- --for loop though main stacks + -- --check if empty + -- --add pouch + -- --break + -- end + -- ) +-- end diff --git a/textures/clear.png b/textures/clear.png new file mode 100644 index 0000000000000000000000000000000000000000..9244264adcf8a710ff13a2d684f148f997f1522f GIT binary patch literal 708 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1|$#LC7xzrVCwdCaSW-r_4ck|p0J|`+k@?8 z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id^O!B}t4yQjGPcSs;x3LM-7@9OZ z=w8Uk63@e{@FOXM;ULghj(rkR4j+zQ04pijarA>!#Pd1(`(A$LlzLtR)BDcFwBi3|wtWop4gCi;u{`7xI8ZA2L-PYy1jFf#wRRI3-_)Pq&*Imx z{ps&h?Ts7z{(f(M7~k`?l9BmF{*UDcW^d%bulm8@@b{Ao7I4RluIDspxZ8IB{^$7q z%7?}cf4Be5TKAJ}!~JbQq4U|*l{*+&ZhqrE(0ZO>k$w%({XjJjxaR}i|AR;2$Dwqf z`|W`4{~+n`0jQ)&zs5XMrtS@Ycb-gLPVZrJhW300zWWR^`xq^1m zyWUxR_7M!z4@iFKeHXjyz0AM7AYOB&=QfLf7qn^Ky}aAIU0%C^v)*oIvhlX<8Qz#F e2P9I`9q-0Hd(Hm59fiOI%i!ti=d#Wzp$P!RnKjM; literal 0 HcmV?d00001 diff --git a/textures/prev.png b/textures/prev.png new file mode 100644 index 0000000000000000000000000000000000000000..b26cd157f95aec853fce734574e5d319686b8399 GIT binary patch literal 728 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1|$#LC7xzrV4Cmg;uunK>+N0tY+*-+wvXwz zGV{>pV?eWW(PFe13zpU}_uI~@{8;u``%wXt0z|TCv@W=53 ztRMJxFuiNkXH!Uj7SHg$kzbdg{D8B3-}@7a_p+b$H~Jso*ufG9bg|50?E~*-*6%X= zp{oh6V%o%>4{WH7l z+KFfIj_uWexoBz8%lvY1e!z>W-gU6xbp)te5*7FQ4;`@FuSbT0~ zesG4L&*4{?z7>OZv;DH)_5U<-S8qQZ_~60(<+)##!W(qOD`oz)FjP!bw_p(4_kbbd zN0ax0R{aXr4Ifz94;&JgVc?E0V9=>KsCwa$_#P&pH1mab=j|8n_P%~ddT!%xg0c8qq1w4R9hWi^tX~{&$kePP23tw zeX`cxZ>W6Da{BQG9yOK(U6%RbeTUyBcriqA%*$HKuiaYEC*D%Tv|*dj8Y31>#v1}n zJC7RZFi3YLX3l4f(>TR(pe@NFWB$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