Some cleanup

This commit is contained in:
2020-07-17 22:39:06 +02:00
parent 90b04af939
commit 125e1d567f
5 changed files with 4 additions and 30 deletions

View File

@@ -22,7 +22,6 @@ import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger;
public class WhatAStorage { public class WhatAStorage {
private static final int MAX_QUESTS = 3; private static final int MAX_QUESTS = 3;
@@ -88,7 +87,7 @@ public class WhatAStorage {
productManager.clear(); productManager.clear();
questManager.clear(); questManager.clear();
productManager.reload(contentManager); productManager.reload(contentManager);
questManager.reload(contentManager); questManager.reload(contentManager, productManager);
Util.LOGGER.log(Level.INFO, "Reloaded game content"); Util.LOGGER.log(Level.INFO, "Reloaded game content");
} }

View File

@@ -53,25 +53,4 @@ public class ContentManager {
public Stream<Resource> getAllOfResource(@NotNull String location) { public Stream<Resource> getAllOfResource(@NotNull String location) {
return packs.stream().flatMap(pack -> Stream.ofNullable(pack.getResource(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;
});
}
} }

View File

@@ -18,7 +18,6 @@ public class ProductManager implements ResourceManager<ProductType<?>> {
productTypes.clear(); productTypes.clear();
} }
@Override
public void reload(@NotNull ContentManager contentManager) { public void reload(@NotNull ContentManager contentManager) {
contentManager.getResources("products", "properties").forEach(resource -> { contentManager.getResources("products", "properties").forEach(resource -> {
InputStream inputStream = resource.getInputStream(); InputStream inputStream = resource.getInputStream();

View File

@@ -2,6 +2,7 @@ package de.siphalor.was.content.quest;
import de.siphalor.was.WhatAStorage; import de.siphalor.was.WhatAStorage;
import de.siphalor.was.content.ContentManager; import de.siphalor.was.content.ContentManager;
import de.siphalor.was.content.product.ProductManager;
import de.siphalor.was.util.ResourceManager; import de.siphalor.was.util.ResourceManager;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -18,11 +19,11 @@ public class QuestManager implements ResourceManager<QuestGenerator> {
questGenerators.clear(); questGenerators.clear();
} }
public void reload(@NotNull ContentManager contentManager) { public void reload(@NotNull ContentManager contentManager, @NotNull ProductManager productManager) {
contentManager.getResources("quests", "csv").forEach(resource -> { contentManager.getResources("quests", "csv").forEach(resource -> {
InputStream inputStream = resource.getInputStream(); InputStream inputStream = resource.getInputStream();
if (inputStream != null) { if (inputStream != null) {
questGenerators.put(resource.getId(), StaticQuestGenerator.fromCsv(inputStream, WhatAStorage.getInstance().getProductManager())); questGenerators.put(resource.getId(), StaticQuestGenerator.fromCsv(inputStream, productManager));
try { try {
inputStream.close(); inputStream.close();
} catch (IOException e) { } catch (IOException e) {

View File

@@ -1,11 +1,7 @@
package de.siphalor.was.util; package de.siphalor.was.util;
import de.siphalor.was.content.ContentManager;
import org.jetbrains.annotations.NotNull;
public interface ResourceManager<T> { public interface ResourceManager<T> {
void clear(); void clear();
void reload(@NotNull ContentManager contentManager);
T get(String id); T get(String id);
} }