NoJobEngine
2.0.7
Toggle main menu visibility
Loading...
Searching...
No Matches
NeuralAssetPaths.h
Go to the documentation of this file.
1
6
#pragma once
7
#include "
Engine/AI/BehaviorTree/BTAssetPaths.h
"
8
#include <algorithm>
9
#include <cctype>
10
#include <filesystem>
11
#include <stdexcept>
12
#include <string>
13
#include <vector>
14
15
namespace
NoJob
{
16
inline
std::filesystem::path
NeuralAssetDirectory
() {
17
// Use the same project-root resolution as Behavior Trees.
18
const
auto
root =
BTPathsDetail::FindProjectRoot
();
19
if
(!root.empty())
return
root /
"Assets"
/
"Neural"
;
20
std::error_code ec;
21
const
auto
cwd = std::filesystem::current_path(ec);
22
if
(ec)
return
std::filesystem::path(
"Assets"
) /
"Neural"
;
23
for
(
auto
base = cwd;; base = base.parent_path()) {
24
const
auto
folder = base /
"Assets"
/
"Neural"
;
25
if
(std::filesystem::is_directory(folder, ec))
return
folder;
26
if
(base == base.root_path() || base == base.parent_path())
break
;
27
}
28
return
cwd /
"Assets"
/
"Neural"
;
29
}
30
inline
bool
IsValidNeuralAssetName
(
const
std::string& name) {
31
return
IsValidBTAssetName
(name);
32
}
33
inline
std::filesystem::path
NeuralAssetPath
(
const
std::string& name) {
34
if
(!
IsValidNeuralAssetName
(name))
35
throw
std::invalid_argument(
"Invalid neural network name"
);
36
return
NeuralAssetDirectory
() / (name +
".njn"
);
37
}
38
inline
std::vector<std::string>
ListNeuralAssetNames
() {
39
std::vector<std::string> names;
40
const
auto
folder =
NeuralAssetDirectory
();
41
std::error_code ec;
42
if
(!std::filesystem::is_directory(folder, ec))
return
names;
43
for
(std::filesystem::directory_iterator it(folder, std::filesystem::directory_options::skip_permission_denied, ec), end;
44
it != end && !ec; it.increment(ec)) {
45
if
(!it->is_regular_file(ec))
continue
;
46
std::string ext = it->path().extension().string();
47
std::transform(ext.begin(), ext.end(), ext.begin(),
48
[](
unsigned
char
c) { return static_cast<char>(std::tolower(c)); });
49
if
(ext ==
".njn"
) names.push_back(it->path().stem().string());
50
}
51
std::sort(names.begin(), names.end());
52
names.erase(std::unique(names.begin(), names.end()), names.end());
53
return
names;
54
}
55
}
// namespace NoJob
BTAssetPaths.h
BTAssetPaths declarations for the Behavior Trees subsystem.
NoJob::BTPathsDetail::FindProjectRoot
fs::path FindProjectRoot()
Definition
BTAssetPaths.h:18
NoJob
Definition
BTActionNode.h:13
NoJob::IsValidBTAssetName
bool IsValidBTAssetName(const std::string &name)
Definition
BTAssetPaths.h:62
NoJob::NeuralAssetDirectory
std::filesystem::path NeuralAssetDirectory()
Definition
NeuralAssetPaths.h:16
NoJob::IsValidNeuralAssetName
bool IsValidNeuralAssetName(const std::string &name)
Definition
NeuralAssetPaths.h:30
NoJob::ListNeuralAssetNames
std::vector< std::string > ListNeuralAssetNames()
Definition
NeuralAssetPaths.h:38
NoJob::NeuralAssetPath
std::filesystem::path NeuralAssetPath(const std::string &name)
Definition
NeuralAssetPaths.h:33
Engine
AI
Neural
NeuralAssetPaths.h
Generated by
1.18.0