Skip to main content

ModPath

See the code at utils/path.gd

Description

Inherits Object

Utilities to help with mod file system paths.


Properties

ExtensionRegEx

static var ExtensionRegEx: RegEx = RegEx.create_from_string("\\.(?<ext>((?<sub_ext>[^.\\/]+)\\.)?(?<main_ext>[^\\/.]+))$")

A RegEx that captures three groups from a file path.

  1. ext - the full extension
  2. sub_ext - the sub extension, if it exists
  3. main_ext - the main extension

Note: While this is a variable, it is NOT meant to be mutated.

Ex.

my_mod.mod.json

  1. ext is mod.json
  2. sub_ext is mod
  3. main_ext is json
TypeRegEx
Default\.(?<ext>((?<sub_ext>[^.\/]+)\.)?(?<main_ext>[^\/.]+))$

Methods

get_extension

static func get_extension(path: String) -> String

Returns the extended extension of the given path.

Note: This is a static method, intended to be called directly on the ModPath class.

Examples

assert(ModPath.get_extension("my_mod.mod.json") == "mod.json")
assert(ModPath.get_extension("my_mod.tres") == "tres")

Parameters

NameTypeDescription
pathStringThe file path from which to get the extension.

Returns

TypeString
DescriptionThe file path's extension.

is_mod_path

static func is_mod_path(path: String) -> bool

Checks if the provided path is a mod file path.

Returns true if the given path is in the format *.mod.tres, *.mod.res, or *.mod.json.

Note: This is a static method, intended to be called directly on the ModPath class.

Parameters

NameTypeDescription
pathStringThe file path to check.

Returns

Typebool
DescriptionReturns true if the given path is in the format *.mod.tres, *.mod.res, or *.mod.json.

to_import_path

static func to_import_path(path: String) -> String

Creates a new path with extension .import.tres.

Note: This is a static method, intended to be called directly on the ModPath class.

Parameters

NameTypeDescription
pathStringThe file path to check.

Returns

TypeString
DescriptionThe modified path.