Some cleanup
This commit is contained in:
@@ -22,7 +22,6 @@ import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class WhatAStorage {
|
||||
private static final int MAX_QUESTS = 3;
|
||||
@@ -88,7 +87,7 @@ public class WhatAStorage {
|
||||
productManager.clear();
|
||||
questManager.clear();
|
||||
productManager.reload(contentManager);
|
||||
questManager.reload(contentManager);
|
||||
questManager.reload(contentManager, productManager);
|
||||
|
||||
Util.LOGGER.log(Level.INFO, "Reloaded game content");
|
||||
}
|
||||
|
||||
@@ -53,25 +53,4 @@ public class ContentManager {
|
||||
public Stream<Resource> getAllOfResource(@NotNull String location) {
|
||||
return packs.stream().flatMap(pack -> Stream.ofNullable(pack.getResource(location)));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Optional<Image> getImage(@NotNull String location) {
|
||||
return getResource(location).map(resource -> {
|
||||
InputStream inputStream = resource.getInputStream();
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
return ImageIO.read(inputStream);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ public class ProductManager implements ResourceManager<ProductType<?>> {
|
||||
productTypes.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload(@NotNull ContentManager contentManager) {
|
||||
contentManager.getResources("products", "properties").forEach(resource -> {
|
||||
InputStream inputStream = resource.getInputStream();
|
||||
|
||||
@@ -2,6 +2,7 @@ package de.siphalor.was.content.quest;
|
||||
|
||||
import de.siphalor.was.WhatAStorage;
|
||||
import de.siphalor.was.content.ContentManager;
|
||||
import de.siphalor.was.content.product.ProductManager;
|
||||
import de.siphalor.was.util.ResourceManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -18,11 +19,11 @@ public class QuestManager implements ResourceManager<QuestGenerator> {
|
||||
questGenerators.clear();
|
||||
}
|
||||
|
||||
public void reload(@NotNull ContentManager contentManager) {
|
||||
public void reload(@NotNull ContentManager contentManager, @NotNull ProductManager productManager) {
|
||||
contentManager.getResources("quests", "csv").forEach(resource -> {
|
||||
InputStream inputStream = resource.getInputStream();
|
||||
if (inputStream != null) {
|
||||
questGenerators.put(resource.getId(), StaticQuestGenerator.fromCsv(inputStream, WhatAStorage.getInstance().getProductManager()));
|
||||
questGenerators.put(resource.getId(), StaticQuestGenerator.fromCsv(inputStream, productManager));
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package de.siphalor.was.util;
|
||||
|
||||
import de.siphalor.was.content.ContentManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface ResourceManager<T> {
|
||||
void clear();
|
||||
void reload(@NotNull ContentManager contentManager);
|
||||
|
||||
T get(String id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user