Skip to content

Commit 51e72ea

Browse files
add example mod + update readme
1 parent 0985712 commit 51e72ea

File tree

8 files changed

+151
-2
lines changed

8 files changed

+151
-2
lines changed

README.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1-
# examples
2-
Example mods for ModLoader
1+
# Mod Loader Examples
2+
3+
This repo has a basic template you can reference when building your own mod. It has lots of comments to help you along the way.
4+
5+
The `root` folder is the same as the root folder in Godot's filesystem.
6+
7+
### Other Games
8+
9+
For other games, see the example mods on their own repo or GitHub organisation. Note that game-specific examples strip away the basics, so this example is always a great place to start.
10+
11+
- [Brotato](https://github.com/BrotatoMods/Brotato-Example-Mods)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source_md5="990c006fc18c991264c9b01fad4ed97e"
2+
dest_md5="84df9f68e686067678f1bee07628d502"
3+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
extends "res://main.gd"
2+
3+
# Brief overview of what the changes in this file do...
4+
5+
const MYMOD_LOG = "AuthorName-ModName" # ! Change `MODNAME` to your actual mod's name
6+
7+
8+
# Extensions
9+
# =============================================================================
10+
11+
func _ready()->void:
12+
# ! Note that we're *not* calling `.return` here. This is because, unlike
13+
# ! all other vanilla funcs (eg `get_gold_bag_pos` below), _ready will
14+
# ! always fire, regardless of your code. In all other cases, we would still
15+
# ! need to call it
16+
17+
# ! Note that you won't see this in the log immediately, because main.gd
18+
# ! doesn't run until you start a run
19+
ModLoaderUtils.log_info("Ready", MYMOD_LOG)
20+
21+
# ! These are custom functions. It will run after vanilla's own _ready is
22+
# ! finished
23+
_modname_my_custom_edit_1()
24+
_modname_my_custom_edit_2()
25+
26+
27+
# This is the name of a func in vanilla
28+
func get_gold_bag_pos()->Vector2:
29+
# ! This calls vanilla's version of this func. The period (.) before the
30+
# func lets you call it without triggering an infinite loop. In this case,
31+
# we're calling the vanilla func to get the original value; then, we can
32+
# modify it to whatever we like
33+
var gold_bag_pos = .get_gold_bag_pos()
34+
35+
# ! If a vanilla func returns something (just as this one returns a Vector2),
36+
# ! your modded funcs should also return something with the same type
37+
return gold_bag_pos
38+
39+
40+
# Custom
41+
# =============================================================================
42+
43+
func _modname_my_custom_edit_1()->void: # ! `void` means it doesn't return anything
44+
pass # ! Using `pass` here allows you to have a empty func without causing errors
45+
46+
47+
func _modname_my_custom_edit_2()->void:
48+
ModLoaderUtils.log_info("Main.gd has been modified", MYMOD_LOG)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "ModName",
3+
"namespace": "AuthorName",
4+
"version_number": "1.1.0",
5+
"description": "Description of your mod...",
6+
"website_url": "https://github.com/exampleauthor/examplemod",
7+
"dependencies": [],
8+
"extra": {
9+
"godot": {
10+
"incompatibilities": [],
11+
"authors": ["AuthorName"],
12+
"compatible_mod_loader_version": "3.0.0",
13+
"compatible_game_version": ["0.6.1.6"],
14+
"config_defaults": {}
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
extends Node
2+
3+
# Brief overview of what your mod does...
4+
5+
# ! Comments prefixed with "!" mean they are extra info. Comments without them
6+
# ! should be kept because they give your mod structure and make it easier to
7+
# ! read by other modders
8+
9+
10+
const MOD_DIR = "AuthorName-ModName/" # name of the folder that this file is in
11+
const MYMOD_LOG = "AuthorName-ModName" # full ID of your mod (AuthorName-ModName)
12+
13+
14+
var dir = ""
15+
var ext_dir = ""
16+
17+
18+
func _init(modLoader = ModLoader):
19+
ModLoaderUtils.log_info("Init", MYMOD_LOG)
20+
21+
# ! We can't use `ModLoader` because the ModLoader instance isn't available
22+
# ! at this point in the mod's loading process. Instead, the class instance
23+
# ! is passed to a mod's `_init` func via the variable `modLoader`.
24+
# ! It will be available in any other places in your mod though, such as in
25+
# ! your _ready func.
26+
dir = modLoader.UNPACKED_DIR + MOD_DIR
27+
ext_dir = dir + "extensions/" # ! any script extensions should go in this folder, and should follow the same folder structure as vanilla
28+
29+
# Add extensions
30+
modLoader.install_script_extension(ext_dir + "main.gd") # brief description of this edit...
31+
#modLoader.install_script_extension(ext_dir + "entities/units/player/player.gd") # ! Note that this file does not exist in this example mod
32+
33+
# ! Add extensions (longform version of the above)
34+
#modLoader.install_script_extension("res://mods-unpacked/AuthorName-ModName/extensions/main.gd")
35+
#modLoader.install_script_extension("res://mods-unpacked/AuthorName-ModName/extensions/entities/units/player/player.gd")
36+
37+
# Add translations
38+
# ! Load translations for your mod, if you need them.
39+
# ! Add translations by adding a CSV called "modname.csv" into the "translations" folder.
40+
# ! Godot will automatically generate a ".translation" file, eg "modname.en.translation".
41+
# ! Note that in this example, only the file called "modname.csv" is custom;
42+
# ! any other files in the "translations" folder were automatically generated by Godot
43+
modLoader.add_translation_from_resource(dir + "translations/modname.en.translation")
44+
45+
46+
func _ready()->void:
47+
ModLoaderUtils.log_info("Ready", MYMOD_LOG)
48+
49+
# ! This uses Godot's native `tr` func, which translates a string. You'll
50+
# ! find this particular string in the example CSV here: translations/modname.csv
51+
ModLoaderUtils.log_info(str("Translation Demo: ", tr("MODNAME_READY_TEXT")), MYMOD_LOG)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
keys,en
2+
MODNAME_EXAMPLE_STRING,This is an example. If you use "EXAMPLE_STRING" for things like character names it will show this text instead
3+
MODNAME_READY_TEXT,This mod's translation file is working correctly!
4+
MODNAME_COMMA_NOTE,"If your string contains a comma like this, you need to wrap the string in double quotes, otherwise it a) won't load, and b) will stop any strings below it from loading."
5+
MODNAME_NOTE,Note that the only custom file in this directory is 'modname.csv'. The other files are generated automatically when you add a CSV to the Godot editor's filesystem
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[remap]
2+
3+
importer="csv_translation"
4+
type="Translation"
5+
6+
[deps]
7+
8+
files=[ "res://mods-unpacked/AuthorName-ModName/translations/modname.en.translation" ]
9+
10+
source_file="res://mods-unpacked/AuthorName-ModName/translations/modname.csv"
11+
dest_files=[ "res://mods-unpacked/AuthorName-ModName/translations/modname.en.translation" ]
12+
13+
[params]
14+
15+
compress=true
16+
delimiter=0
Binary file not shown.

0 commit comments

Comments
 (0)