Skip to content

Commit 2fa2627

Browse files
authored
Merge branch 'master' into drop
2 parents af802f1 + e286269 commit 2fa2627

File tree

191 files changed

+3796
-1302
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+3796
-1302
lines changed

.github/pull_request_template.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
3+
- [ ] This PR has been tested locally

.github/workflows/build.yml

-16
This file was deleted.

.github/workflows/luacheck.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: luacheck
2+
on: [push, pull_request]
3+
jobs:
4+
luacheck:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Checkout
8+
uses: actions/checkout@v4
9+
- name: Luacheck
10+
uses: lunarmodules/luacheck@master

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ debug.txt
1313
/mods/ctf/ctf_map/textures/*Back.*
1414
/mods/ctf/ctf_map/textures/*Left.*
1515
/mods/ctf/ctf_map/textures/*Right.*
16-
/mods/ctf/ctf_map/textures/*_screenshot.png
16+
/mods/ctf/ctf_map/textures/*_screenshot.png
17+
18+
*.blend1

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,22 @@ Note that this version may be slightly behind the git version, but it will be a
4545
* If you use Visual Studio Code we recommend these extensions:
4646
* https://marketplace.visualstudio.com/items?itemName=sumneko.lua
4747
* https://marketplace.visualstudio.com/items?itemName=dwenegar.vscode-luacheck
48+
* https://marketplace.visualstudio.com/items?itemName=GreenXenith.minetest-tools
4849

4950
## License
5051

5152
Created by [rubenwardy](https://rubenwardy.com/).
5253
Developed by [LandarVargan](https://github.com/LoneWolfHT).
5354
Previous Developers: [savilli](https://github.com/savilli).
5455

55-
Licenses where not specified:
56-
Code: LGPLv2.1+
57-
Textures: CC-BY-SA 3.0
58-
59-
### Textures
56+
Check out [mods/](mods/) to see all the installed mods and their respective licenses.
6057

61-
* [Header](menu/header.png): CC BY-SA 4.0 by xenonca
62-
* [Background Image](menu/background.png): CC0 (where applicable) by Apelta (Uses [Minetest Game](https://github.com/minetest/minetest_game) textures, the majority of which are licensed CC-BY-SA 3.0). The player skin used is licensed CC-BY-SA 3.0
58+
Licenses where not specified:\
59+
Code: [GNU LGPLv2.1+](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html)\
60+
Media: [CC BY-SA 3.0 Unported](https://creativecommons.org/licenses/by-sa/3.0/)
6361

64-
### Mods
62+
### Textures
6563

66-
Check out [mods/](mods/) to see all the installed mods and their respective licenses.
64+
* [Header](menu/header.png): [CC BY 3.0 Unported](https://creativecommons.org/licenses/by/3.0/) by [SuddenSFD](https://github.com/SuddenSFD)
65+
* [Background Image](menu/background.png): [CC BY-SA 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/) (where applicable) by [GreenBlob](https://github.com/a-blob) (Uses [Minetest Game](https://github.com/minetest/minetest_game) textures, the majority of which are licensed [CC BY-SA 3.0 Unported](https://creativecommons.org/licenses/by-sa/3.0/)). The player skins used are licensed under [CC BY-SA 3.0 Unported](https://creativecommons.org/licenses/by-sa/3.0/)
66+
* [Icon](menu/icon.png): [CC BY 3.0](https://creativecommons.org/licenses/by/3.0/) by [SuddenSFD](https://github.com/SuddenSFD)

docs/accurate_statbar.patch

+10-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ index 46c947b6..f4372843 100644
66
local hud_ids = {}
77

88
local function scaleToDefault(player, field)
9-
+ return player["get_" .. field](player)
10-
- -- Scale "hp" or "breath" to the default dimensions
11-
- local current = player["get_" .. field](player)
12-
- local nominal = core["PLAYER_MAX_".. field:upper() .. "_DEFAULT"]
13-
- local max_display = math.max(nominal,
14-
- math.max(player:get_properties()[field .. "_max"], current))
15-
- return current / max_display * nominal
9+
+ if field == "health" then
10+
+ return player["get_" .. field](player)
11+
+ else
12+
-- Scale "hp" or "breath" to the default dimensions
13+
local current = player["get_" .. field](player)
14+
local nominal = core["PLAYER_MAX_".. field:upper() .. "_DEFAULT"]
15+
local max_display = math.max(nominal,
16+
math.max(player:get_properties()[field .. "_max"], current))
17+
return current / max_display * nominal
18+
+ end
1619
end
1720

1821
local function update_builtin_statbars(player)

docs/ctf-api.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
CaptureTheFlag Lua API Reference
22
==================================
33

4+
# Code Style
5+
* Use tabs for indentation.
6+
47
# mods/apis/
58
This folder contains a collection of mods with the main goal of providing an API
69

@@ -21,7 +24,7 @@ ctf_settings.register("my_setting", {
2124
on_change = function(player, new_value)
2225
<...>
2326
end
24-
}
27+
})
2528
```
2629

2730
### `ctf_settings.set(player, setting, value)`
@@ -36,7 +39,10 @@ ctf_settings.register("my_setting", {
3639

3740
---
3841
# mods/ctf/
39-
TODO
42+
TODO, below is a collection of quick notes for later
43+
44+
## ctf_teams
45+
* https://modern.ircdocs.horse/formatting.html#colors-16-98
4046

4147
---
4248
# mods/mtg/

menu/background.png

1.36 MB
Loading

menu/header.png

-39.3 KB
Loading

menu/icon.png

-2.82 KB
Loading

mods/apis/ctf_gui/dev.lua

+26-9
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,48 @@
1+
local unset_function = "return "
2+
13
function ctf_gui.show_formspec_dev(player, formname, formspec, formcontext)
24
local filepath = minetest.get_worldpath().."/ctf_gui/"
35
local filename = filepath.."file_edit.txt"
6+
local slower_loop = false
7+
8+
minetest.chat_send_all("Started formspec editing file at "..filename)
49

510
minetest.mkdir(filepath)
611

712
local file = assert(io.open(filename, "w"))
8-
9-
file:write(formspec)
10-
13+
if type(formspec) ~= "function" then
14+
file:write(formspec)
15+
else
16+
file:write(unset_function)
17+
end
1118
file:close()
1219

1320
local function interval()
14-
if formspec:sub(1, 3) == "[f]" then
15-
local result, form = pcall(loadstring(formspec:sub(4)), formcontext)
16-
ctf_gui.show_formspec(player, formname, result and form or "")
21+
if type(formspec) == "function" then
22+
ctf_gui.show_formspec(player, formname, formspec(formcontext))
23+
elseif formspec:match("^%s*return") then
24+
local result, form = pcall((loadstring(formspec) or function() return function() end end)(), formcontext)
25+
26+
ctf_gui.show_formspec(player, formname,
27+
result and form or "size[10,10]hypertext[0,0;10,10;err;"..minetest.formspec_escape(form or "").."]"
28+
)
29+
30+
slower_loop = not result
1731
else
1832
ctf_gui.show_formspec(player, formname, formspec)
1933
end
2034

21-
minetest.after(1, function()
35+
minetest.after(slower_loop and 3 or 1, function()
2236
local f = assert(io.open(filename, "r"))
37+
local new_form = f:read("*a")
2338

24-
formspec = f:read("*a")
39+
if new_form ~= unset_function then
40+
formspec = new_form
41+
end
2542

2643
f:close()
2744

28-
if formspec:match("^exit") then
45+
if type(formspec) == "function" or not formspec:match("^exit") then
2946
interval()
3047
else
3148
minetest.request_shutdown("Formspec dev requested shutdown", true)

mods/apis/ctf_gui/init.lua

+11-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function ctf_gui.init()
3939
local action = ctx._on_formspec_input(pname, ctx, fields, ...)
4040

4141
if action == "refresh" then
42+
minetest.log("action", "Refreshing formspec "..dump(ctx._formname).." to "..dump(pname))
4243
minetest.show_formspec(pname, ctx._formname, ctx._formspec(ctx))
4344
end
4445
end
@@ -115,6 +116,7 @@ function ctf_gui.show_formspec(player, formname, formspec, formcontext)
115116
context[player]._formname = formname
116117
context[player]._formspec = formspec
117118

119+
minetest.log("action", "Showing new_formspec "..dump(formname).." to "..dump(player))
118120
if type(formspec) == "function" then
119121
minetest.show_formspec(player, formname, formspec(formcontext))
120122
else
@@ -144,6 +146,7 @@ do
144146
end
145147
end
146148

149+
-- minetest.log("action", "[ctf_gui] unpacking: "..dump(l))
147150
return format(base, unpck(l))
148151
end
149152

@@ -457,9 +460,16 @@ function ctf_gui.old_show_formspec(player, formname, formdef)
457460
formdef._info = formdef
458461
context[player] = formdef
459462

460-
minetest.show_formspec(player, formname, formspec)
463+
if minetest.get_player_by_name(player) then
464+
minetest.log("action", "Showing formspec "..dump(formname).." to "..dump(player))
465+
minetest.show_formspec(player, formname, formspec)
466+
end
461467
end,
462468
formdef, ctf_gui.ELEM_SIZE, ctf_gui.SCROLLBAR_WIDTH)
463469
end
464470

471+
minetest.register_on_leaveplayer(function(player)
472+
context[player:get_player_name()] = nil
473+
end)
474+
465475
dofile(minetest.get_modpath("ctf_gui").."/dev.lua")

mods/apis/ctf_settings/init.lua

+59-16
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ctf_settings = {
33
settings_list = {},
44
}
55

6-
local FORMSIZE = {x = 8, y = 5}
6+
local FORMSIZE = {x = 8, y = 9.4}
77
local SCROLLBAR_W = 0.4
88

99
minetest.after(0, function()
@@ -29,16 +29,35 @@ function ctf_settings.register(name, def)
2929
table.insert(ctf_settings.settings_list, name)
3030
end
3131

32+
---@param player ObjectRef
3233
function ctf_settings.set(player, setting, value)
3334
player:get_meta():set_string("ctf_settings:"..setting, value)
3435
end
3536

37+
---@param player ObjectRef
3638
---@return string Returns the player's chosen setting value, the default given at registration, or if both are unset: ""
3739
function ctf_settings.get(player, setting)
3840
local value = player:get_meta():get_string("ctf_settings:"..setting)
3941
local info = ctf_settings.settings[setting]
4042

41-
return value == "" and info.default or value
43+
return value == "" and (info and info.default) or value
44+
end
45+
46+
-- This Function MIT by Rubenwardy
47+
--- Creates a scrollbaroptions for a scroll_container
48+
--
49+
-- @param visible_l the length of the scroll_container and scrollbar
50+
-- @param total_l length of the scrollable area
51+
-- @param scroll_factor as passed to scroll_container
52+
local function make_scrollbaroptions_for_scroll_container(visible_l, total_l, scroll_factor)
53+
54+
assert(total_l >= visible_l)
55+
56+
local thumb_size = (visible_l / total_l) * (total_l - visible_l)
57+
58+
local max = total_l - visible_l
59+
60+
return ("scrollbaroptions[min=0;max=%f;thumbsize=%f]"):format(max / scroll_factor, thumb_size / scroll_factor)
4261
end
4362

4463
minetest.register_on_mods_loaded(function()
@@ -48,30 +67,48 @@ minetest.register_on_mods_loaded(function()
4867
local setting_list = {}
4968
local lastypos = -0.5
5069

70+
if not context then
71+
context = {}
72+
end
73+
74+
if not context.setting then
75+
context.setting = {}
76+
end
77+
5178
for k, setting in ipairs(ctf_settings.settings_list) do
5279
local settingdef = ctf_settings.settings[setting]
5380

81+
if not context.setting[setting] then
82+
context.setting[setting] = ctf_settings.get(player, setting)
83+
end
84+
5485
if settingdef.type == "bool" then
5586
setting_list[k] = {
5687
"checkbox[0,%f;%s;%s;%s]tooltip[%s;%s]",
5788
lastypos,
5889
setting,
5990
settingdef.label or setting,
60-
ctf_settings.get(player, setting),
91+
context.setting[setting],
6192
setting,
6293
settingdef.description or HumanReadable(setting)
6394
}
6495

6596
lastypos = lastypos + 0.5
6697
elseif settingdef.type == "list" then
98+
local max_len = 0
99+
100+
for _, val in pairs(settingdef.list) do
101+
max_len = math.max(val:len(), max_len)
102+
end
103+
67104
lastypos = lastypos + 0.3
68105
setting_list[k] = {
69106
"dropdown[0,%f;%f;%s;%s;%d]tooltip[0,%f;%f,0.6;%s]",
70107
lastypos,
71-
FORMSIZE.x/1.7,
108+
math.max(FORMSIZE.x / 2, math.min(FORMSIZE.x - SCROLLBAR_W + 2, 0.5 + (max_len * 0.23))),
72109
setting,
73110
settingdef.list,
74-
ctf_settings.get(player, setting),
111+
context.setting[setting],
75112
--label
76113
lastypos,
77114
(FORMSIZE.x/1.7) - 0.3,
@@ -84,21 +121,21 @@ minetest.register_on_mods_loaded(function()
84121
local form = {
85122
{"box[-0.1,-0.1;%f,%f;#00000055]", FORMSIZE.x - SCROLLBAR_W, FORMSIZE.y},
86123
{"scroll_container[-0.1,0.3;%f,%f;settings_scrollbar;vertical;0.1]",
87-
FORMSIZE.x - SCROLLBAR_W,
124+
FORMSIZE.x - SCROLLBAR_W + 2,
88125
FORMSIZE.y + 0.7
89126
},
90127
ctf_gui.list_to_formspec_str(setting_list),
91128
"scroll_container_end[]",
92-
{"scrollbaroptions[max=%d]", math.ceil((lastypos - 3.833) * 11.538)},
129+
make_scrollbaroptions_for_scroll_container(FORMSIZE.y + 0.7, math.max(lastypos+1, FORMSIZE.y + 0.7), 0.1),
93130
{"scrollbar[%f,-0.1;%f,%f;vertical;settings_scrollbar;%f]",
94131
FORMSIZE.x - SCROLLBAR_W,
95132
SCROLLBAR_W,
96133
FORMSIZE.y,
97-
context and context.settings_scrollbar or 0
134+
context.settings_scrollbar or 0
98135
},
99136
}
100137

101-
return sfinv.make_formspec(player, context, ctf_gui.list_to_formspec_str(form), true)
138+
return sfinv.make_formspec(player, context, ctf_gui.list_to_formspec_str(form), false)
102139
end,
103140
on_player_receive_fields = function(self, player, context, fields)
104141
local refresh = false
@@ -110,24 +147,30 @@ minetest.register_on_mods_loaded(function()
110147
if setting.type == "bool" then
111148
local newvalue = value == "true" and "true" or "false"
112149

113-
ctf_settings.set(player, field, newvalue)
150+
if context.setting[field] ~= newvalue then
151+
context.setting[field] = newvalue
152+
ctf_settings.set(player, field, newvalue)
114153

115-
if setting.on_change then
116-
setting.on_change(player, newvalue)
154+
if setting.on_change then
155+
setting.on_change(player, newvalue)
156+
end
157+
158+
refresh = true
117159
end
118160
elseif setting.type == "list" then
119161
local idx = table.indexof(setting.list, value)
120162

121-
if idx ~= -1 then
163+
if idx ~= -1 and context.setting[field] ~= tostring(idx) then
164+
context.setting[field] = tostring(idx)
122165
ctf_settings.set(player, field, tostring(idx))
123166

124167
if setting.on_change then
125-
setting.on_change(player, idx)
168+
setting.on_change(player, tostring(idx))
126169
end
170+
171+
refresh = true
127172
end
128173
end
129-
130-
refresh = true
131174
end
132175
end
133176

0 commit comments

Comments
 (0)