Skip to content

Commit

Permalink
Merge branch 'master' into score
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWolfHT authored Aug 20, 2024
2 parents 22356fd + 7c622b3 commit ed51e9a
Show file tree
Hide file tree
Showing 63 changed files with 1,616 additions and 843 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/build.yml

This file was deleted.

10 changes: 10 additions & 0 deletions .github/workflows/luacheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: luacheck
on: [push, pull_request]
jobs:
luacheck:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Luacheck
uses: lunarmodules/luacheck@master
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Note that this version may be slightly behind the git version, but it will be a
* If you use Visual Studio Code we recommend these extensions:
* https://marketplace.visualstudio.com/items?itemName=sumneko.lua
* https://marketplace.visualstudio.com/items?itemName=dwenegar.vscode-luacheck
* https://marketplace.visualstudio.com/items?itemName=GreenXenith.minetest-tools

## License

Expand Down
5 changes: 4 additions & 1 deletion docs/ctf-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ ctf_settings.register("my_setting", {

---
# mods/ctf/
TODO
TODO, below is a collection of quick notes for later

## ctf_teams
* https://modern.ircdocs.horse/formatting.html#colors-16-98

---
# mods/mtg/
Expand Down
6 changes: 3 additions & 3 deletions mods/apis/ctf_gui/dev.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local unset_function = "[f]\nreturn "
local unset_function = "return "

function ctf_gui.show_formspec_dev(player, formname, formspec, formcontext)
local filepath = minetest.get_worldpath().."/ctf_gui/"
Expand All @@ -20,8 +20,8 @@ function ctf_gui.show_formspec_dev(player, formname, formspec, formcontext)
local function interval()
if type(formspec) == "function" then
ctf_gui.show_formspec(player, formname, formspec(formcontext))
elseif formspec:sub(1, 3) == "[f]" then
local result, form = pcall((loadstring(formspec:sub(4)) or function() return function() end end)(), formcontext)
elseif formspec:match("^%s*return") then
local result, form = pcall((loadstring(formspec) or function() return function() end end)(), formcontext)

ctf_gui.show_formspec(player, formname,
result and form or "size[10,10]hypertext[0,0;10,10;err;"..minetest.formspec_escape(form or "").."]"
Expand Down
39 changes: 37 additions & 2 deletions mods/apis/ctf_settings/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function ctf_settings.get(player, setting)
local value = player:get_meta():get_string("ctf_settings:"..setting)
local info = ctf_settings.settings[setting]

return value == "" and info.default or value
return value == "" and (info and info.default) or value
end

-- This Function MIT by Rubenwardy
Expand Down Expand Up @@ -115,11 +115,33 @@ minetest.register_on_mods_loaded(function()
settingdef.description or HumanReadable(setting),
}
lastypos = lastypos + 0.6
elseif settingdef.type == "bar" then
lastypos = lastypos + 0.7
setting_list[k] = {
"label[0,%f;%s: %d%%]"..
"scrollbaroptions[min=%d;max=%d;smallstep=%d]"..
"scrollbar[0,%f;%f,0.4;horizontal;%s;%s]",
lastypos - 0.5,
settingdef.label or HumanReadable(setting),
(
tonumber(context.setting[setting])
/
((settingdef.max - settingdef.min) - tonumber(settingdef.default))
) * 100,
settingdef.min or 0,
settingdef.max or 10,
settingdef.step or 1,
lastypos,
FORMSIZE.x - SCROLLBAR_W -2,
setting,
context.setting[setting],
}
lastypos = lastypos + 0.5
end
end

local form = {
{"box[-0.1,-0.1;%f,%f;#00000055]", FORMSIZE.x - SCROLLBAR_W, FORMSIZE.y},
{"box[-0.1,-0.1;%f,%f;#00000055]", FORMSIZE.x - SCROLLBAR_W, FORMSIZE.y},
{"scroll_container[-0.1,0.3;%f,%f;settings_scrollbar;vertical;0.1]",
FORMSIZE.x - SCROLLBAR_W + 2,
FORMSIZE.y + 0.7
Expand Down Expand Up @@ -168,6 +190,19 @@ minetest.register_on_mods_loaded(function()
setting.on_change(player, tostring(idx))
end

refresh = true
end
elseif setting.type == "bar" then
local scrollevent = minetest.explode_scrollbar_event(value)

if scrollevent.value and context.setting[field] ~= tostring(scrollevent.value) then
context.setting[field] = tostring(scrollevent.value)
ctf_settings.set(player, field, tostring(scrollevent.value))

if setting.on_change then
setting.on_change(player, tostring(scrollevent.value))
end

refresh = true
end
end
Expand Down
64 changes: 40 additions & 24 deletions mods/apis/hud_events/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@ local HUD_COLORS = {
dark = 0x212529,
}

local hud_queues = {}
local hud_queues = {
-- {}, channel 1
-- {}, channel 2
-- ...
}
local quick_event_timer = {}

minetest.register_on_leaveplayer(function(player)
local pname = player:get_player_name()

if hud_queues[pname] then
hud_queues[pname].t:cancel()
hud_queues[pname] = nil
for channel=1, #hud_queues do
if hud_queues[channel][pname] then
hud_queues[channel][pname].t:cancel()
hud_queues[channel][pname] = nil
end
end

if quick_event_timer[pname] then
Expand All @@ -41,7 +47,7 @@ local function show_quick_hud_event(player, huddef)
hud:add(player, "hud_event_quick", {
hud_elem_type = "text",
position = {x = 0.5, y = 0.5},
offset = {x = 0, y = 45},
offset = {x = 0, y = 20},
alignment = {x = "center", y = "down"},
text = huddef.text,
color = huddef.color,
Expand All @@ -56,46 +62,49 @@ local function show_quick_hud_event(player, huddef)
quick_event_timer[pname] = minetest.after(HUD_SHOW_QUICK_TIME, function()
if not player:is_player() then return end

hud:remove(player, "hud_event_quick")
if hud:exists(player, "hud_event_quick") then
hud:remove(player, "hud_event_quick")
end
end)
end

local function handle_hud_events(player)
local function handle_hud_events(player, channel)
local pname = player:get_player_name()

local huddef = table.remove(hud_queues[pname].e, 1)
local huddef = table.remove(hud_queues[channel][pname].e, 1)
local event_name = "hud_event_"..tostring(channel)

if not hud:exists(player, "hud_event") then
hud:add(player, "hud_event", {
if not hud:exists(player, event_name) then
hud:add(player, event_name, {
hud_elem_type = "text",
position = {x = 0.5, y = 0.5},
offset = {x = 0, y = 20},
offset = {x = 0, y = 45 + (channel - 1) * 25},
alignment = {x = "center", y = "down"},
text = huddef.text,
color = huddef.color,
})
else
hud:change(player, "hud_event", {
hud:change(player, event_name, {
text = huddef.text,
color = huddef.color
})
end

hud_queues[pname].t = minetest.after(HUD_SHOW_TIME, function()
hud_queues[channel][pname].t = minetest.after(HUD_SHOW_TIME, function()
player = minetest.get_player_by_name(pname)

if player then
hud:change(player, "hud_event", {text = ""})
hud:change(player, event_name, {text = ""})

hud_queues[pname].t = minetest.after(HUD_SHOW_NEXT_TIME, function()
hud_queues[channel][pname].t = minetest.after(HUD_SHOW_NEXT_TIME, function()
player = minetest.get_player_by_name(pname)

if player then
if #hud_queues[pname].e >= 1 then
handle_hud_events(player)
if #hud_queues[channel][pname].e >= 1 then
handle_hud_events(player, channel)
else
hud:remove(player, "hud_event")
hud_queues[pname] = nil
hud:remove(player, event_name)
hud_queues[channel][pname] = nil
end
end
end)
Expand All @@ -108,6 +117,7 @@ end
text = "This is a hud event",
color = "info",
quick = true,
channel = an integer or nil
})
]]
function hud_events.new(player, def)
Expand All @@ -118,6 +128,8 @@ function hud_events.new(player, def)
def = {text = def}
end

def.channel = def.channel or 1

if def.color then
if type(def.color) == "string" then
def.color = HUD_COLORS[def.color]
Expand All @@ -129,13 +141,17 @@ function hud_events.new(player, def)
if not def.quick then
local pname = player:get_player_name()

if not hud_queues[pname] then
hud_queues[pname] = {e = {}}
while not hud_queues[def.channel] do
table.insert(hud_queues, {})
end

if not hud_queues[def.channel][pname] then
hud_queues[def.channel][pname] = {e = {}}
end
table.insert(hud_queues[pname].e, {text = def.text, color = def.color})
table.insert(hud_queues[def.channel][pname].e, {text = def.text, color = def.color, channel = def.channel})

if not hud_queues[pname].t then
handle_hud_events(player)
if not hud_queues[def.channel][pname].t then
handle_hud_events(player, def.channel)
end
else
show_quick_hud_event(player, def)
Expand Down
2 changes: 1 addition & 1 deletion mods/ctf/ctf_chat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ minetest.register_chatcommand("t", {
local tcolor = ctf_teams.team[tname].color
for username in pairs(ctf_teams.online_players[tname].players) do
minetest.chat_send_player(username,
minetest.colorize(tcolor, "<" .. name .. "> ** " .. param .. " **"))
minetest.colorize(tcolor, "[TEAM] <" .. name .. "> " .. param ))
end
else
minetest.chat_send_player(name,
Expand Down
5 changes: 5 additions & 0 deletions mods/ctf/ctf_combat/ctf_healing/bandage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ function ctf_healing.register_bandage(name, def)
text = uname .. " healed you!",
color = 0xC1FF44,
})
hud_events.new(uname, {
quick = true,
text = "You healed "..pname.."!",
color = 0xC1FF44,
})
elseif type(result) == "string" then
hud_events.new(uname, {
quick = true,
Expand Down
5 changes: 5 additions & 0 deletions mods/ctf/ctf_combat/ctf_kill_list/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ local kill_list = {}

local image_scale_map = ctf_settings.settings["ctf_kill_list:tp_size"].image_scale_map
local function update_hud_line(player, idx, new)
if not ctf_teams.get(player) then
hud:clear(player)
return
end

idx = HUD_LINES - (idx-1)

local image_scale = tonumber(ctf_settings.get(player, "ctf_kill_list:tp_size"))
Expand Down
4 changes: 2 additions & 2 deletions mods/ctf/ctf_combat/ctf_ranged/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ local function process_ray(ray, user, look_dir, def)
end
end
elseif hitpoint.type == "object" then
hitpoint.ref:punch(user, 1, {
full_punch_interval = 1,
hitpoint.ref:punch(user, def.fire_interval or 0.1, {
full_punch_interval = def.fire_interval or 0.1,
damage_groups = {ranged = 1, [def.type] = 1, fleshy = def.damage}
}, look_dir)
end
Expand Down
55 changes: 30 additions & 25 deletions mods/ctf/ctf_map/ctf_traps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,35 +68,40 @@ minetest.register_node("ctf_map:spike", {
})

for _, team in ipairs(ctf_teams.teamlist) do
local spikecolor = ctf_teams.team[team].color

minetest.register_node("ctf_map:spike_"..team, {
description = HumanReadable(team).." Team Spike",
drawtype = "plantlike",
tiles = {"ctf_map_spike.png^[colorize:"..spikecolor..":150"},
inventory_image = "ctf_map_spike.png^[colorize:"..spikecolor..":150",
use_texture_alpha = "clip",
paramtype = "light",
paramtype2 = "meshoptions",
sunlight_propagates = true,
walkable = false,
damage_per_second = 7,
groups = {cracky=1, level=2},
drop = "ctf_map:spike",
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
on_place = function(itemstack, placer, pointed_thing)
return minetest.item_place(itemstack, placer, pointed_thing, 34)
end
})
if not ctf_teams.team[team].not_playing then
local spikecolor = ctf_teams.team[team].color

minetest.register_node("ctf_map:spike_"..team, {
description = HumanReadable(team).." Team Spike",
drawtype = "plantlike",
tiles = {"ctf_map_spike.png^[colorize:"..spikecolor..":150"},
inventory_image = "ctf_map_spike.png^[colorize:"..spikecolor..":150",
use_texture_alpha = "clip",
paramtype = "light",
paramtype2 = "meshoptions",
sunlight_propagates = true,
walkable = false,
damage_per_second = 7,
groups = {cracky=1, level=2},
drop = "ctf_map:spike",
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
on_place = function(itemstack, placer, pointed_thing)
return minetest.item_place(itemstack, placer, pointed_thing, 34)
end
})
end
end

minetest.register_on_player_hpchange(function(player, hp_change, reason)
if reason.type == "node_damage" then
local team = ctf_teams.get(player)

local spike_team = string.match(reason.node, "ctf_map:spike_(%S+)")
if spike_team and ctf_modebase.flag_captured[spike_team] then
return 0, true
end
if team and reason.node == string.format("ctf_map:spike_%s", team) then
return 0, true
end
Expand Down Expand Up @@ -129,7 +134,7 @@ local function damage_cobble_dig(pos, node, digger)
local placerobj = minetest.get_player_by_name(placer_name)

if placerobj then
digger:punch(placerobj, 10, {
digger:punch(placerobj, 1, {
damage_groups = {
fleshy = 7,
damage_cobble = 1,
Expand Down
Loading

0 comments on commit ed51e9a

Please sign in to comment.