Work from Home
parent
0753b3a5ed
commit
10f4a0cd00
18
api.lua
18
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
|
||||
|
|
119
formspecs.lua
119
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
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
113
spawning.lua
113
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
|
||||
|
||||
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 708 B |
Binary file not shown.
After Width: | Height: | Size: 727 B |
Binary file not shown.
After Width: | Height: | Size: 728 B |
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
Loading…
Reference in New Issue