minor blueprint db tweaks
This commit is contained in:
parent
a035a15632
commit
26a65250f2
2 changed files with 41 additions and 1 deletions
|
@ -75,6 +75,10 @@ public class Blueprint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected BlueprintMeta getMeta() {
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
|
||||||
public BlueprintId getId() {
|
public BlueprintId getId() {
|
||||||
return meta.getId();
|
return meta.getId();
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,14 +38,39 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||||
* @author CovertJaguar <http://www.railcraft.info/>
|
* @author CovertJaguar <http://www.railcraft.info/>
|
||||||
*/
|
*/
|
||||||
public class BlueprintDatabase {
|
public class BlueprintDatabase {
|
||||||
|
/**
|
||||||
|
* Initialize the blueprint database.
|
||||||
|
*
|
||||||
|
* @param configDir config directory to read the blueprints from.
|
||||||
|
*/
|
||||||
public static void init(File configDir) {
|
public static void init(File configDir) {
|
||||||
blueprintFolder = new File(new File(configDir, "buildcraft"), "blueprints");
|
blueprintFolder = new File(new File(configDir, "buildcraft"), "blueprints");
|
||||||
|
|
||||||
if (!blueprintFolder.exists()) blueprintFolder.mkdirs();
|
if (!blueprintFolder.exists()) blueprintFolder.mkdirs();
|
||||||
|
|
||||||
loadIndex();
|
loadIndex(); // TODO: load index in a thread
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: server: send ids to the client on connect, mby full meta
|
||||||
|
// TODO: client: send missing blueprints to the server after receiving the server's ids
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list with the metadata for all available blueprints.
|
||||||
|
*
|
||||||
|
* @return meta data iterable
|
||||||
|
*/
|
||||||
|
public static Iterable<BlueprintMeta> getList() {
|
||||||
|
return blueprintMetas.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a specific blueprint by id.
|
||||||
|
*
|
||||||
|
* @note The blueprint will be loaded as needed.
|
||||||
|
*
|
||||||
|
* @param id blueprint id
|
||||||
|
* @return blueprint or null if it can't be retrieved
|
||||||
|
*/
|
||||||
public static Blueprint get(BlueprintId id) {
|
public static Blueprint get(BlueprintId id) {
|
||||||
Blueprint ret = blueprints.get(id);
|
Blueprint ret = blueprints.get(id);
|
||||||
|
|
||||||
|
@ -59,13 +84,24 @@ public class BlueprintDatabase {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a blueprint to the database and save it to disk.
|
||||||
|
*
|
||||||
|
* @param blueprint blueprint to add
|
||||||
|
* @return id for the added blueprint
|
||||||
|
*/
|
||||||
public static BlueprintId add(Blueprint blueprint) {
|
public static BlueprintId add(Blueprint blueprint) {
|
||||||
BlueprintId id = save(blueprint);
|
BlueprintId id = save(blueprint);
|
||||||
|
|
||||||
blueprint.setId(id);
|
blueprint.setId(id);
|
||||||
|
|
||||||
|
BlueprintMeta prevValue = blueprintMetas.put(id, blueprint.getMeta());
|
||||||
blueprints.put(id, blueprint);
|
blueprints.put(id, blueprint);
|
||||||
|
|
||||||
|
if (prevValue != null) {
|
||||||
|
// TODO: duplicate entry, shouldn't happen
|
||||||
|
}
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue