Initial commit
commit
97aa36c726
|
@ -0,0 +1,96 @@
|
||||||
|
|
||||||
|
# Created by https://www.gitignore.io/api/lua,code,linux,windows
|
||||||
|
# Edit at https://www.gitignore.io/?templates=lua,code,linux,windows
|
||||||
|
|
||||||
|
### Code ###
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
|
||||||
|
### Linux ###
|
||||||
|
*~
|
||||||
|
|
||||||
|
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||||
|
.fuse_hidden*
|
||||||
|
|
||||||
|
# KDE directory preferences
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Linux trash folder which might appear on any partition or disk
|
||||||
|
.Trash-*
|
||||||
|
|
||||||
|
# .nfs files are created when an open file is removed but is still being accessed
|
||||||
|
.nfs*
|
||||||
|
|
||||||
|
### Lua ###
|
||||||
|
# Compiled Lua sources
|
||||||
|
luac.out
|
||||||
|
|
||||||
|
# luarocks build files
|
||||||
|
*.src.rock
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
|
||||||
|
# Object files
|
||||||
|
*.o
|
||||||
|
*.os
|
||||||
|
*.ko
|
||||||
|
*.obj
|
||||||
|
*.elf
|
||||||
|
|
||||||
|
# Precompiled Headers
|
||||||
|
*.gch
|
||||||
|
*.pch
|
||||||
|
|
||||||
|
# Libraries
|
||||||
|
*.lib
|
||||||
|
*.a
|
||||||
|
*.la
|
||||||
|
*.lo
|
||||||
|
*.def
|
||||||
|
*.exp
|
||||||
|
|
||||||
|
# Shared objects (inc. Windows DLLs)
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.so.*
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Executables
|
||||||
|
*.exe
|
||||||
|
*.out
|
||||||
|
*.app
|
||||||
|
*.i*86
|
||||||
|
*.x86_64
|
||||||
|
*.hex
|
||||||
|
|
||||||
|
|
||||||
|
### Windows ###
|
||||||
|
# Windows thumbnail cache files
|
||||||
|
Thumbs.db
|
||||||
|
Thumbs.db:encryptable
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
|
||||||
|
# Dump file
|
||||||
|
*.stackdump
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
# End of https://www.gitignore.io/api/lua,code,linux,windows
|
|
@ -0,0 +1,12 @@
|
||||||
|
unused_args = false
|
||||||
|
allow_defined_top = true
|
||||||
|
|
||||||
|
globals = {
|
||||||
|
"classroom",
|
||||||
|
}
|
||||||
|
|
||||||
|
read_globals = {
|
||||||
|
"minetest",
|
||||||
|
"sfinv",
|
||||||
|
"vector",
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
classroom.register_action("bring", {
|
||||||
|
title = "Bring",
|
||||||
|
description = "Teleport players to your location",
|
||||||
|
online_required = true,
|
||||||
|
func = function(runner, players)
|
||||||
|
local pos = runner:get_pos()
|
||||||
|
|
||||||
|
for _, name in pairs(players) do
|
||||||
|
local player = minetest.get_player_by_name(name)
|
||||||
|
player:set_pos(pos)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
classroom.register_action("look", {
|
||||||
|
title = "Look",
|
||||||
|
description = "Make players look at you",
|
||||||
|
online_required = true,
|
||||||
|
func = function(runner, players)
|
||||||
|
local pos = runner:get_pos()
|
||||||
|
|
||||||
|
for _, name in pairs(players) do
|
||||||
|
local player = minetest.get_player_by_name(name)
|
||||||
|
local pos2 = player:get_pos()
|
||||||
|
player:set_look_horizontal(vector.angle(pos, pos2))
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
classroom.register_action("mute", {
|
||||||
|
title = "Mute",
|
||||||
|
description = "Revoke shout from players",
|
||||||
|
online_required = false,
|
||||||
|
func = function(runner, players)
|
||||||
|
for _, name in pairs(players) do
|
||||||
|
print("Muting " .. name)
|
||||||
|
local privs = minetest.get_player_privs(name)
|
||||||
|
privs.shout = nil
|
||||||
|
minetest.set_player_privs(name, privs)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
classroom.register_action("unmute", {
|
||||||
|
title = "Unmute",
|
||||||
|
description = "Grant shout to players",
|
||||||
|
online_required = false,
|
||||||
|
func = function(runner, players)
|
||||||
|
for _, name in pairs(players) do
|
||||||
|
local privs = minetest.get_player_privs(name)
|
||||||
|
privs.shout = true
|
||||||
|
minetest.set_player_privs(name, privs)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
classroom.register_action("fly", {
|
||||||
|
title = "Fly",
|
||||||
|
description = "Grant fly to players",
|
||||||
|
online_required = false,
|
||||||
|
func = function(runner, players)
|
||||||
|
for _, name in pairs(players) do
|
||||||
|
local privs = minetest.get_player_privs(name)
|
||||||
|
privs.fly = true
|
||||||
|
minetest.set_player_privs(name, privs)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
classroom.register_action("nofly", {
|
||||||
|
title = "NoFly",
|
||||||
|
description = "Revoke fly from players",
|
||||||
|
online_required = false,
|
||||||
|
func = function(runner, players)
|
||||||
|
for _, name in pairs(players) do
|
||||||
|
local privs = minetest.get_player_privs(name)
|
||||||
|
privs.fly = nil
|
||||||
|
minetest.set_player_privs(name, privs)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
|
@ -0,0 +1,73 @@
|
||||||
|
local _groups = {}
|
||||||
|
local _action_by_name = {}
|
||||||
|
|
||||||
|
function classroom.get_students()
|
||||||
|
local students = {}
|
||||||
|
for _, player in pairs(minetest.get_connected_players()) do
|
||||||
|
students[#students + 1] = player:get_player_name()
|
||||||
|
end
|
||||||
|
|
||||||
|
return students
|
||||||
|
end
|
||||||
|
|
||||||
|
function classroom.get_group_students(name)
|
||||||
|
local group = classroom.get_group(name)
|
||||||
|
if not group then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local students = {}
|
||||||
|
for _, student in pairs(group.students) do
|
||||||
|
if minetest.get_player_by_name(group.students) then
|
||||||
|
students[#students + 1] = student
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return students
|
||||||
|
end
|
||||||
|
|
||||||
|
function classroom.get_all_groups()
|
||||||
|
return _groups
|
||||||
|
end
|
||||||
|
|
||||||
|
function classroom.get_group(name)
|
||||||
|
return _groups[name]
|
||||||
|
end
|
||||||
|
|
||||||
|
function classroom.create_group(name)
|
||||||
|
if _groups[name] then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local group = {
|
||||||
|
name = name,
|
||||||
|
students = {},
|
||||||
|
}
|
||||||
|
|
||||||
|
_groups[name] = group
|
||||||
|
|
||||||
|
return group
|
||||||
|
end
|
||||||
|
|
||||||
|
function classroom.register_action(name, def)
|
||||||
|
_action_by_name[name] = def
|
||||||
|
end
|
||||||
|
|
||||||
|
function classroom.get_actions()
|
||||||
|
return _action_by_name
|
||||||
|
end
|
||||||
|
|
||||||
|
function classroom.get_students_by_selector(selector)
|
||||||
|
if selector == "*" then
|
||||||
|
return classroom.get_students()
|
||||||
|
elseif selector:sub(1, 6) == "group:" then
|
||||||
|
return classroom.get_group_students(selector:sub(7))
|
||||||
|
else
|
||||||
|
return { selector }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function classroom.run_action(aname, runner, selector, params)
|
||||||
|
local action = _action_by_name[aname]
|
||||||
|
action.func(runner, classroom.get_students_by_selector(selector))
|
||||||
|
end
|
|
@ -0,0 +1,123 @@
|
||||||
|
local infos = {
|
||||||
|
{
|
||||||
|
title = "Shout?",
|
||||||
|
type = "priv",
|
||||||
|
privs = { shout = true },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title = "Fly?",
|
||||||
|
type = "priv",
|
||||||
|
privs = { fly = true },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title = "Fast?",
|
||||||
|
type = "priv",
|
||||||
|
privs = { fast = true },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local function get_group(context)
|
||||||
|
if context and context.groupname then
|
||||||
|
return classroom.get_group_students(context.groupname)
|
||||||
|
else
|
||||||
|
return classroom.get_students()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
sfinv.register_page("edu", {
|
||||||
|
title = "Classroom",
|
||||||
|
get = function(self, player, context)
|
||||||
|
local fs = {
|
||||||
|
"tablecolumns[color;text"
|
||||||
|
}
|
||||||
|
|
||||||
|
context.select_toggle = context.select_toggle or "all"
|
||||||
|
|
||||||
|
for i, col in pairs(infos) do
|
||||||
|
fs[#fs + 1] = ";color;text,align=center"
|
||||||
|
if i == 1 then
|
||||||
|
fs[#fs + 1] = ",padding=2"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
fs[#fs + 1] = "]"
|
||||||
|
fs[#fs + 1] = "tabheader[0.3,1.1;group;All,Group 1;1]"
|
||||||
|
fs[#fs + 1] = "table[0,0.8;5,8;kids;,Name"
|
||||||
|
for _, col in pairs(infos) do
|
||||||
|
fs[#fs + 1] = ",," .. col.title
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, student in pairs(get_group(context)) do
|
||||||
|
fs[#fs + 1] = ",,"
|
||||||
|
fs[#fs + 1] = minetest.formspec_escape(student)
|
||||||
|
|
||||||
|
for _, col in pairs(infos) do
|
||||||
|
local color, value
|
||||||
|
if col.type == "priv" then
|
||||||
|
local has_priv = minetest.check_player_privs(student, col.privs)
|
||||||
|
color = has_priv and "green" or "red"
|
||||||
|
value = has_priv and "Yes" or "No"
|
||||||
|
end
|
||||||
|
|
||||||
|
fs[#fs + 1] = ","
|
||||||
|
fs[#fs + 1] = color
|
||||||
|
fs[#fs + 1] = ","
|
||||||
|
fs[#fs + 1] = minetest.formspec_escape(value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
fs[#fs + 1] = ";2]"
|
||||||
|
|
||||||
|
|
||||||
|
fs[#fs + 1] = "container[5.25,0]"
|
||||||
|
|
||||||
|
local x = 0
|
||||||
|
local y = 0.8
|
||||||
|
for aname, action in pairs(classroom.get_actions()) do
|
||||||
|
fs[#fs + 1] = "button["
|
||||||
|
fs[#fs + 1] = tostring(x)
|
||||||
|
fs[#fs + 1] = ","
|
||||||
|
fs[#fs + 1] = tostring(y)
|
||||||
|
fs[#fs + 1] = ";1,1;action_"
|
||||||
|
fs[#fs + 1] = aname
|
||||||
|
fs[#fs + 1] = ";"
|
||||||
|
fs[#fs + 1] = minetest.formspec_escape(action.title)
|
||||||
|
fs[#fs + 1] = "]"
|
||||||
|
|
||||||
|
fs[#fs + 1] = "tooltip[action_"
|
||||||
|
fs[#fs + 1] = aname
|
||||||
|
fs[#fs + 1] = ";"
|
||||||
|
fs[#fs + 1] = minetest.formspec_escape(action.description)
|
||||||
|
fs[#fs + 1] = "]"
|
||||||
|
|
||||||
|
if x < 1.5 then
|
||||||
|
x = x + 0.9
|
||||||
|
else
|
||||||
|
x = 0
|
||||||
|
y = y + 0.8
|
||||||
|
end
|
||||||
|
end
|
||||||
|
fs[#fs + 1] = "container_end[]"
|
||||||
|
|
||||||
|
return sfinv.make_formspec(player, context, table.concat(fs, ""), false)
|
||||||
|
end,
|
||||||
|
on_player_receive_fields = function(self, player, context, fields)
|
||||||
|
for aname, action in pairs(classroom.get_actions()) do
|
||||||
|
if fields["action_" .. aname] then
|
||||||
|
local selector
|
||||||
|
if context.select_toggle == "all" then
|
||||||
|
selector = "*"
|
||||||
|
elseif context.select_toggle == "group" then
|
||||||
|
selector = "group:" .. context.groupname
|
||||||
|
elseif context.select_toggle == "selected" then
|
||||||
|
error("Unimplemented")
|
||||||
|
else
|
||||||
|
error("Unknown selector")
|
||||||
|
end
|
||||||
|
|
||||||
|
classroom.run_action(aname, player, selector)
|
||||||
|
sfinv.set_player_inventory_formspec(player)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
|
@ -0,0 +1,5 @@
|
||||||
|
classroom = {}
|
||||||
|
|
||||||
|
dofile(minetest.get_modpath("classroom") .. "/api.lua")
|
||||||
|
dofile(minetest.get_modpath("classroom") .. "/gui.lua")
|
||||||
|
dofile(minetest.get_modpath("classroom") .. "/actions.lua")
|
Loading…
Reference in New Issue