Skip to content

Commit

Permalink
New path interpolation tool
Browse files Browse the repository at this point in the history
  • Loading branch information
ZILtoid1991 committed Jul 4, 2024
1 parent 14f4ab8 commit 492d33d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pixelperfectengine/src/pixelperfectengine/system/etc.d
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ S removeUnallowedDups(S)(S input, S symbolList) @safe pure nothrow {
* and/or numbers.
* Returns: The interpolated string.
*/
S interpolateStr(S)(S input, S[S] symbolList) @safe pure nothrow {
S interpolateStr(S)(S input, S[S] symbolList) @safe pure {
S output;
while (input.length) {
ptrdiff_t begin = countUntil(input, '%');
Expand Down
13 changes: 12 additions & 1 deletion pixelperfectengine/src/pixelperfectengine/system/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ public dstring loadTextFile(F = File)(F file) {
public immutable string pathRoot;
///Path to the executable folder, null if not eveilable for security reasons.
public immutable string pathExec;
public string[string] pathSymbols;
shared static this () {
import std.path;
import std.file : exists;
Expand All @@ -270,6 +271,9 @@ shared static this () {
else assert(0, "Folder /system/ does not exist! Please reinstall the software or contact the developer if that does
not solve the issue.");
}
pathSymbols["PATH"] = pathRoot;
pathSymbols["EXEC"] = pathToExec;
pathSymbols["SYSTEM"] = pathRoot ~ "/system/";
}
/**
* Builds a path to the language file.
Expand All @@ -285,14 +289,21 @@ public string getPathToLocalizationFile (string country, string language, string
return pathRoot ~ "/local/" ~ language ~ "." ~ fileext;
}
///Builds a path to the asset path.
///This function will be favored less moving forward.
public string getPathToAsset (string path) @safe pure {
if (startsWith(path, "%PATH%")) path = path[6..$];
else if (startsWith(path, "../", "..\\")) path = path[3..$];
//else if (startsWith(path, ["./", ".\\"])) path = path[2..$];
return buildNormalizedPath(pathRoot ~ dirSeparator ~ path);
}
///Subtitutes symbols found in `path`, then returns the resolved path.
///This function will be favored more moving forward.
public string resolvePath(string path) @safe {
import pixelperfectengine.system.etc : interpolateStr;
return interpolateStr(path, pathSymbols);
}
/**
* Implements the RIFF serialization system
* Implements the RIFF serialization system (Maybe remove?)
*/
public struct RIFFHeader{
char[4] data;
Expand Down

0 comments on commit 492d33d

Please sign in to comment.