Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Grasscutter
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
ziqian zhang
Grasscutter
Commits
4b05ed28
Commit
4b05ed28
authored
3 years ago
by
Melledy
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #15 from Melledy/file-separator
Use the operating system's file separator
parents
d98ea08f
d873b8ad
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/emu/grasscutter/data/ResourceLoader.java
+21
-26
21 additions, 26 deletions
src/main/java/emu/grasscutter/data/ResourceLoader.java
src/main/java/emu/grasscutter/utils/Utils.java
+9
-0
9 additions, 0 deletions
src/main/java/emu/grasscutter/utils/Utils.java
with
30 additions
and
26 deletions
src/main/java/emu/grasscutter/data/ResourceLoader.java
+
21
−
26
View file @
4b05ed28
...
...
@@ -2,20 +2,12 @@ package emu.grasscutter.data;
import
java.io.File
;
import
java.io.FileReader
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.TreeMap
;
import
java.util.*
;
import
java.util.Map.Entry
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.stream.Stream
;
import
emu.grasscutter.utils.Utils
;
import
org.reflections.Reflections
;
import
com.google.gson.reflect.TypeToken
;
...
...
@@ -39,19 +31,12 @@ public class ResourceLoader {
}
});
classList
.
sort
((
a
,
b
)
->
{
return
b
.
getAnnotation
(
ResourceType
.
class
).
loadPriority
().
value
()
-
a
.
getAnnotation
(
ResourceType
.
class
).
loadPriority
().
value
();
});
classList
.
sort
((
a
,
b
)
->
b
.
getAnnotation
(
ResourceType
.
class
).
loadPriority
().
value
()
-
a
.
getAnnotation
(
ResourceType
.
class
).
loadPriority
().
value
());
return
classList
;
}
public
static
void
loadAll
()
{
// Create resource folder if it doesnt exist
File
resFolder
=
new
File
(
Grasscutter
.
getConfig
().
RESOURCE_FOLDER
);
if
(!
resFolder
.
exists
())
{
resFolder
.
mkdir
();
}
// Load ability lists
loadAbilityEmbryos
();
loadOpenConfig
();
...
...
@@ -110,7 +95,7 @@ public class ResourceLoader {
try
{
loadFromResource
(
resourceDefinition
,
type
,
map
);
}
catch
(
Exception
e
)
{
Grasscutter
.
getLogger
().
error
(
"Error loading resource file: "
+
type
.
name
(),
e
);
Grasscutter
.
getLogger
().
error
(
"Error loading resource file: "
+
Arrays
.
toString
(
type
.
name
()
)
,
e
);
}
}
}
...
...
@@ -153,10 +138,16 @@ public class ResourceLoader {
Pattern
pattern
=
Pattern
.
compile
(
"(?<=ConfigAvatar_)(.*?)(?=.json)"
);
embryoList
=
new
LinkedList
<>();
File
folder
=
new
File
(
Grasscutter
.
getConfig
().
RESOURCE_FOLDER
+
"BinOutput\\Avatar\\"
);
for
(
File
file
:
folder
.
listFiles
())
{
AvatarConfig
config
=
null
;
String
avatarName
=
null
;
File
folder
=
new
File
(
Utils
.
toFilePath
(
Grasscutter
.
getConfig
().
RESOURCE_FOLDER
+
"BinOutput/Avatar/"
));
File
[]
files
=
folder
.
listFiles
();
if
(
files
==
null
)
{
Grasscutter
.
getLogger
().
error
(
"Error loading ability embryos: no files found in "
+
folder
.
getAbsolutePath
());
return
;
}
for
(
File
file
:
files
)
{
AvatarConfig
config
;
String
avatarName
;
Matcher
matcher
=
pattern
.
matcher
(
file
.
getName
());
if
(
matcher
.
find
())
{
...
...
@@ -209,14 +200,18 @@ public class ResourceLoader {
String
[]
folderNames
=
{
"BinOutput\\Talent\\EquipTalents\\"
,
"BinOutput\\Talent\\AvatarTalents\\"
};
for
(
String
name
:
folderNames
)
{
File
folder
=
new
File
(
Grasscutter
.
getConfig
().
RESOURCE_FOLDER
+
name
);
File
folder
=
new
File
(
Utils
.
toFilePath
(
Grasscutter
.
getConfig
().
RESOURCE_FOLDER
+
name
));
File
[]
files
=
folder
.
listFiles
();
if
(
files
==
null
)
{
Grasscutter
.
getLogger
().
error
(
"Error loading open config: no files found in "
+
folder
.
getAbsolutePath
());
return
;
}
for
(
File
file
:
f
older
.
listF
iles
()
)
{
for
(
File
file
:
files
)
{
if
(!
file
.
getName
().
endsWith
(
".json"
))
{
continue
;
}
Map
<
String
,
OpenConfigData
[]>
config
=
null
;
Map
<
String
,
OpenConfigData
[]>
config
;
try
(
FileReader
fileReader
=
new
FileReader
(
file
))
{
config
=
Grasscutter
.
getGsonFactory
().
fromJson
(
fileReader
,
type
);
...
...
This diff is collapsed.
Click to expand it.
src/main/java/emu/grasscutter/utils/Utils.java
+
9
−
0
View file @
4b05ed28
...
...
@@ -79,6 +79,15 @@ public final class Utils {
return
v7
;
}
/**
* Creates a string with the path to a file.
* @param path The path to the file.
* @return A path using the operating system's file separator.
*/
public
static
String
toFilePath
(
String
path
)
{
return
path
.
replace
(
"/"
,
File
.
separator
);
}
/**
* Checks if a file exists on the file system.
* @param path The path to the file.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment