Skip to content

Commit

Permalink
Split '/SRC/LUA/TEXT.LUA' into separate language files
Browse files Browse the repository at this point in the history
Updated the add-on loading routine and Language Files handling
  • Loading branch information
LeonardoTheMutant committed Nov 11, 2024
1 parent c8aa441 commit c2a81cd
Show file tree
Hide file tree
Showing 16 changed files with 1,606 additions and 1,663 deletions.
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ As a `[mapnum]` you can use **MAPK0** or **K0** (*"Abandoned Shelter"*)
The [Pull Requests](https:github.com/LeonardoTheMutant/SRB2-Murder-Mystery/pulls) are always open! All contributions would be greatly appreciated especially maps, music, graphics, ideas or bug fixes. If you want to make something unique you can even make a translation. Yes you read it right, this gametype supports localisations on different languages. You can add your own language to the project by either
1. Modifying the source code you are having right now and creating a new Pull Request
2. Making a **Custom Language File** from the [template](TEMPLATES/customlang.lua) and then in SRB2 add it as a regular Add-On together with MM (main MM Add-On has to be loaded first)
2. Making a **Language File** from the [template](SRC/LUA/TEXT/EN.LUA) and then in SRB2 add it as a regular Add-On together with MM (main MM Add-On has to be loaded first)
4 changes: 2 additions & 2 deletions SRC/DEV_DOCS/List_of_Func_and_Const.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ There is a customization function defined in <code>MM</code> table inside the co

| Name | Description |
| --- | --- |
| <code>**MM.AddLang**(*string* index, *table* lang)</code> | Add a translation into MM. <code>index</code> is usually a 2 or 3 characters long name of the language. For example `"EN"` shows that the language is English. <code>table</code> is the translation data itself. The format of the <code>table</code> can be found [here](https://github.com/LeonardoTheMutant/SRB2-Murder-Mystery/blob/main/TEMPLATES/customlang.lua).<br>*Note:* Index should be all characters **UPPERCASE** otherwise it won't be accesible! |
| <code>**MM.AddLang**(*string* index, *table* lang)</code> | Add a translation into MM. <code>index</code> is usually a 2 or 3 characters long name of the language. For example `"EN"` shows that the language is English. <code>table</code> is the translation data itself. The format of the <code>table</code> can be found [here](../LUA/TEXT/EN.LUA).<br>*Note:* Index should be all characters **UPPERCASE** otherwise it won't be accesible! |

## `FUNCTIONS.LUA`

Expand Down Expand Up @@ -192,7 +192,7 @@ The description of each value in the `MM` table. The `MM` constant itself is def
| <code>version</code> | *string* | Version number of the add-on | <code>"1.0-ALPHA"</code> |
| <code>debug</code> | *boolean* | Enable/Disable the add-on's *Debug Mode* functionality<br>*Note:* **The add-on must boot with this variable set to <code>true</code> to use the Debug in any form.** | <code>true</code> |
| <code>releasedate</code> | *string* | The release date of the add-on version. | <code>"August 19th 2024"</code> |
| <code>text</code> | *table* | Collection of all text used in **Murder Mystery** with all translations. This variable is **netsynced** | *See [the template file](https://github.com/LeonardoTheMutant/SRB2-Murder-Mystery/blob/main/TEMPLATES/customlang.lua)* |
| <code>text</code> | *table* | Collection of all text used in **Murder Mystery** with all translations. This variable is **netsynced** | *See [the template file](../LUA/TEXT/EN.LUA)* |
| <code>RoleColor</code> | *string[5]* | The text colors for roles | *See [<code>INIT.LUA</code>](../INIT.LUA)* |
| <code>RoleColorHUD</code> | *string[5]* | The HUD text colors for roles | *See [<code>INIT.LUA</code>](../INIT.LUA)* |
| <code>hud</code> | *table* | HUD control variables for each sub-renderer (<code>MM.hud.game</code>, <code>MM.hud.scores</code>, <code>MM.hud.intermission</code>). Each sub-renderer has two attributes: <code>enabled</code> (custom scripts can disable MM's HUD renderers by setting this to <code>false</code>) and <code>pos</code> (coordinates of the different HUD elements) | *See [<code>INIT.LUA</code>](../INIT.LUA)* |
Expand Down
20 changes: 9 additions & 11 deletions SRC/DEV_DOCS/MM_HUD_Library.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@ Now lets get into the "under the hood" details and how you can print such string
<br><br>
Functions like <code>**V_DrawStrASCII()**</code>, <code>**V_DrawStrASCII_Center()**</code> and <code>**V_DrawStrASCII_Right()**</code> are designed to print strings with Extended ASCII symbols. Still, this is not enough to actually print strings like these because you're missing the font for the characters (more specifically, font graphics/patches). `SRB2.pk3` contains graphics for the printable Standard ASCII characters only (0x19-0x7E range, 25-126 in decimal). You need the graphics for **every single extended character** you are going to use.
<br><br>
Let's imagine that we are making a Greek translation of Murder Mystery. We use ***Windows1253*** as our base. We make the font graphics and name them like `"1253C###"` (`###` is a decimal number that corresponds to a character in that codepage). Our prefix for Greek codepage is `"1253C"` because we named files like that. Now we need to tell our Rendering Functions to use these files as graphics for Greek letters. The 4th argument in the <code>**V_DrawStrASCII()**</code> function specifies the character set prefix to use. In case of the **Custom Language File** for Murder Mystery gametype we simply need to include the `"CHARSET"` key to the LUA table and set its value to the Character Set prefix we got. The final result should look something like this:
Let's imagine that we are making a Greek translation of Murder Mystery. We use ***Windows1253*** as our base. We make the font graphics and name them like `"1253C###"` (`###` is a decimal number that corresponds to a character in that codepage). Our prefix for Greek codepage is `"1253C"` because we named files like that. Now we need to tell our Rendering Functions to use these files as graphics for Greek letters. The 4th argument in the <code>**V_DrawStrASCII()**</code> function specifies the character set prefix to use. In case of the **Language Files** for the LTM's Murder Mystery we simply need to include the `"CHARSET"` key to the LUA table and set its value to the Character Set prefix we got. The final result should look something like this:

```lua
local greekText={
["VERSION"]="1.0", --don't forget about the compatibility!
["AUTHOR"]="Sonic",
["NONASCII"]=true, --little outdated name but we set this to show that this language is not Latin-based
["CHARSET"]="1253C", --this is the font graphic file prefix that we needed!
["MM"]="Murder Mystery in Greek",
MM.AddLang("GR", {
["VERSION"] = "1.0", --don't forget about the compatibility!
["AUTHOR"] = "Sonic",
["NONASCII"] = true, --little outdated name but we set this to show that this language is not Latin-based
["CHARSET"] = "1253C", --this is the font graphic file prefix that we needed!
["MM"] = "Murder Mystery in Greek",
...
}

MM.AddLang("GR", greekText)
})
```

And now when we kindly ask the <code>**V_DrawStrASCII()**</code> function (or the gametype) to print the Delta character (Δ, `0xC4` in hex, 192 in decimal) the function will try to load the file by the name of `"1253C192"` and draw this graphic on the screen. Wow, it works now! Amazing isn't it?
Expand Down Expand Up @@ -224,7 +222,7 @@ Similar to [Windows1252](https://wikipedia.org/wiki/Windows-1252) but also suppo

## Text Patches

As an alternative to the regular Patch files, MM HUD Library provides a way to draw bitmap graphics provided by the **Text**. This is developed primarily for the **Custom Language Files** as these will most likely not be packed in a `.pk3` archive (to additionally include all required graphics).
As an alternative to the regular Patch files, MM HUD Library provides a way to draw bitmap graphics provided by the **Text**. This is developed primarily for the **Language Files** as these will most likely not be packed in a `.pk3` archive (to additionally include all required graphics).
<br><br>
You must be very familliar how the `TIME` HUD label in vanilla SRB2 looks (if not you can open the game right now and see it)(this label can also be found in `srb2.pk3` as `STTTIME` lump). All you need to know about the Text Patch is that it is a bitmap representation of an image where every charater is a pointer to SRB2 palette's color. This is what `STTTIME` patch looks like as Text Patch:

Expand Down
13 changes: 9 additions & 4 deletions SRC/FOR_DEVELOPERS.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ MM_LTMs_MurderMystery_v1.0-ALPHA.pk3
| | +-HUD_MINIGAMES.LUA - Dedicated HUD renderer for the minigames
| | +-MINIGAME.LUA - Main logic code for "PONG" and "SONIC RUN" minigames
| |
| +-TEXT-\
| | +-EN.LUA - All Text and messages used in the add-on (English version), also a template file for other languages
| |
| +-ABILITIES.LUA - Character abilities & sneak
| +-CCMD.LUA - MMHELP and MMLANG commands
| +-CHAT.LUA - Chat management
Expand All @@ -48,10 +51,12 @@ MM_LTMs_MurderMystery_v1.0-ALPHA.pk3
Other files are either textures or music and do not require an introduction


As I've said earlier, the GitHub repository has more content to work with such as an additional LUA file
in the repository called "customlang.lua" in the TEMPLATES/ folder. This is a template file for custom translations.
Yes, THIS GAMETYPE SUPPORTS TRANSLATIONS. I tried my best to make the tutorial about languages in that template
understandable but if you have questions you can always ask us in our MM_DEV Discord (or even on GitHub).
As I've said earlier, the GitHub repository has more content to work with such as bunch of useful tools to make a
MM language file in LUA format.

Yes, THIS GAMETYPE SUPPORTS TRANSLATIONS. You can take /SRC/LUA/TEXT/EN.LUA as the template file for your language
I tried my best to make the tutorial about languages in that template understandable but if you have questions you
can always ask us in our SRB2MM_DEV Discord (or even on GitHub).

If you're new to the LUA you can freely use our code for educational purposes

Expand Down
46 changes: 30 additions & 16 deletions SRC/INIT.LUA
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ rawset(_G, "MM", {
pads = {32, 32},
hits = 0,
padcolor = {37, 153} --player role colors
}
},
text = {}
})

--
Expand Down Expand Up @@ -117,15 +118,15 @@ MM.AddLang = function(langID,langTbl)
end
end
MM.text[langID:upper()] = langTbl
print("\x83Succesfuly added \x82"..langID.." \x83(by "..tostring(MM.text[langID:upper()]["AUTHOR"])..") lang as a MM language.")
print("\x87Murder Mystery\x80: Added \x82\""..langID.."\"\x80 language by "..tostring(MM.text[langID:upper()]["AUTHOR"]))
if (MM.text[langID:upper()]["VERSION"] ~= MM.version) print("\x82WARNING:\x80 This language file is \x85OUTDATED\x80 and may result crashes. Please ask \x84"..tostring(MM.text[langID:upper()]["AUTHOR"]).."\x80 to update it for the \x87Murder Mystery "..MM.version) end
end

--CVARs
local function VarChange(v) --callback function called by CV_CALL flag
if (v.name == "mm_abilities")
if (v.value) print("\x87Murder Mystery:\x80 Skin abilities are Enabled (no limits)")
else print("\x87Murder Mystery:\x80 Skin abilities are Disabled (\"Regular person\" mode)") end
if (v.value) print("\x87Murder Mystery\x80: Skin abilities are Enabled (no limits)")
else print("\x87Murder Mystery\x80: Skin abilities are Disabled (\"Regular person\" mode)") end
elseif (v.name == "mm_wepconfig")
local sentences = {
[0] = "All weapons enabled",
Expand All @@ -137,14 +138,14 @@ local function VarChange(v) --callback function called by CV_CALL flag
MM.weaponconfig[2] = (v.value >> 2) & 3
MM.weaponconfig[3] = (v.value >> 4) & 3
MM.weaponconfig[4] = (v.value >> 6) & 3
print("\x87Murder Mystery:\x80 Weapon Configuration was changed to \x81"..v.value.."\x80. In other words...\n\t\x89Normal gameplay\x80:\n\t\t"..MM.RoleColor[ROLE_MURDERER].."Murderer\x80: "..sentences[MM.weaponconfig[1]].."\n\t\t"..MM.RoleColor[ROLE_SHERIFF].."Sheriff\x80: "..sentences[MM.weaponconfig[2]].."\n\t\x88Showdown Duel\x80:\n\t\t"..MM.RoleColor[ROLE_MURDERER].."Murderer\x80: "..sentences[MM.weaponconfig[3]].."\n\t\t"..MM.RoleColor[ROLE_SHERIFF].."Sheriff\x80: "..sentences[MM.weaponconfig[4]])
print("\x87Murder Mystery\x80: Weapon Configuration was changed to \x81"..v.value.."\x80. In other words...\n\t\x89Normal gameplay\x80:\n\t\t"..MM.RoleColor[ROLE_MURDERER].."Murderer\x80: "..sentences[MM.weaponconfig[1]].."\n\t\t"..MM.RoleColor[ROLE_SHERIFF].."Sheriff\x80: "..sentences[MM.weaponconfig[2]].."\n\t\x88Showdown Duel\x80:\n\t\t"..MM.RoleColor[ROLE_MURDERER].."Murderer\x80: "..sentences[MM.weaponconfig[3]].."\n\t\t"..MM.RoleColor[ROLE_SHERIFF].."Sheriff\x80: "..sentences[MM.weaponconfig[4]])
elseif (v.name == "mm_wepinno")
if (v.value == 0) print("\x87Murder Mystery:\x80 Weapons are disabled for "..MM.RoleColor[ROLE_INNOCENT].."Innoncents")
elseif (v.value == 1) print("\x87Murder Mystery: "..MM.RoleColor[ROLE_INNOCENT].."Innoncents\x80 have an access to the Knife and Red Ring weapons")
elseif (v.value == 2) print("\x87Murder Mystery: "..MM.RoleColor[ROLE_INNOCENT].."Innoncents\x80 have an access to the Knife") end
if (v.value == 0) print("\x87Murder Mystery\x80: Weapons are disabled for "..MM.RoleColor[ROLE_INNOCENT].."Innoncents")
elseif (v.value == 1) print("\x87Murder Mystery\x80: "..MM.RoleColor[ROLE_INNOCENT].."Innoncents\x80 have an access to the Knife and Red Ring weapons")
elseif (v.value == 2) print("\x87Murder Mystery\x80: "..MM.RoleColor[ROLE_INNOCENT].."Innoncents\x80 have an access to the Knife") end
elseif (v.name == "mm_cryptic")
if (v.value) print("\x87Murder Mystery:\x80 Nametags and most of the player counters got disabled. \x81Good Luck finding out who others are.")
else print("\x87Murder Mystery:\x80 Nametags and player counters are now enabled") end
if (v.value) print("\x87Murder Mystery\x80: Nametags and most of the player counters got disabled. \x81Good Luck finding out who others are.")
else print("\x87Murder Mystery\x80: Nametags and player counters are now enabled") end
end
end
-- Flags: 4 = CV_NETVAR; 6 = CV_NETVAR|CV_CALL
Expand All @@ -164,19 +165,18 @@ CV_RegisterVar({name = "mm_wepinno", defaultvalue = 1, PossibleValue = {MIN = 0,
print("\n\x87LTM's MURDER MYSTERY \x81v"..MM.version.."\n")

--Freeslot Gametype, Sheriff's Emerald & Knife object
freeslot('TOL_LTM_MM', 'MT_SHREML', 'MT_MMKNIFE', 'SPR_STEPA0', 'S_MMSTEP', 'MT_MMSTEP')
freeslot('sfx_mmdth1', 'sfx_mmdth2', 'sfx_mmdth3', 'sfx_mmdth4', 'sfx_mmdth5', 'sfx_mmdth6', 'sfx_mmdth7')

G_AddGametype({
name = "LTM_MM",
identifier = "ltmmurdermystery",
identifier = "LTMMURDERMYSTERY",
typeoflevel = TOL_LTM_MM,
rules = GTR_DEATHMATCHSTARTS|GTR_RINGSLINGER|GTR_FIRSTPERSON|GTR_TIMELIMIT,
intermissiontype = int_match,
headerleftcolor = 37,
headerrightcolor = 153,
description = "\x88LeonardoTheMutant's\x80 \x87Murder Mystery\x80:\nKill everyone as \x85Murderer\x80, prevent the murders as \x84Sheriff\x80 and survive as \x83Innocent\x80!"
})
freeslot('TOL_LTM_MM', 'MT_SHREML', 'MT_MMKNIFE', 'SPR_STEPA0', 'S_MMSTEP', 'MT_MMSTEP')
freeslot('sfx_mmdth1', 'sfx_mmdth2', 'sfx_mmdth3', 'sfx_mmdth4', 'sfx_mmdth5', 'sfx_mmdth6', 'sfx_mmdth7')

--Sheriff Drop Emerald
mobjinfo[MT_SHREML]={
Expand Down Expand Up @@ -220,8 +220,18 @@ sfxinfo[sfx_mmdth5].caption = "OH NO!"
sfxinfo[sfx_mmdth6].caption = "Pain"
sfxinfo[sfx_mmdth7].caption = "Moonwalker"

--Script files init
dofile("TEXT.LUA")
--Load the text and all translations (they have to be loaded first)
print("\n\x87Murder Mystery\x80: Loading text...")
dofile("TEXT/EN.LUA") --English text is required for the game to run on the basic level so DO NOT REMOVE OR COMMENT THIS LINE
dofile("TEXT/ES.LUA")
dofile("TEXT/FR.LUA")
dofile("TEXT/PL.LUA")
dofile("TEXT/RU.LUA")
dofile("TEXT/TR.LUA")
dofile("TEXT/UA.LUA")

--Script files load
print("\n\x87Murder Mystery\x80: Loading main logic scripts...")
dofile("FUNCTIONS.LUA")
if (MM.debug) dofile("DEBUG.LUA") end
dofile("GAME.LUA")
Expand All @@ -233,9 +243,13 @@ dofile("FOOTSTEPS.LUA")
dofile("ABILITIES.LUA")
dofile("TIMETRAVEL.LUA")

--Minigames module
print("\n\x87Murder Mystery\x80: Loading minigames module...")
if (not isdedicatedserver) dofile("MINIGAMES/HUD_MINIGAMES.LUA") end
dofile("MINIGAMES/MINIGAMES.LUA")

--Map scripts
print("\n\x87Murder Mystery\x80: Loading map scripts...")
dofile("MAPS/MAPK0.LUA")
dofile("MAPS/MAPK6.LUA")
dofile("MAPS/MAPK7.LUA")
Expand Down
10 changes: 5 additions & 5 deletions SRC/LUA/CCMD.LUA
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
-- CCMD.LUA
-- Code by LeonardoTheMutant
-- Translations by awesome MM_DEV members
-- Translations by awesome SRB2MM_DEV members
--
-- Code for MMHELP and MMLANG console comands

local tech_info = {
"\4LTM's \7Murder Mystery\16",
"Version\17 "..MM.version.."\16 ("..MM.releasedate..")",
"by \18\"SRB2 MM_DEV team\"\16",
"by \18\"SRB2MM_DEV team\"\16",
"(Full credits are in README.TXT inside this .PK3)",
"\nChanges from\17 10.1-BETA\16:",
" - TODO;",
"\n\nFound an issue or just want to help in this gametype's development? Any kind of contribution to the project matters and can help!\n",
"\20Discord (MM_DEV team):\ndiscord.com/invite/UgG8h2djFE\16\n",
"\20Discord (SRB2MM_DEV team):\ndiscord.com/invite/UgG8h2djFE\16\n",
"\22GitHub:\ngithub.com/LeonardoTheMutant/SRB2-Murder-Mystery\16\n",
"\27Website:\nleonardothemutant.github.io/SRB2-Murder-Mystery\16\n"
}
Expand Down Expand Up @@ -113,7 +113,7 @@ COM_AddCommand("mmlang", function(p, l) --player, lang
CONS_Printf(p, langCount.." languages in total")
if (langIncomp) then CONS_Printf(p, "\x85"..langIncomp.." are incompatible, they may result errors (or even crashes) when selected") end
if (nonascii) then CONS_Printf(p, "\n* \x80Language is not Latin based. All letters of this language in the console/chat texts will be simulated with English (ASCII compatible) ones.") end
CONS_Printf(p, "\nIf you cannot find your language here please ask the game administrator(s) to add the required MM language file or contact our \x82LTM_MM_DEV Team\x80 to help us add it to this gametype:\n \x84".."Discord: https://discord.com/invite/UgG8h2djFE\x80\n \x86GitHub: https://github.com/LeonardoTheMutant/SRB2-Murder-Mystery")
CONS_Printf(p, "\nIf you cannot find your language here please ask the game administrator(s) to add the required MM language file or contact our \x82SRB2MM_DEV Team\x80 to help us add it to this gametype:\n \x84".."Discord: https://discord.com/invite/UgG8h2djFE\x80\n \x86GitHub: https://github.com/LeonardoTheMutant/SRB2-Murder-Mystery")
else
l = $:upper()
if (MM.text[l])
Expand All @@ -129,7 +129,7 @@ COM_AddCommand("mmlang", function(p, l) --player, lang
f:close()
--CONS_Printf(p, "\x83NOTE:\x80 Language preferences saved to \x81/luafiles/client/MM.DAT")
else CONS_Printf(p, "\x85Failed to save\x80 Language preferences to \x81/luafiles/client/MM.DAT\x80. Does your folder lack read+write privileges?") end
else CONS_Printf(p, "'\x82"..l.."\x80' language is not present/loaded into the game\nPlease ask your game Administrator to add the required MM language file or contact our SRB2 MM_DEV Team for help.") end
else CONS_Printf(p, "'\x82"..l.."\x80' language is not present/loaded into the game\nPlease ask your game Administrator to add the required MM language file or contact our SRB2MM_DEV Team for help.") end
end
end, COM_LOCAL)

Expand Down
6 changes: 3 additions & 3 deletions SRC/LUA/FUNCTIONS.LUA
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ rawset(_G, "MM_InitPlayer", function(p)

if (not p.mm) then p.mm = {} end
p.mm.kills = 0
p.mm.killername = false
p.mm.killedby = false
p.mm.weapondelay = 0
p.mm.camping = 0
p.mm.chatdelay = 0
Expand Down Expand Up @@ -221,7 +221,7 @@ rawset(_G, "MM_KillPlayerByPlayer", function(p, k) --player, killer (both MOBJ_T
plr.mm.hud.flashscrn = 1
P_PlayerRingBurst(plr, -1)
P_PlayerWeaponPanelOrAmmoBurst(plr)
plr.mm.killername = k.player.name
plr.mm.killedby = k.player.name
k.player.mm.kills = $ + 1
if (not k.player.mm.sneak) P_PlayDeathSound(p) end
plr.rmomx = 0
Expand Down Expand Up @@ -249,7 +249,7 @@ rawset(_G, "MM_KillPlayerByHazard", function(p, spawnbody) --player (mobt_t), "S
plr.spectator = true
plr.mm.role = ROLE_NONE
plr.mm.hud.flashscrn = 1
plr.mm.killername = "your stupidity"
plr.mm.killedby = "your stupidity"

if (spawnbody)
local body = P_SpawnMobjFromMobj(p,0,0,0,MT_DEADPLR)
Expand Down
Loading

0 comments on commit c2a81cd

Please sign in to comment.