More work on the new player knowledge system
This commit is contained in:
parent
3e0907fa3e
commit
c6d02aee9d
|
@ -15,6 +15,7 @@ public class ConfigurationHandler {
|
|||
|
||||
private static final String CATEGORY_SOUND = "general.sound";
|
||||
private static final String CATEGORY_ENERGY_VALUE = "general.energy_value";
|
||||
private static final String CATEGORY_PLAYER_KNOWLEDGE = "general.player_knowledge";
|
||||
|
||||
public static void init(File configFile) {
|
||||
|
||||
|
@ -58,6 +59,13 @@ public class ConfigurationHandler {
|
|||
Settings.SOUND_MODE_OPTIONS,
|
||||
Settings.SOUND_MODE_LABEL);
|
||||
|
||||
Settings.playerKnowledgeTemplateEnabled = configuration.getBoolean(
|
||||
Settings.USE_PLAYER_KNOWLEDGE_TEMPLATE_NAME,
|
||||
CATEGORY_PLAYER_KNOWLEDGE,
|
||||
Settings.USE_PLAYER_KNOWLEDGE_TEMPLATE_DEFAULT,
|
||||
StatCollector.translateToLocal(Settings.USE_PLAYER_KNOWLEDGE_TEMPLATE_COMMENT),
|
||||
Settings.USE_PLAYER_KNOWLEDGE_TEMPLATE_LABEL);
|
||||
|
||||
Settings.onlyLoadFile = configuration.getBoolean(
|
||||
Settings.ABILITIES_ONLY_LOAD_FILE_NAME,
|
||||
Configuration.CATEGORY_GENERAL,
|
||||
|
@ -108,6 +116,12 @@ public class ConfigurationHandler {
|
|||
private static final String SOUND_MODE_DEFAULT = "All";
|
||||
private static final String[] SOUND_MODE_OPTIONS = new String[]{"All", "Self", "None"};
|
||||
|
||||
public static boolean playerKnowledgeTemplateEnabled;
|
||||
private static final String USE_PLAYER_KNOWLEDGE_TEMPLATE_NAME = "use_template";
|
||||
private static final String USE_PLAYER_KNOWLEDGE_TEMPLATE_LABEL = "player_knowledge.use_template.label";
|
||||
private static final String USE_PLAYER_KNOWLEDGE_TEMPLATE_COMMENT = "player_knowledge.use_template.comment";
|
||||
private static final boolean USE_PLAYER_KNOWLEDGE_TEMPLATE_DEFAULT = true;
|
||||
|
||||
public static boolean onlyLoadFile;
|
||||
private static final String ABILITIES_ONLY_LOAD_FILE_NAME = "abilities.onlyLoadFile";
|
||||
private static final String ABILITIES_ONLY_LOAD_FILE_LABEL = "general.abilities.onlyLoadFile.label";
|
||||
|
|
|
@ -17,6 +17,10 @@ public class PlayerKnowledge {
|
|||
this(Collections.EMPTY_SET);
|
||||
}
|
||||
|
||||
public PlayerKnowledge(PlayerKnowledge playerKnowledge) {
|
||||
this(playerKnowledge.knownItemStacks);
|
||||
}
|
||||
|
||||
public PlayerKnowledge(Collection<ItemStack> itemStacks) {
|
||||
|
||||
knownItemStacks = new TreeSet<>(Comparators.ID_COMPARATOR);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.pahimar.ee3.knowledge;
|
||||
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.pahimar.ee3.handler.ConfigurationHandler;
|
||||
import com.pahimar.ee3.reference.Comparators;
|
||||
import com.pahimar.ee3.reference.Files;
|
||||
import com.pahimar.ee3.util.SerializationHelper;
|
||||
|
@ -10,6 +12,7 @@ import net.minecraft.init.Items;
|
|||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class PlayerKnowledgeRegistry {
|
||||
|
@ -48,35 +51,118 @@ public class PlayerKnowledgeRegistry {
|
|||
* teach
|
||||
* makeForget
|
||||
* makeForgetAll
|
||||
* load
|
||||
* save
|
||||
*/
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*
|
||||
* @param entityPlayer
|
||||
* @return
|
||||
*/
|
||||
public PlayerKnowledge getPlayerKnowledge(EntityPlayer entityPlayer) {
|
||||
|
||||
if (entityPlayer != null) {
|
||||
return getPlayerKnowledge(entityPlayer.getDisplayName());
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("EntityPlayer must be non-null");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*
|
||||
* @param playerName
|
||||
* @return
|
||||
*/
|
||||
public PlayerKnowledge getPlayerKnowledge(String playerName) {
|
||||
|
||||
// TODO Logging
|
||||
if (playerName != null && !playerName.isEmpty()) {
|
||||
if (!playerKnowledgeMap.containsKey(playerName)) {
|
||||
playerKnowledgeMap.put(playerName, load(getPlayerKnowledgeFile(playerName)));
|
||||
}
|
||||
|
||||
return playerKnowledgeMap.get(playerName);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Invalid player name - must not be null and must be longer than 0 characters");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*/
|
||||
public void save() {
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
||||
|
||||
// Save the template to file
|
||||
SerializationHelper.writeJsonFile(templatePlayerKnowledgeFile, SerializationHelper.GSON.toJson(templatePlayerKnowledge));
|
||||
|
||||
// Save every currently loaded player knowledge to file
|
||||
for (String playerName : playerKnowledgeMap.keySet()) {
|
||||
SerializationHelper.writeJsonFile(getPlayerKnowledgeFile(playerName), SerializationHelper.GSON.toJson(playerKnowledgeMap.get(playerName)));
|
||||
File playerKnowledgeFile = getPlayerKnowledgeFile(playerName);
|
||||
if (playerKnowledgeFile != null) {
|
||||
SerializationHelper.writeJsonFile(playerKnowledgeFile, SerializationHelper.GSON.toJson(playerKnowledgeMap.get(playerName)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SerializationHelper.writeJsonFile(templatePlayerKnowledgeFile, SerializationHelper.GSON.toJson(templatePlayerKnowledge));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*/
|
||||
public void load() {
|
||||
|
||||
// Load template knowledge
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void loadPlayer(EntityPlayer entityPlayer) {
|
||||
|
||||
}
|
||||
|
||||
public void loadPlayer(File file) {
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
private PlayerKnowledge load(File file) {
|
||||
|
||||
if (file != null) {
|
||||
try {
|
||||
String jsonString = SerializationHelper.readJsonFile(file);
|
||||
PlayerKnowledge playerKnowledge = SerializationHelper.GSON.fromJson(jsonString, PlayerKnowledge.class);
|
||||
|
||||
if (playerKnowledge != null) {
|
||||
return playerKnowledge;
|
||||
}
|
||||
}
|
||||
catch (JsonSyntaxException | FileNotFoundException e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (ConfigurationHandler.Settings.playerKnowledgeTemplateEnabled) {
|
||||
return new PlayerKnowledge(templatePlayerKnowledge);
|
||||
}
|
||||
else {
|
||||
return new PlayerKnowledge();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*
|
||||
* @param playerName
|
||||
* @return
|
||||
*/
|
||||
private static File getPlayerKnowledgeFile(String playerName) {
|
||||
return new File(Files.playerDataDirectory, "knowledge" + File.separator + "transmutation" + File.separator + playerName + ".json");
|
||||
|
||||
if (playerName != null && playerName.isEmpty()) {
|
||||
return new File(Files.playerDataDirectory, "knowledge" + File.separator + "transmutation" + File.separator + playerName + ".json");
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Invalid player name - must not be null and must be longer than 0 characters");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,11 @@ sound=Sound Options
|
|||
sound.mode.label=Play Sounds Only From
|
||||
sound.mode.comment='All' plays mod sounds from all players, 'Self' only plays mod sounds from you, and 'None' does not play any mod sounds
|
||||
|
||||
# Configuration (Player Knowledge Options)
|
||||
player_knowledge=Player Knowledge Options
|
||||
player_knowledge.use_template.label=Use Knowledge Template
|
||||
player_knowledge.use_template.comment=Whether or not to use the player knowledge template. The template allows players to start with some items already researched
|
||||
|
||||
general.abilities.onlyLoadFile.label=Only load Abilities file
|
||||
general.abilities.onlyLoadFile.comment=Setting this to true means that Abilities are initially only loaded from file, rather than from both file and from other mods
|
||||
|
||||
|
|
Loading…
Reference in a new issue