diff --git a/actions.lua b/actions.lua index b243ce7..9b0568b 100644 --- a/actions.lua +++ b/actions.lua @@ -1,6 +1,8 @@ +local S = classroom.S + classroom.register_action("bring", { - title = "Bring", - description = "Teleport players to your location", + title = S"Bring", + description = S"Teleport players to your location", online_required = true, func = function(runner, players) local pos = runner:get_pos() @@ -13,8 +15,8 @@ classroom.register_action("bring", { }) classroom.register_action("look", { - title = "Look", - description = "Make players look at you", + title = S"Look", + description = S"Make players look at you", online_required = true, func = function(runner, players) local pos = runner:get_pos() @@ -28,8 +30,8 @@ classroom.register_action("look", { }) classroom.register_action("mute", { - title = "Mute", - description = "Revoke shout from players", + title = S"Mute", + description = S"Revoke shout from players", online_required = false, func = function(runner, players) for _, name in pairs(players) do @@ -42,8 +44,8 @@ classroom.register_action("mute", { }) classroom.register_action("unmute", { - title = "Unmute", - description = "Grant shout to players", + title = S"Unmute", + description = S"Grant shout to players", online_required = false, func = function(runner, players) for _, name in pairs(players) do @@ -55,8 +57,8 @@ classroom.register_action("unmute", { }) classroom.register_action("fly", { - title = "Fly", - description = "Grant fly to players", + title = S"Fly", + description = S"Grant fly to players", online_required = false, func = function(runner, players) for _, name in pairs(players) do @@ -68,8 +70,8 @@ classroom.register_action("fly", { }) classroom.register_action("nofly", { - title = "NoFly", - description = "Revoke fly from players", + title = S"NoFly", + description = S"Revoke fly from players", online_required = false, func = function(runner, players) for _, name in pairs(players) do diff --git a/gui.lua b/gui.lua index b16cfa0..ddf651e 100644 --- a/gui.lua +++ b/gui.lua @@ -1,16 +1,18 @@ +local S = classroom.S +local FS = classroom.FS local infos = { { - title = "Shout?", + title = S"Shout?", type = "priv", privs = { shout = true }, }, { - title = "Fly?", + title = S"Fly?", type = "priv", privs = { fly = true }, }, { - title = "Fast?", + title = S"Fast?", type = "priv", privs = { fast = true }, }, @@ -25,7 +27,7 @@ local function get_group(context) end sfinv.register_page("classroom:edu", { - title = "Classroom", + title = S"Classroom", check_perm = function(self, player) return minetest.check_player_privs(player:get_player_name(), { teacher = true }) end, @@ -34,7 +36,7 @@ sfinv.register_page("classroom:edu", { end, get = function(self, player, context) if not self:check_perm(player) then - return "label[0,0;Access denied]" + return "label[0,0;" .. FS"Access denied" .. "]" end local fs = { @@ -52,7 +54,8 @@ sfinv.register_page("classroom:edu", { fs[#fs + 1] = "]" do - fs[#fs + 1] = "tabheader[0.3,1.1;group;All" + fs[#fs + 1] = "tabheader[0.3,1.1;group;" + fs[#fs + 1] = FS"All" local selected_group_idx = 1 local i = 2 for name, group in pairs(classroom.get_all_groups()) do @@ -88,7 +91,7 @@ sfinv.register_page("classroom:edu", { 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" + value = has_priv and FS"Yes" or FS"No" end fs[#fs + 1] = "," @@ -102,46 +105,78 @@ sfinv.register_page("classroom:edu", { fs[#fs + 1] = selection_id fs[#fs + 1] = "]" - fs[#fs + 1] = "button[5.25,-0.2;1.4,1;new_group;New Group]" + fs[#fs + 1] = "button[5.25,-0.2;1.4,1;new_group;" + fs[#fs + 1] = FS"New Group" + fs[#fs + 1] = "]" if context.groupname then - fs[#fs + 1] = "button[6.65,-0.2;1.4,1;edit_group;Edit Group]" + fs[#fs + 1] = "button[6.65,-0.2;1.4,1;edit_group;" + fs[#fs + 1] = FS"Edit Group" + fs[#fs + 1] = "]" else fs[#fs + 1] = "box[6.65,-0.1;1.2,0.7;#222]" - fs[#fs + 1] = "label[6.8,0.05;Edit Group]" - fs[#fs + 1] = "tooltip[6.65,-0.2;1.4,1;Please select a group first]" + fs[#fs + 1] = "label[6.8,0.05;" + fs[#fs + 1] = FS"Edit Group" + fs[#fs + 1] = "]" + fs[#fs + 1] = "tooltip[6.65,-0.2;1.4,1;" + fs[#fs + 1] = FS"Please select a group first" + fs[#fs + 1] = "]" end fs[#fs + 1] = "container[5.25,1.1]" fs[#fs + 1] = "box[-0.25,-0.3;3.1,1.15;#666]" - fs[#fs + 1] = "label[0,-0.3;Run actions on:]" + fs[#fs + 1] = "label[0,-0.3;" + fs[#fs + 1] = FS"Run actions on:" + fs[#fs + 1] = "]" if context.select_toggle == "all" then fs[#fs + 1] = "box[0,0.1;0.8,0.7;#53ac56]" - fs[#fs + 1] = "label[0.3,0.25;All]" + fs[#fs + 1] = "label[0.3,0.25;" + fs[#fs + 1] = FS"All" + fs[#fs + 1] = "]" else - fs[#fs + 1] = "button[0,0;1,1;select_all;All]" + fs[#fs + 1] = "button[0,0;1,1;select_all;" + fs[#fs + 1] = FS"All" + fs[#fs + 1] = "]" end if not context.groupname then fs[#fs + 1] = "box[0.9,0.1;0.8,0.7;#333]" - fs[#fs + 1] = "label[1.05,0.25;Group]" - fs[#fs + 1] = "tooltip[0.9,0;1,1;Please select a group first]" + fs[#fs + 1] = "label[1.05,0.25;" + fs[#fs + 1] = FS"Group" + fs[#fs + 1] = "]" + fs[#fs + 1] = "tooltip[0.9,0;1,1;" + fs[#fs + 1] = FS"Please select a group first" + fs[#fs + 1] = "]" elseif context.select_toggle == "group" then fs[#fs + 1] = "box[0.9,0.1;0.8,0.7;#53ac56]" - fs[#fs + 1] = "label[1.05,0.25;Group]" + fs[#fs + 1] = "label[1.05,0.25;" + fs[#fs + 1] = FS"Group" + fs[#fs + 1] = "]" else - fs[#fs + 1] = "button[0.9,0;1,1;select_group;Group]" + fs[#fs + 1] = "button[0.9,0;1,1;select_group;" + fs[#fs + 1] = FS"Group" + fs[#fs + 1] = "]" end if not context.selected_student then fs[#fs + 1] = "box[1.8,0.1;0.8,0.7;#333]" - fs[#fs + 1] = "label[1.85,0.25;Selected]" - fs[#fs + 1] = "tooltip[1.8,0;1,1;Please select a student first]" + fs[#fs + 1] = "label[1.85,0.25;" + fs[#fs + 1] = FS"Selected" + fs[#fs + 1] = "]" + fs[#fs + 1] = "tooltip[1.8,0;1,1;" + fs[#fs + 1] = FS"Please select a student first" + fs[#fs + 1] = "]" elseif context.select_toggle == "selected" then fs[#fs + 1] = "box[1.8,0.1;0.8,0.7;#53ac56]" - fs[#fs + 1] = "label[1.85,0.25;Selected]" + fs[#fs + 1] = "label[1.85,0.25;" + fs[#fs + 1] = FS"Selected" + fs[#fs + 1] = "]" else - fs[#fs + 1] = "button[1.8,0;1,1;select_selected;Selected]" + fs[#fs + 1] = "button[1.8,0;1,1;select_selected;" + fs[#fs + 1] = FS"Selected" + fs[#fs + 1] = "]" end - fs[#fs + 1] = "label[0,0.9;Actions]" + fs[#fs + 1] = "label[0,0.9;" + fs[#fs + 1] = FS"Actions:" + fs[#fs + 1] = "]" local x = 0 local y = 1.2 @@ -177,10 +212,12 @@ sfinv.register_page("classroom:edu", { fs[#fs + 1] = tostring(y) fs[#fs + 1] = "]" - fs[#fs + 1] = "label[0,-0.1;Selected user: " - fs[#fs + 1] = minetest.formspec_escape(context.selected_student) + fs[#fs + 1] = "label[0,-0.1;" + fs[#fs + 1] = FS("Selected user: @1", context.selected_student) + fs[#fs + 1] = "]" + fs[#fs + 1] = "button[0,0.3;1.5,1;teleport;" + fs[#fs + 1] = FS"Teleport to" fs[#fs + 1] = "]" - fs[#fs + 1] = "button[0,0.3;1.5,1;teleport;Teleport To]" fs[#fs + 1] = "container_end[]" end @@ -303,11 +340,11 @@ function classroom.show_new_group(player) return end - minetest.show_formspec(player:get_player_name(), "classroom:new_group", [[ - size[5,1.8] - field[0.2,0.4;5,1;name;Name;] - button[1.5,1;2,1;create;Create] - ]]) + minetest.show_formspec(player:get_player_name(), "classroom:new_group", table.concat({ + "size[5,1.8]", + "field[0.2,0.4;5,1;name;", FS"Name", ";]", + "button[1.5,1;2,1;create;", FS"Create", "]", + }, "")) end @@ -344,8 +381,10 @@ function classroom.show_edit_group(player, groupname) local fs = { "size[5.55,6]", - "label[0,-0.1;Other students]", - "label[3.3,-0.1;Students in group ", minetest.formspec_escape(context.groupname), "]", + "label[0,-0.1;", FS"Other students", "]", + "label[3.3,-0.1;", + FS("Students in group @1", context.groupname), + "]", "button[2.25,0.5;1,1;go_right;", minetest.formspec_escape(">"), "]", "button[2.25,1.5;1,1;go_left;", minetest.formspec_escape("<"), "]", } @@ -367,7 +406,9 @@ function classroom.show_edit_group(player, groupname) fs[#fs + 1] = tostring(context.index_r) fs[#fs + 1] = "]" else - fs[#fs + 1] = "label[3.5,0.7;No students]" + fs[#fs + 1] = "label[3.5,0.7;" + fs[#fs + 1] = FS("No students") + fs[#fs + 1] = "]" end local not_members = classroom.get_students_except(members) @@ -389,7 +430,9 @@ function classroom.show_edit_group(player, groupname) fs[#fs + 1] = tostring(context.index_l) fs[#fs + 1] = "]" else - fs[#fs + 1] = "label[0.4,0.7;No students]" + fs[#fs + 1] = "label[0.4,0.7;" + fs[#fs + 1] = FS("No students") + fs[#fs + 1] = "]" end minetest.show_formspec(player:get_player_name(), "classroom:edit_group", table.concat(fs, "")) diff --git a/init.lua b/init.lua index 408e464..88d4c0e 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,10 @@ classroom = {} +classroom.S = minetest.get_translator("classroom") +classroom.FS = function(...) + return minetest.formspec_escape(classroom.S(...)) +end + dofile(minetest.get_modpath("classroom") .. "/api.lua") dofile(minetest.get_modpath("classroom") .. "/gui.lua") dofile(minetest.get_modpath("classroom") .. "/actions.lua") @@ -8,6 +13,7 @@ minetest.register_privilege("teacher", { give_to_singleplayer = false }) +-- Hooks needed to make api.lua testable classroom.get_connected_players = minetest.get_connected_players classroom.get_player_by_name = minetest.get_player_by_name classroom.check_player_privs = minetest.check_player_privs diff --git a/tests/api_spec.lua b/tests/api_spec.lua index e11c3b1..2f1b6d0 100644 --- a/tests/api_spec.lua +++ b/tests/api_spec.lua @@ -8,6 +8,7 @@ end local function recreate_classroom() _G.classroom = { + S = string.format, get_connected_players = function() return { fake_player("user1"), diff --git a/utils/client.conf b/utils/client.conf new file mode 100644 index 0000000..58c7654 --- /dev/null +++ b/utils/client.conf @@ -0,0 +1,4 @@ +max_fps = 5 +screen_h = 30 +screen_w = 30 +enable_shaders = false diff --git a/utils/server.conf b/utils/server.conf new file mode 100644 index 0000000..f5c262a --- /dev/null +++ b/utils/server.conf @@ -0,0 +1,2 @@ +name = teacher1 +port = 30000 diff --git a/utils/start.sh b/utils/start.sh index 010b82a..81f233e 100755 --- a/utils/start.sh +++ b/utils/start.sh @@ -10,9 +10,17 @@ find_minetest() { echo "Found minetest at: $MT_DIR" } +set_conf() { + # Make readonly config + conf=/tmp/$1.conf + chmod 0644 $conf # incase it already exists + cp utils/$1.conf /tmp/$1.conf + chmod 0444 $conf +} + start_server() { echo "Starting server" - $MT --server --port 30000 --world "${MT_DIR}/worlds/edu" --name "teacher1" & + $MT --server --port 30000 --world "${MT_DIR}/worlds/edu" --name "teacher1" --config "$conf" & } start_client() { @@ -22,15 +30,16 @@ start_client() { start_headless_client() { echo "Starting headless client $1" - xvfb-run $MT --address "127.0.0.1" --name $1 --password "pass" --go & + xvfb-run $MT --address "127.0.0.1" --name $1 --password "pass" --config "$conf" --go & } find_minetest -build_conf +set_conf server start_server +set_conf client start_headless_client student1 start_headless_client student2 start_headless_client student3