mod_main.gd 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. extends Node
  2. # ! Comments prefixed with "!" mean they are extra info. Comments without them
  3. # ! should be kept because they give your mod structure and make it easier to
  4. # ! read by other modders
  5. # ! Comments with "?" should be replaced by you with the appropriate information
  6. # ! This template file is statically typed. You don't have to do that, but it can help avoid bugs
  7. # ! You can learn more about static typing in the docs
  8. # ! https://docs.godotengine.org/en/3.5/tutorials/scripting/gdscript/static_typing.html
  9. # ? Brief overview of what your mod does...
  10. const MOD_DIR := "AuthorName-ModName" # Name of the directory that this file is in
  11. const LOG_NAME := "AuthorName-ModName:Main" # Full ID of the mod (AuthorName-ModName)
  12. var mod_dir_path := ""
  13. var extensions_dir_path := ""
  14. var translations_dir_path := ""
  15. # ! your _ready func.
  16. func _init() -> void:
  17. ModLoaderLog.info("Init", LOG_NAME)
  18. mod_dir_path = ModLoaderMod.get_unpacked_dir().path_join(MOD_DIR)
  19. # Add extensions
  20. install_script_extensions()
  21. install_script_hook_files()
  22. # Add translations
  23. add_translations()
  24. func install_script_extensions() -> void:
  25. # ! any script extensions should go in this directory, and should follow the same directory structure as vanilla
  26. extensions_dir_path = mod_dir_path.path_join("extensions")
  27. # ? Brief description/reason behind this edit of vanilla code...
  28. ModLoaderMod.install_script_extension(extensions_dir_path.path_join("main.gd"))
  29. #ModLoaderMod.install_script_extension(ext_dir + "entities/units/player/player.gd") # ! Note that this file does not exist in this example mod
  30. # ! Add extensions (longform version of the above)
  31. #ModLoaderMod.install_script_extension("res://mods-unpacked/AuthorName-ModName/extensions/main.gd")
  32. #ModLoaderMod.install_script_extension("res://mods-unpacked/AuthorName-ModName/extensions/entities/units/player/player.gd")
  33. func install_script_hook_files() -> void:
  34. extensions_dir_path = mod_dir_path.path_join("extensions")
  35. ModLoaderMod.install_script_hooks("res://main.gd", extensions_dir_path.path_join("main.gd"))
  36. func add_translations() -> void:
  37. # ! Place all of your translation files into this directory
  38. translations_dir_path = mod_dir_path.path_join("translations")
  39. # ! Load translations for your mod, if you need them.
  40. # ! Add translations by adding a CSV called "modname.csv" into the "translations" directory.
  41. # ! Godot will automatically generate a ".translation" file, eg "modname.en.translation".
  42. # ! Note that in this example, only the file called "modname.csv" is custom;
  43. # ! any other files in the "translations" directory were automatically generated by Godot
  44. ModLoaderMod.add_translation(translations_dir_path.path_join("modname.en.position"))
  45. func _ready() -> void:
  46. ModLoaderLog.info("Ready", LOG_NAME)
  47. # ! This uses Godot's native `tr` func, which translates a string. You'll
  48. # ! find this particular string in the example CSV here: translations/modname.csv
  49. ModLoaderLog.info("Translation Demo: " + tr("MODNAME_READY_TEXT"), LOG_NAME)