2019-01-03 13:57:48 -08:00
|
|
|
was={
|
|
|
|
functions={},
|
2019-01-04 02:32:59 -08:00
|
|
|
function_packed={},
|
2019-01-04 10:46:50 -08:00
|
|
|
info={
|
|
|
|
["!"]="Empty value",
|
|
|
|
["=="]="Equal (only used with if)",
|
|
|
|
["~="]="Equal (only used with if)",
|
|
|
|
[">"]="Greater then (only used with if)",
|
|
|
|
["<"]="Less then (only used with if)",
|
|
|
|
[">="]="Greater or equal (only used with if)",
|
|
|
|
["<="]="Less or equal (only used with if)",
|
|
|
|
},
|
2019-01-03 13:57:48 -08:00
|
|
|
privs={},
|
|
|
|
user={},
|
2019-01-04 09:37:55 -08:00
|
|
|
username="",
|
2019-01-04 04:19:33 -08:00
|
|
|
symbols={
|
2019-01-05 00:00:27 -08:00
|
|
|
["!"]=function(var,vars,user,run_func_name)
|
|
|
|
if run_func_name and run_func_name=="if" then
|
|
|
|
return "!"
|
|
|
|
end
|
|
|
|
end,
|
2019-01-04 10:46:50 -08:00
|
|
|
[">"]=function() return ">" end,
|
|
|
|
["<"]=function() return "<" end,
|
|
|
|
["=="]=function() return "==" end,
|
|
|
|
["~="]=function() return "~=" end,
|
|
|
|
[">="]=function() return ">=" end,
|
|
|
|
["<="]=function() return "<=" end,
|
2019-01-04 04:19:33 -08:00
|
|
|
},
|
2019-01-04 10:46:50 -08:00
|
|
|
symbols_characters="#@=?!&{}%*+-/$<>|~^",
|
2019-01-03 13:57:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
dofile(minetest.get_modpath("was") .. "/api.lua")
|
2019-01-04 02:32:59 -08:00
|
|
|
dofile(minetest.get_modpath("was") .. "/register.lua")
|
2019-01-03 13:57:48 -08:00
|
|
|
|
|
|
|
minetest.register_chatcommand("was", {
|
|
|
|
description = "World action script gui",
|
|
|
|
func = function(name, param)
|
|
|
|
was.gui(name)
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2019-01-04 11:47:35 -08:00
|
|
|
minetest.register_node("was:computer", {
|
|
|
|
description = "Computer",
|
|
|
|
tiles = {"default_steel_block.png"},
|
|
|
|
groups = {oddly_breakable_by_hand = 3,was_component=1},
|
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("owner",placer:get_player_name() or "")
|
|
|
|
end,
|
|
|
|
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
|
|
|
|
local meta=minetest.get_meta(pos)
|
|
|
|
local name=player:get_player_name() or ""
|
|
|
|
if meta:get_string("owner")==name or minetest.check_player_privs(name, {protection_bypass=true}) then
|
2019-01-04 15:30:48 -08:00
|
|
|
if meta:get_string("owner")=="" then
|
|
|
|
return
|
|
|
|
end
|
2019-01-04 11:47:35 -08:00
|
|
|
local text=minetest.deserialize(meta:get_string("text"))
|
|
|
|
was.gui(name,"",{text=text})
|
|
|
|
if was.user[name] and not was.user[name].nodepos then
|
|
|
|
was.user[name].nodepos=pos
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
can_dig = function(pos, player)
|
|
|
|
local meta=minetest.get_meta(pos)
|
|
|
|
local name=player:get_player_name() or ""
|
|
|
|
if meta:get_string("owner")==name or minetest.check_player_privs(name, {protection_bypass=true}) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2019-01-04 08:02:12 -08:00
|
|
|
was.gui_addnumbers=function(text)
|
|
|
|
text=text.."\n"
|
2019-01-05 09:40:37 -08:00
|
|
|
for i=1,text:len(),1 do
|
|
|
|
if text:sub(i,i)~="\n" then
|
|
|
|
text=text:sub(i,text:len())
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2019-01-04 08:02:12 -08:00
|
|
|
local t=""
|
|
|
|
for i,v in ipairs(text.split(text,"\n")) do
|
|
|
|
t=t ..i.." " ..v .."\n"
|
|
|
|
end
|
|
|
|
return t
|
|
|
|
end
|
|
|
|
|
2019-01-05 09:40:37 -08:00
|
|
|
|
2019-01-04 08:02:12 -08:00
|
|
|
was.gui_delnumbers=function(text)
|
2019-01-05 09:40:37 -08:00
|
|
|
for i=1,text:len(),1 do
|
|
|
|
if text:sub(i,i)~="\n" then
|
|
|
|
text=text:sub(i,text:len())
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2019-01-04 08:02:12 -08:00
|
|
|
local t=""
|
|
|
|
for i,v in ipairs(text.split(text,"\n")) do
|
|
|
|
for ii=1,v:len(),1 do
|
|
|
|
local s=string.sub(v,ii,ii)
|
2019-01-05 09:40:37 -08:00
|
|
|
if not was.num(s) then
|
|
|
|
ii= (s==" " and ii+1) or ii
|
|
|
|
t=t .. string.sub(v,ii,v:len()).."\n"
|
|
|
|
break
|
2019-01-04 08:02:12 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return t
|
|
|
|
end
|
|
|
|
|
2019-01-04 11:47:35 -08:00
|
|
|
was.gui=function(name,msg,other)
|
|
|
|
|
2019-01-04 15:30:48 -08:00
|
|
|
was.user[name]=was.user[name] or {text=(other and other.text or ""),funcs={},inserttext="true",lines="off"}
|
2019-01-04 11:47:35 -08:00
|
|
|
|
2019-01-04 15:30:48 -08:00
|
|
|
local text=was.user[name].text
|
2019-01-03 13:57:48 -08:00
|
|
|
local funcs=""
|
2019-01-05 00:00:27 -08:00
|
|
|
local symbs="SYMBOLS,"
|
2019-01-03 13:57:48 -08:00
|
|
|
|
2019-01-04 08:02:12 -08:00
|
|
|
for f,v in pairs(was.symbols) do
|
2019-01-04 15:30:48 -08:00
|
|
|
symbs=symbs .. f ..","
|
2019-01-04 08:02:12 -08:00
|
|
|
end
|
|
|
|
|
2019-01-03 13:57:48 -08:00
|
|
|
for f,v in pairs(was.functions) do
|
|
|
|
if minetest.check_player_privs(name,was.privs[f]) then
|
|
|
|
funcs=funcs .. f ..","
|
|
|
|
table.insert(was.user[name].funcs,f)
|
|
|
|
end
|
|
|
|
end
|
2019-01-04 15:30:48 -08:00
|
|
|
|
2019-01-03 13:57:48 -08:00
|
|
|
funcs=funcs:sub(0,funcs:len()-1)
|
2019-01-04 15:30:48 -08:00
|
|
|
symbs=symbs:sub(0,symbs:len()-1)
|
2019-01-03 13:57:48 -08:00
|
|
|
|
|
|
|
local gui="size[20,12]"
|
|
|
|
.."textarea[0,1.3;17,13;text;;" .. text .. "]"
|
|
|
|
.."label[0,0.6;".. minetest.colorize("#00FF00",(msg or "")) .."]"
|
|
|
|
.."button[0,-0.2;1.3,1;run;Run]"
|
|
|
|
.."button[1,-0.2;1.3,1;save;Save]"
|
2019-01-04 08:02:12 -08:00
|
|
|
.."button[2,-0.2;1.5,1;lines;Lines " ..was.user[name].lines.."]"
|
2019-01-04 15:30:48 -08:00
|
|
|
.."dropdown[16.6,0.4;3,12;slist;" .. symbs ..";]"
|
|
|
|
.."textlist[16.6,1;3,12;list;" .. funcs .."]"
|
|
|
|
.."checkbox[16.6,-0.4;inserttext;Insert text;".. was.user[name].inserttext.."]"
|
2019-01-03 13:57:48 -08:00
|
|
|
|
|
|
|
minetest.after(0.1, function(gui,name)
|
|
|
|
return minetest.show_formspec(name, "was.gui",gui)
|
|
|
|
end, gui,name)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_on_player_receive_fields(function(user, form, pressed)
|
|
|
|
if form=="was.gui" then
|
|
|
|
local name=user:get_player_name()
|
|
|
|
if (pressed.quit and not pressed.key_enter) or not was.user[name] then
|
2019-01-04 11:47:35 -08:00
|
|
|
if was.user[name] then
|
|
|
|
was.user[name].nodepos=nil
|
|
|
|
end
|
2019-01-03 13:57:48 -08:00
|
|
|
return
|
|
|
|
end
|
2019-01-04 08:02:12 -08:00
|
|
|
|
2019-01-03 13:57:48 -08:00
|
|
|
local funcs=was.user[name].funcs
|
|
|
|
was.user[name].funcs={}
|
|
|
|
was.user[name].text=pressed.text
|
|
|
|
|
2019-01-04 08:02:12 -08:00
|
|
|
if was.user[name].text:find("%[") or was.user[name].text:find("%]") then
|
|
|
|
was.user[name].text=was.user[name].text:gsub("%[","")
|
|
|
|
was.user[name].text=was.user[name].text:gsub("%]","")
|
|
|
|
minetest.close_formspec(name,form)
|
|
|
|
was.gui(name,"Unallowed characters removed")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if pressed.lines then
|
|
|
|
if was.user[name].lines=="on" then
|
|
|
|
was.user[name].text=was.gui_delnumbers(was.user[name].text)
|
|
|
|
was.user[name].lines="off"
|
|
|
|
else
|
|
|
|
was.user[name].text=was.gui_addnumbers(was.user[name].text)
|
|
|
|
was.user[name].lines="on"
|
|
|
|
end
|
|
|
|
was.gui(name)
|
|
|
|
elseif was.user[name].lines=="on" then
|
|
|
|
was.user[name].text=was.gui_delnumbers(was.user[name].text)
|
|
|
|
was.user[name].lines="off"
|
|
|
|
end
|
|
|
|
|
|
|
|
if pressed.inserttext then
|
|
|
|
was.user[name].inserttext=pressed.inserttext
|
|
|
|
end
|
|
|
|
|
2019-01-03 13:57:48 -08:00
|
|
|
if pressed.list and pressed.list~="IMV" then
|
|
|
|
local n=pressed.list:gsub("CHG:","")
|
|
|
|
local f=funcs[tonumber(n)]
|
|
|
|
local info=was.info[f] or ""
|
|
|
|
if was.privs[f] then
|
|
|
|
info=info .. "| Privs: " ..minetest.privs_to_string(was.privs[f])
|
|
|
|
end
|
2019-01-04 08:02:12 -08:00
|
|
|
if was.user[name].inserttext=="true" and f then
|
|
|
|
was.user[name].text=was.user[name].text .. f ..(was.functions[f] and "()" or "")
|
|
|
|
end
|
2019-01-03 13:57:48 -08:00
|
|
|
minetest.close_formspec(name,form)
|
|
|
|
was.gui(name,info)
|
2019-01-05 00:00:27 -08:00
|
|
|
elseif pressed.slist and pressed.slist~="SYMBOLS" then
|
2019-01-04 15:30:48 -08:00
|
|
|
if was.user[name].inserttext=="true" then
|
|
|
|
was.user[name].text=was.user[name].text .. pressed.slist
|
|
|
|
end
|
|
|
|
was.gui(name,was.info[pressed.slist] or "")
|
2019-01-03 13:57:48 -08:00
|
|
|
elseif pressed.save then
|
2019-01-04 11:47:35 -08:00
|
|
|
if was.user[name].nodepos and minetest.get_item_group(minetest.get_node(was.user[name].nodepos).name,"was_component")==1 then
|
|
|
|
local meta=minetest.get_meta(was.user[name].nodepos)
|
|
|
|
meta:set_string("text",minetest.serialize(was.user[name].text))
|
|
|
|
was.gui(name,"Text saved successful")
|
|
|
|
end
|
2019-01-03 13:57:48 -08:00
|
|
|
elseif pressed.run then
|
|
|
|
local msg=was.compiler(pressed.text,name)
|
2019-01-04 08:02:12 -08:00
|
|
|
|
|
|
|
if msg then
|
|
|
|
was.user[name].text=was.gui_addnumbers(was.user[name].text)
|
|
|
|
was.user[name].lines="on"
|
|
|
|
end
|
|
|
|
|
2019-01-03 13:57:48 -08:00
|
|
|
was.gui(name,msg)
|
|
|
|
end
|
|
|
|
end
|
2019-01-04 02:32:59 -08:00
|
|
|
end)
|
|
|
|
|
|
|
|
--was.compiler("if(a==!) test(111)")
|