Skip to content

Commit

Permalink
add resource load system
Browse files Browse the repository at this point in the history
  • Loading branch information
efekos committed Jan 30, 2024
1 parent 8e407bc commit b16a295
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/dev/efekos/pg/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public static Path getMainPath() {
private static final ProcessContext context = new ProcessContext();

private static final List<Process> processList = Arrays.asList(
new ReadResourcesProcess(),
new LoadLocalesProcess(),
new SetupBinFolderProcess(),
new GrabDataProcess(),
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/dev/efekos/pg/process/ProcessContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import dev.efekos.pg.data.schema.*;
import dev.efekos.pg.data.timeline.TimelineEvent;
import dev.efekos.pg.resource.ResourceManager;

import java.util.Arrays;
import java.util.List;
Expand All @@ -32,4 +33,5 @@ public class ProcessContext {
public List<Project> projects;
public TagColorInfo tagColorInfo;
public List<TimelineEvent> collectedTimeline;
public ResourceManager resourceManager;
}
36 changes: 36 additions & 0 deletions src/main/java/dev/efekos/pg/process/ReadResourcesProcess.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2024 efekos
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package dev.efekos.pg.process;

import dev.efekos.pg.Main;
import dev.efekos.pg.resource.ResourceManager;

public class ReadResourcesProcess implements Process {
@Override
public String getName() {
return "Load Resources";
}

@Override
public void init(ProcessContext context) throws Exception {
Main.LOGGER.info("Creating resource manager");
ResourceManager manager = new ResourceManager();
manager.init();

context.resourceManager = manager;
}
}
40 changes: 40 additions & 0 deletions src/main/java/dev/efekos/pg/resource/Resource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2024 efekos
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package dev.efekos.pg.resource;

public class Resource {
private final String pathName;
private final boolean removeCopyright;

public String getPathName(){
return pathName;
}

public boolean shouldRemoveCopyright(){
return removeCopyright;
}

public Resource(String pathName) {
this.pathName = pathName;
this.removeCopyright = false;
}

public Resource(String pathName, boolean removeCopyright) {
this.pathName = pathName;
this.removeCopyright = removeCopyright;
}
}
78 changes: 78 additions & 0 deletions src/main/java/dev/efekos/pg/resource/ResourceManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2024 efekos
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package dev.efekos.pg.resource;

import dev.efekos.pg.Main;

import java.util.HashMap;

public class ResourceManager {
private final HashMap<Resource,String> resourceMap = new HashMap<>();

public void init(){
Main.LOGGER.info("Loading resources");
Resources.all().forEach(this::putResource);
Main.LOGGER.success("Loaded "+resourceMap.size()+" resources");
}

private final String CSS_COPYRIGHT_TEXT = """
/*
* Copyright 2024 efekos
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
""";
private final String HTML_COPYRIGHT_TEXT = """
<!--
~ Copyright 2024 efekos
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
~ documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
~ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
~ persons to whom the Software is furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
~ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
~ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
~ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
""";

private void putResource(Resource resource){
String s = Main.readStringResource(resource.getPathName());
if(resource.shouldRemoveCopyright()){
s = s.replace(CSS_COPYRIGHT_TEXT,"").replace(HTML_COPYRIGHT_TEXT,"");
}
resourceMap.put(resource,s);
}

public String getResource(Resource resource){
return resourceMap.get(resource);
}
}
Loading

0 comments on commit b16a295

Please sign in to comment.