Skip to content

Commit

Permalink
Prepared fix for issue #1009.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsschmidt1337 committed Dec 10, 2023
1 parent 415a276 commit 0cb5469
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 30 deletions.
9 changes: 9 additions & 0 deletions primitive_rules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,14 @@ Znap; Title "znap5.dat"; Matches ".*Znap.*"

Torus; Title "t01q1429.dat"
Torus|Inside; Title "t01i3333.dat"; Contains "Torus_Inside"
Torus|Inside (mixed); Title "48\tm06i8000.dat"; Contains "Mixed-Mode_Torus_Inner"
Torus|Outside; Title "t01o4000.dat"; Contains "Torus_Outside"
Torus|Outside (mixed); Title "48\tm04o4000.dat"; Contains "Mixed-Mode_Torus_Outer"
Torus|Tube; Title "t01q1429.dat"; Contains "Torus_Tube"

Logo; Title "logo-technic-1.dat"; Matches "Logo.*"

_Standard Bricks; Title "3002.dat"
_Standard Bricks|_Brick; Title "3005.dat"; Matches "Brick.*"
_Standard Bricks|_Plate; Title "3024.dat"; Matches "Plate.*"
_Standard Bricks|_Tile; Title "3070b.dat"; Matches "Tile.*"
Original file line number Diff line number Diff line change
Expand Up @@ -652,35 +652,6 @@ private void load(boolean waitForRenderer) {
setSelectedPrimitive(null);
primitives.clear();

List<String> searchPaths = new ArrayList<>();
String ldrawPath = WorkbenchManager.getUserSettingState().getLdrawFolderPath();
if (ldrawPath != null) {
searchPaths.add(ldrawPath + File.separator + "p" + File.separator); //$NON-NLS-1$
searchPaths.add(ldrawPath + File.separator + "P" + File.separator); //$NON-NLS-1$
searchPaths.add(ldrawPath + File.separator + "p" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
searchPaths.add(ldrawPath + File.separator + "P" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
searchPaths.add(ldrawPath + File.separator + "p" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
searchPaths.add(ldrawPath + File.separator + "P" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
}
String unofficial = WorkbenchManager.getUserSettingState().getUnofficialFolderPath();
if (unofficial != null) {
searchPaths.add(unofficial + File.separator + "p" + File.separator); //$NON-NLS-1$
searchPaths.add(unofficial + File.separator + "P" + File.separator); //$NON-NLS-1$
searchPaths.add(unofficial + File.separator + "p" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
searchPaths.add(unofficial + File.separator + "P" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
searchPaths.add(unofficial + File.separator + "p" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
searchPaths.add(unofficial + File.separator + "P" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
}
String project = Project.getProjectPath();
if (project != null) {
searchPaths.add(project + File.separator + "p" + File.separator); //$NON-NLS-1$
searchPaths.add(project + File.separator + "P" + File.separator); //$NON-NLS-1$
searchPaths.add(project + File.separator + "p" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
searchPaths.add(project + File.separator + "P" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
searchPaths.add(project + File.separator + "p" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
searchPaths.add(project + File.separator + "P" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
}

Map<String, Primitive> titleMap = new HashMap<>();
Map<String, String> leavesTitleMap = new HashMap<>();
Map<String, Primitive> primitiveMap = new HashMap<>();
Expand All @@ -689,6 +660,7 @@ private void load(boolean waitForRenderer) {
Map<String, List<PrimitiveRule>> leavesRulesMap = new HashMap<>();
final String lowResSuffix = File.separator + "8" + File.separator; //$NON-NLS-1$
final String hiResSuffix = File.separator + "48" + File.separator; //$NON-NLS-1$

try {

// Creating the categories / Rules
Expand Down Expand Up @@ -952,6 +924,37 @@ private void load(boolean waitForRenderer) {
NLogger.error(CompositePrimitive.class, e);
}
}

List<String> searchPaths = new ArrayList<>();
String ldrawPath = WorkbenchManager.getUserSettingState().getLdrawFolderPath();
if (ldrawPath != null) {
searchPaths.add(ldrawPath + File.separator + "p" + File.separator); //$NON-NLS-1$
searchPaths.add(ldrawPath + File.separator + "P" + File.separator); //$NON-NLS-1$
searchPaths.add(ldrawPath + File.separator + "p" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
searchPaths.add(ldrawPath + File.separator + "P" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
searchPaths.add(ldrawPath + File.separator + "p" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
searchPaths.add(ldrawPath + File.separator + "P" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
}
String unofficial = WorkbenchManager.getUserSettingState().getUnofficialFolderPath();
if (unofficial != null) {
searchPaths.add(unofficial + File.separator + "p" + File.separator); //$NON-NLS-1$
searchPaths.add(unofficial + File.separator + "P" + File.separator); //$NON-NLS-1$
searchPaths.add(unofficial + File.separator + "p" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
searchPaths.add(unofficial + File.separator + "P" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
searchPaths.add(unofficial + File.separator + "p" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
searchPaths.add(unofficial + File.separator + "P" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
}
String project = Project.getProjectPath();
if (project != null) {
searchPaths.add(project + File.separator + "p" + File.separator); //$NON-NLS-1$
searchPaths.add(project + File.separator + "P" + File.separator); //$NON-NLS-1$
searchPaths.add(project + File.separator + "p" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
searchPaths.add(project + File.separator + "P" + File.separator + "48" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
searchPaths.add(project + File.separator + "p" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
searchPaths.add(project + File.separator + "P" + File.separator + "8" + File.separator); //$NON-NLS-1$ //$NON-NLS-2$
}

searchPaths.add(ldrawPath + File.separator + "parts" + File.separator); //$NON-NLS-1$

boolean isUppercase = false;
boolean isEmpty = true;
Expand All @@ -961,7 +964,7 @@ private void load(boolean waitForRenderer) {
isUppercase = !isUppercase;
continue;
}
final File[] files = libFolder.listFiles();
final File[] files = listFiles(ldrawPath, libFolder);
if (files == null) {
isUppercase = !isUppercase;
continue;
Expand Down Expand Up @@ -1218,6 +1221,30 @@ private void load(boolean waitForRenderer) {
});
}

private File[] listFiles(String ldrawPath, File libFolder) {
final String partsFolder;
if ("parts".equals(libFolder.getName())) { //$NON-NLS-1$
partsFolder = "parts"; //$NON-NLS-1$
} else if ("PARTS".equals(libFolder.getName())) { //$NON-NLS-1$
partsFolder = "PARTS"; //$NON-NLS-1$
} else {
return libFolder.listFiles();
}

final String[] standardBricks = (
"""
3001.dat,3002.dat,
3005.dat,
3024.dat,
3070b.dat""").split(",");//$NON-NLS-1$ //$NON-NLS-2$
final File[] result = new File[standardBricks.length];
for (int i = 0; i < result.length; i++) {
result[i] = new File(ldrawPath + File.separator + partsFolder + File.separator + standardBricks[i].trim());
}

return result;
}

// What follows now is a very minimalistic DAT file parser (<500LOC)

private static final Pattern WHITESPACE = Pattern.compile("\\s+"); //$NON-NLS-1$
Expand Down

0 comments on commit 0cb5469

Please sign in to comment.