Work from Home

master
ExeVirus 2020-12-16 21:53:26 -05:00
parent 0753b3a5ed
commit 10f4a0cd00
8 changed files with 176 additions and 78 deletions

18
api.lua
View File

@ -106,9 +106,12 @@ function adv_core.take_from_player(name, fire, water, earth, air)
end end
end end
local num_pages = 0
local num_objects = 0
function adv_core.register_object(object_name, lfire, lwater, learth, lair) function adv_core.register_object(object_name, lfire, lwater, learth, lair)
local objectTable = minetest.deserialize(adv_core.mod_storage:get_string("objectTable")) or {} 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 object name is taken, Error out
if objectTable.object_name ~= nil then if objectTable.object_name ~= nil then
minetest.log("Unable to add " .. object_name .. " to adventure core object list, name already taken") 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, earth = learth,
air = lair, air = lair,
} }
objectTable.num_objects = objectTable.num_objects+1
adv_core.mod_storage:set_string("objectTable", minetest.serialize(objectTable))
return true return true
end 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" --"fire","water","earth","air"
function adv_core.spawn_element(element_type, pos) function adv_core.spawn_element(element_type, pos)
if element_type == "fire" then if element_type == "fire" then

View File

@ -24,7 +24,7 @@ function adv_core.guide_formspec(name)
"box[4.87,2.77;0.41,0.4;#00000030]", --air "box[4.87,2.77;0.41,0.4;#00000030]", --air
"image[2.8,5.2;0.5,0.5;fire.png]", "image[2.8,5.2;0.5,0.5;fire.png]",
"button[6.12,4.24;1.5,0.5;play;This Sound]", "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, "label[1,2;",black,
"----------- Adventure Core is a discovery mod! -----------\n", black, "----------- Adventure Core is a discovery mod! -----------\n", black,
"]", "]",
@ -111,7 +111,12 @@ end
function adv_core.store_formspec(name, page, search, selected) function adv_core.store_formspec(name, page, search, selected)
--how to sort: --how to sort:
--https://stackoverflow.com/questions/17436947/how-to-iterate-through-table-in-lua --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 = { local formspec = {
"formspec_version[3]", "formspec_version[3]",
"size[16,12]", "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,6.0;0.5,0.5;earth.png]",
"image[0.35,7.4;0.5,0.5;air.png]", "image[0.35,7.4;0.5,0.5;air.png]",
--Search Bar --Search Bar
"field[10.0,10;4,0.6;search;;]", "field[9.0,10;6,0.6;search;;]",
"image_button[14.1,10;0.6,0.6;magnify.png;do_search;]", "image_button[14.1,10;0.6,0.6;search.png;do_search;]",
"image_button[14.8,10;0.6,0.6;reset.png;do_search;]", "image_button[14.8,10;0.6,0.6;clear.png;reset_search;]",
} --Paging
-- Reset Search, bottom right corner "label[11,1;Page ", page , " of " , num_pages , "]",
-- Grid of options. right half "image_button[11.3,0.2;0.6,0.6;prev.png;next_page;]",
-- Paging arrows <->, middle left and right of right half "image_button[12.3,0.2;0.6,0.6;next.png;previous_page;]",
-- Selected item, and cost, left half }
-- Create Button, bottom middle of left half.
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 -- Number of pages is always the same, search function will separate them into
-- a group of matched and the rest in unmatched. -- a group of matched and the rest in unmatched.
-- Then it will display *both* sets in alphabetical order, matching first. -- Then it will display *both* sets in alphabetical order, matching first.
-- Matching are displayed with a light-blue background box around them. -- 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, "") return table.concat(formspec, "")
end end

View File

@ -1,5 +1,9 @@
-- REGISTER -- 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 -- ---Register the round rock
-- minetest.register_node("rocks:".. name .."_round", { -- minetest.register_node("rocks:".. name .."_round", {
-- description = "Round " .. name .. " Rock", -- description = "Round " .. name .. " Rock",

View File

@ -101,71 +101,66 @@ local function spawn_element(player, with_biomes)
end end
end end
local total_time = 0
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
local new_time = minetest.get_us_time() total_time = total_time + dtime
local old_time = tonumber(adv_core.mod_storage:get_string("time")) if total_time > 1 then -- every second
if old_time ~= nil then total_time = 0
--Every second: local new_time = minetest.get_us_time()
if old_time + 1000000 < new_time then for _,player in ipairs(minetest.get_connected_players()) do
for _,player in ipairs(minetest.get_connected_players()) do local name = player:get_player_name()
local name = player:get_player_name() local player_old_time = tonumber(adv_core.mod_storage:get_string(name .. "old_time"))
local player_old_time = tonumber(adv_core.mod_storage:get_string(name .. "old_time")) if player_old_time == nil then
if player_old_time == nil then adv_core.mod_storage:set_string(name .. "old_time", new_time)
adv_core.mod_storage:set_string(name .. "old_time", new_time) player_old_time = new_time
player_old_time = new_time end
end local player_countdown = tonumber(adv_core.mod_storage:get_string(name .. "countdown")) or init_time
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)
minetest.chat_send_all("old_time: " .. player_old_time .. "countdown: " .. player_countdown)
if player_old_time + player_countdown < new_time then
if player_old_time + player_countdown < new_time then minetest.chat_send_all("attempting spawn")
minetest.chat_send_all("attempting spawn") local spawned = nil
local spawned = nil if biome_spawns and default_en then
if biome_spawns and default_en then spawned = spawn_element(player, true)
spawned = spawn_element(player, true) else
else spawned = spawn_element(player, false)
spawned = spawn_element(player, false) end
end if spawned then
if spawned then minetest.chat_send_all("spawn_successful")
minetest.chat_send_all("spawn_successful") local countdown = time_between + math.random(-spread,spread)
local countdown = time_between + math.random(-spread,spread) local dist = vector.distance(player:get_pos(), spawn_point)
local dist = vector.distance(player:get_pos(), spawn_point) if dist > base_dist then
if dist > base_dist then countdown = countdown - math.floor(base_dist / 1000) * dist_adjust
countdown = countdown - math.floor(base_dist / 1000) * dist_adjust else
else countdown = countdown + spawn_adjust
countdown = countdown + spawn_adjust end
end adv_core.mod_storage:set_string(name .. "countdown", 3000000)--math.max(countdown, min_time) * 1000000)
adv_core.mod_storage:set_string(name .. "countdown", 3000000)--math.max(countdown, min_time) * 1000000) else
else minetest.chat_send_all("spawn_unsuccessful")
minetest.chat_send_all("spawn_unsuccessful") adv_core.mod_storage:set_string(name .. "countdown", 1000000) -- try again in 1 seconds...
adv_core.mod_storage:set_string(name .. "countdown", 1000000) -- try again in 1 seconds... end
end adv_core.mod_storage:set_string(name .. "old_time", new_time)
adv_core.mod_storage:set_string(name .. "old_time", new_time)
end
end end
adv_core.mod_storage:set_string("time",tostring(new_time))
end end
else
adv_core.mod_storage:set_string("time",tostring(new_time))
end end
end) end)
--Do players respawn/spawn with a guidebook and pouch? -- --Do players respawn/spawn with a guidebook and pouch?
if adv_core.setting("enable_starting_items", true) then -- if adv_core.setting("enable_starting_items", true) then
minetest.register_on_newplayer(function(playerRef) -- minetest.register_on_newplayer(function(playerRef)
local inv = player:get_inventory() -- local inv = player:get_inventory()
local main = inv:get_list("main") -- local main = inv:get_list("main")
--for loop through main stacks -- --for loop through main stacks
--check if empty -- --check if empty
--add guidebook -- --add guidebook
--break -- --break
--for loop though main stacks -- --for loop though main stacks
--check if empty -- --check if empty
--add pouch -- --add pouch
--break -- --break
end -- end
) -- )
end -- end

BIN
textures/clear.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 708 B

BIN
textures/next.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 727 B

BIN
textures/prev.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 728 B

BIN
textures/search.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB