Skip to content

Commit

Permalink
Merge pull request #269 from GMLambda/lang
Browse files Browse the repository at this point in the history
Localization
  • Loading branch information
ZehMatt authored May 3, 2024
2 parents 40f7577 + c5325cb commit f177169
Show file tree
Hide file tree
Showing 18 changed files with 263 additions and 180 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
0.9.20 (in development)
- Feature: Episode 1 support.
- Improved: Language localization of settings (English only as of now).
- Improved: When "Friendly Fire" and "Player Collision" both disabled, bullet can pass through other players.
- Improved: Lambda no longer override the localization already existing in the game.
- Improved: d2_coast_03: Give more supplies, hope this can help player fight with multiple gunships better.
Expand Down
1 change: 1 addition & 0 deletions gamemode/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include("cl_postprocess.lua")
include("cl_ragdoll_ext.lua")
include("cl_taunts.lua")
include("cl_hud.lua")
include("cl_lang.lua")
DEFINE_BASECLASS("gamemode_base")
local DbgPrint = GetLogging("Client")
local CurTime = CurTime
Expand Down
39 changes: 39 additions & 0 deletions gamemode/cl_lang.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
local DbgPrint = GetLogging("Language")

local SUPPORTED_LANGUAGES = {
["en"] = "english",
}

local function GetCurrentLanguage()
local gmod_language = GetConVar("gmod_language")
local lang = gmod_language:GetString()
local realLang = SUPPORTED_LANGUAGES[lang]
if realLang == nil then
DbgPrint("Language '" .. lang .. "' is not supported, falling back to 'en'")
realLang = "english"
end
return realLang
end

function GM:LoadLocalisation()
local langName = GetCurrentLanguage()
local gameType = self:GetGameType()
if gameType == nil then return end
while gameType ~= nil do
local langData = gameType.Localisation
if langData ~= nil then
local langEntries = langData[langName]
if langEntries ~= nil then
for k, v in pairs(langEntries) do
DbgPrint("Adding localisation: " .. k .. " = " .. v)
language.Add(k, v)
end
end
end
gameType = gameType.Base
end
end

cvars.AddChangeCallback("gmod_language", function(cvar, old, new)
GAMEMODE:LoadLocalisation()
end)
79 changes: 79 additions & 0 deletions gamemode/gametypes/base/cl_localisation.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
if SERVER then AddCSLuaFile() end
local LOCALISATION = {}
LOCALISATION["english"] = {
["World"] = "Cruel World",
["base_ai"] = "Creature",
["Valve_Hint_EnterVan"] = "%+use% ENTER VAN",
["Valve_Hint_ExitVan"] = "%+use% EXIT VAN",
["Valve_Hint_Crouch"] = "%+duck% CROUCH",
["Valve_Hint_Sprint"] = "%+speed% SPRINT",
["Valve_Hint_PushButton"] = "%+use% PUSH BUTTON",
["Valve_Hint_PicKUp"] = "%+use% PICK UP",
["Valve_Hint_Interact"] = "%+use% INTERACT",
["Valve_Hint_GravGun"] = "%+attack% PUNT OBJECT %+attack2% PULL OBJECT",
["Valve_Hint_CarryTurret"] = "%+use% OR GRAVITY GUN TO PICK UP TURRET",
["Valve_Hint_CROSSBOW"] = "%+attack2% CROSSBOW ZOOM",
["GM_DIFFICULTY"] = "Difficulty level",
["GM_DIFFICULTY_DESC"] = "Set the gametype difficulty",
["GM_WALKSPEED"] = "Walk speed",
["GM_WALKSPEED_DESC"] = "Set speed when slowly walking with ALT key",
["GM_NORMSPEED"] = "Normal speed",
["GM_NORMSPEED_DESC"] = "Set speed normal walk speed",
["GM_SPRINTSPEED"] = "Sprint speed",
["GM_SPRINTSPEED_DESC"] = "Set running speed",
["GM_CONNECTTIMEOUT"] = "Connection timeout",
["GM_CONNECTTIMEOUT_DESC"] = "Set how long should it wait for connecting players",
["GM_PLAYERCOLLISION"] = "Player collision",
["GM_PLAYERCOLLISION_DESC"] = "Players can collide with other players",
["GM_FRIENDLYFIRE"] = "Friendly fire",
["GM_FRIENDLYFIRE_DESC"] = "Enable damage to other players",
["GM_PREVENTITEMMOVE"] = "Prevent item moving",
["GM_PREVENTITEMMOVE_DESC"] = "Prevent items from moving when shooting at them",
["GM_DEFAMMO"] = "Limit default ammo",
["GM_DEFAMMO_DESC"] = "Disable ammo limits",
["GM_AUTOJUMP"] = "Allow auto jump",
["GM_AUTOJUMP_DESC"] = "Allow players to use the auto jump feature",
["GM_RESPAWNTIME"] = "Respawn time",
["GM_RESPAWNTIME_DESC"] = "Set players respawn time",
["GM_CHECKPOINT_RESPAWN"] = "Checkpoint respawn",
["GM_CHECKPOINT_RESPAWN_DESC"] = "Players have to wait for checkpoints in order to respawn",
["GM_RESTARTTIME"] = "Restart time",
["GM_RESTARTTIME_DESC"] = "Set time between round ending and starting",
["GM_MAPCHANGETIME"] = "Mapchange time",
["GM_MAPCHANGETIME_DESC"] = "Set time after between map finish and level change",
["GM_CHECKPOINTTIMEOUT"] = "Checkpoint timeout",
["GM_CHECKPOINTTIMEOUT_DESC"] = "Set how long checkpoints wait for other players",
["GM_GODMODE"] = "Godmode",
["GM_GODMODE_DESC"] = "Enable god mode, prevents any damage",
["GM_PICKUPDELAY"] = "Pickup delay",
["GM_PICKUPDELAY_DESC"] = "Set weapon/item delay before picking it up",
["GM_DIFFMETRICS"] = "NPC/Player metrics",
["GM_DIFFMETRICS_DESC"] = "Metrics for use by developers",
["GM_WEAPONDROP"] = "Weapon drop mode",
["GM_WEAPONDROP_DESC"] = "Change what players drop on death",
["GM_CHANGELVLDELAY"] = "Level change delay",
["GM_CHANGELVLDELAY_DESC"] = "The amount in seconds to wait before changing to the next map",
["GM_COCKROACHES"] = "Cockroach amount",
["GM_COCKROACHES_DESC"] = "The maximum amount of cockroaches that can be spawned. 0 to disable them",
["GM_ABH"] = "Accelerated backhopping",
["GM_ABH_DESC"] = "Enable ABH, widely used by speedrunners to achieve insane speed",
["GM_DYNCHECKPOINT"] = "Dynamic checkpoints",
["GM_DYNCHECKPOINT_DESC"] = "Enable dynamic checkpoints",
["GM_NPCDMG"] = "Friendly NPC damage",
["GM_NPCDMG_DESC"] = "Allows friendly NPC to take damage",
["GM_PLYTRACK"] = "Player tracking",
["GM_PLYTRACK_DESC"] = "Allows seeing players through walls",
["GM_ANTLIONCOLLISION"] = "Friendly antlion collision",
["GM_ANTLIONCOLLISION_DESC"] = "Enable/disable colliding with friendly antlions",
["GM_PLAYERSPEECH"] = "Player speech",
["GM_PLAYERSPEECH_DESC"] = "Enable/disable players speaking based on performance",
["GM_PLAYERHURTSOUNDS"] = "Player damage speech",
["GM_PLAYERHURTSOUNDS_DESC"] = "Enable/disable players speaking based on recieved damage",
["GM_DM_FRAGLIMIT"] = "Score limit",
["GM_DM_FRAGLIMIT_DESC"] = "Set score limit for round to end",
["GM_DM_TIMELIMIT"] = "Round time limit",
["GM_DM_TIMELIMIT_DESC"] = "Set how long the round lasts",
["GM_DM_TEAMONLY"] = "Team based deathmatch",
["GM_DM_TEAMONLY_DESC"] = "Switch between DM or TDM",
}
return LOCALISATION
63 changes: 24 additions & 39 deletions gamemode/gametypes/gametype_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ GAMETYPE.ImportantPlayerNPCNames = {}
GAMETYPE.ImportantPlayerNPCClasses = {}
GAMETYPE.PlayerTiming = false
GAMETYPE.WaitForPlayers = false
GAMETYPE.Localisation = include("base/cl_localisation.lua")
function GAMETYPE:GetData(name)
local base = self
while base ~= nil do
Expand Down Expand Up @@ -102,7 +103,6 @@ function GAMETYPE:LoadMapScript(path, name)
end

function GAMETYPE:LoadLocalisation(lang)
-- Stub
end

function GAMETYPE:AllowPlayerTracking()
Expand Down Expand Up @@ -315,7 +315,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("walkspeed", {
Category = "SERVER",
NiceName = "#GM_WALKSPEED",
Description = "Walk speed",
Description = "#GM_WALKSPEED_DESC",
Type = "int",
Default = 150,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED),
Expand All @@ -328,7 +328,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("normspeed", {
Category = "SERVER",
NiceName = "#GM_NORMSPEED",
Description = "Run speed",
Description = "#GM_NORMSPEED_DESC",
Type = "int",
Default = 190,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED),
Expand All @@ -341,7 +341,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("sprintspeed", {
Category = "SERVER",
NiceName = "#GM_SPRINTSPEED",
Description = "Sprint speed",
Description = "#GM_SPRINTSPEED_DESC",
Type = "int",
Default = 320,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED),
Expand All @@ -354,7 +354,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("connect_timeout", {
Category = "SERVER",
NiceName = "#GM_CONNECTTIMEOUT",
Description = "Timeout limit",
Description = "#GM_CONNECTTIMEOUT_DESC",
Type = "int",
Default = 120,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED),
Expand All @@ -366,7 +366,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("playercollision", {
Category = "SERVER",
NiceName = "#GM_PLAYERCOLLISION",
Description = "Player collision",
Description = "#GM_PLAYERCOLLISION_DESC",
Type = "bool",
Default = true,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED)
Expand All @@ -375,7 +375,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("friendlyfire", {
Category = "SERVER",
NiceName = "#GM_FRIENDLYFIRE",
Description = "Friendly fire",
Description = "#GM_FRIENDLYFIRE_DESC",
Type = "bool",
Default = false,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED)
Expand All @@ -384,7 +384,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("prevent_item_move", {
Category = "SERVER",
NiceName = "#GM_PREVENTITEMMOVE",
Description = "Prevent item moving",
Description = "#GM_PREVENTITEMMOVE_DESC",
Type = "bool",
Default = true,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED)
Expand All @@ -393,7 +393,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("limit_default_ammo", {
Category = "SERVER",
NiceName = "#GM_DEFAMMO",
Description = "Limit default ammo",
Description = "#GM_DEFAMMO_DESC",
Type = "bool",
Default = true,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED)
Expand All @@ -402,7 +402,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("allow_auto_jump", {
Category = "SERVER",
NiceName = "#GM_AUTOJUMP",
Description = "Auto jump",
Description = "#GM_AUTOJUMP_DESC",
Type = "bool",
Default = false,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED)
Expand All @@ -411,7 +411,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("max_respawn_timeout", {
Category = "SERVER",
NiceName = "#GM_RESPAWNTIME",
Description = "Respawn time",
Description = "#GM_RESPAWNTIME_DESC",
Type = "int",
Default = 20,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED),
Expand All @@ -424,7 +424,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("checkpoint_respawn", {
Category = "SERVER",
NiceName = "#GM_CHECKPOINT_RESPAWN",
Description = "Players have to wait for checkpoints in order to respawn",
Description = "#GM_CHECKPOINT_RESPAWN_DESC",
Type = "bool",
Default = false,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED),
Expand All @@ -433,7 +433,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("map_restart_timeout", {
Category = "SERVER",
NiceName = "#GM_RESTARTTIME",
Description = "Restart time",
Description = "#GM_RESTARTTIME_DESC",
Type = "int",
Default = 20,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED),
Expand All @@ -446,7 +446,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("map_change_timeout", {
Category = "SERVER",
NiceName = "#GM_MAPCHANGETIME",
Description = "Map change time",
Description = "#GM_MAPCHANGETIME_DESC",
Type = "int",
Default = 60,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED),
Expand All @@ -459,7 +459,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("checkpoint_timeout", {
Category = "SERVER",
NiceName = "#GM_CHECKPOINTTIMEOUT",
Description = "Checkpoint timeout",
Description = "#GM_CHECKPOINTTIMEOUT_DESC",
HelpText = "Set to 0 to disable timeout",
Type = "int",
Default = 60,
Expand All @@ -473,7 +473,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("player_god", {
Category = "SERVER",
NiceName = "#GM_GODMODE",
Description = "Player god mode",
Description = "#GM_GODMODE_DESC",
Type = "bool",
Default = false,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED)
Expand All @@ -482,7 +482,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("pickup_delay", {
Category = "SERVER",
NiceName = "#GM_PICKUPDELAY",
Description = "Pickup delay",
Description = "#GM_PICKUPDELAY_DESC",
Type = "float",
Default = 0.5,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED),
Expand All @@ -492,7 +492,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("difficulty_metrics", {
Category = "DEVELOPER",
NiceName = "#GM_DIFFMETRICS",
Description = "NPC/Player metrics",
Description = "#GM_DIFFMETRICS_DESC",
Type = "bool",
Default = false,
Flags = bit.bor(0, FCVAR_REPLICATED),
Expand All @@ -502,7 +502,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("weapondropmode", {
Category = "SERVER",
NiceName = "#GM_WEAPONDROP",
Description = "Weapon Drop Mode",
Description = "#GM_WEAPONDROP_DESC",
Type = "int",
Default = 1,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED),
Expand All @@ -519,16 +519,16 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("abh", {
Category = "SERVER",
NiceName = "#GM_ABH",
Description = "Accelerated backhopping",
Description = "#GM_ABH_DESC",
Type = "bool",
Default = false,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED)
})

GAMEMODE:AddSetting("changelevel_delay", {
Category = "SERVER",
NiceName = "#GM_ABH",
Description = "The amount in seconds to wait before changing to the next map",
NiceName = "#GM_CHANGELVLDELAY",
Description = "#GM_CHANGELVLDELAY_DESC",
Type = "int",
Default = 6,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED),
Expand All @@ -541,7 +541,7 @@ function GAMETYPE:InitSettings()
GAMEMODE:AddSetting("max_cockroaches", {
Category = "SERVER",
NiceName = "#GM_COCKROACHES",
Description = "The maximum amount of cockroaches that can be spawned",
Description = "#GM_COCKROACHES_DESC",
Type = "int",
Default = 30,
Flags = bit.bor(0, FCVAR_ARCHIVE, FCVAR_NOTIFY, FCVAR_REPLICATED),
Expand All @@ -559,19 +559,4 @@ end
hook.Add("LambdaLoadGameTypes", "LambdaBaseGameType", function(gametypes)
--
gametypes:Add("lambda_base", GAMETYPE)
end)

if CLIENT then
language.Add("World", "Cruel World")
language.Add("base_ai", "Creature")
language.Add("Valve_Hint_EnterVan", "%+use% ENTER VAN")
language.Add("Valve_Hint_ExitVan", "%+use% EXIT VAN")
language.Add("Valve_Hint_Crouch", "%+duck% CROUCH")
language.Add("Valve_Hint_Sprint", "%+speed% SPRINT")
language.Add("Valve_Hint_PushButton", "%+use% PUSH BUTTON")
language.Add("Valve_Hint_PicKUp", "%+use% PICK UP")
language.Add("Valve_Hint_Interact", "%+use% INTERACT")
language.Add("Valve_Hint_GravGun", "%+attack% PUNT OBJECT %+attack2% PULL OBJECT")
language.Add("Valve_Hint_CarryTurret", "%+use% OR GRAVITY GUN TO PICK UP TURRET")
language.Add("Valve_Hint_CROSSBOW", "%+attack2% CROSSBOW ZOOM")
end
end)
Loading

0 comments on commit f177169

Please sign in to comment.