MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / ParseSource

Method ParseSource

src/openrct2/object/ResourceTable.cpp:48–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46 }
47
48 ResourceTable::SourceInfo ResourceTable::ParseSource(std::string_view source)
49 {
50 SourceInfo info;
51 auto base = source;
52 auto rangeStart = source.find('[');
53 if (rangeStart != std::string::npos)
54 {
55 base = source.substr(0, rangeStart);
56 info.SourceRange = ParseRange(source.substr(rangeStart));
57 }
58
59 auto fileName = base;
60 auto fileNameStart = base.find('/');
61 if (fileNameStart != std::string::npos)
62 {
63 fileName = base.substr(fileNameStart + 1);
64 }
65 else
66 {
67 fileNameStart = base.find(':');
68 if (fileNameStart != std::string::npos)
69 {
70 fileName = base.substr(fileNameStart + 1);
71 }
72 }
73
74 auto& env = GetContext()->GetPlatformEnvironment();
75 if (String::startsWith(base, "$LGX:"))
76 {
77 info.Kind = SourceKind::gx;
78 info.Path = fileName;
79 }
80 else if (String::startsWith(base, "$G1"))
81 {
82 auto dataPath = env.GetDirectoryPath(DirBase::rct2, DirId::data);
83 info.Kind = SourceKind::g1;
84 // info.Path = env->FindFile(DirBase::rct2, DirId::data, "g1.dat");
85 }
86 else if (String::startsWith(base, "$CSG"))
87 {
88 auto dataPath = env.GetDirectoryPath(DirBase::rct2, DirId::data);
89 info.Kind = SourceKind::csg;
90 // info.Path = env->FindFile(DirBase::rct2, DirId::data, "g1.dat");
91 }
92 else if (String::startsWith(base, "$RCT1:DATA/"))
93 {
94 info.Kind = SourceKind::data;
95 info.Path = env.FindFile(DirBase::rct1, DirId::data, fileName);
96 }
97 else if (String::startsWith(base, "$RCT2:DATA/"))
98 {
99 info.Kind = SourceKind::data;
100 info.Path = env.FindFile(DirBase::rct2, DirId::data, fileName);
101 }
102 else if (String::startsWith(base, "$RCT2:OBJDATA/"))
103 {
104 info.Kind = SourceKind::objData;
105 info.Path = env.FindFile(DirBase::rct2, DirId::objects, fileName);

Callers

nothing calls this directly

Calls 5

GetContextFunction · 0.85
startsWithFunction · 0.85
findMethod · 0.80
GetDirectoryPathMethod · 0.80
FindFileMethod · 0.80

Tested by

no test coverage detected