mirror of
https://github.com/ProjectSWGCore/Holocore.git
synced 2026-10-07 22:13:40 -04:00
Refactored ClientFactory to be used statically
This commit is contained in:
@@ -46,7 +46,8 @@ import resources.client_info.visitors.SlotDescriptorData;
|
||||
import utilities.ByteUtilities;
|
||||
|
||||
public class ClientFactory {
|
||||
|
||||
private static ClientFactory instance;
|
||||
|
||||
private Map <String, ClientData> dataMap = new HashMap<String, ClientData>();
|
||||
private Map <String, String> typeMap = new HashMap<String, String>();
|
||||
|
||||
@@ -81,11 +82,17 @@ public class ClientFactory {
|
||||
* A null instance of {@link ClientData} means that parsing for the type of file is not done, or a file was entered that doesn't exist on the
|
||||
* file system.
|
||||
*/
|
||||
public synchronized ClientData getInfoFromFile(String file, boolean saveInfo) {
|
||||
ClientData data = dataMap.get(file);
|
||||
public synchronized static ClientData getInfoFromFile(String file, boolean saveInfo) {
|
||||
ClientFactory factory = ClientFactory.instance;
|
||||
if (factory == null) {
|
||||
ClientFactory.instance = new ClientFactory();
|
||||
factory = ClientFactory.instance;
|
||||
}
|
||||
|
||||
ClientData data = factory.dataMap.get(file);
|
||||
|
||||
if (data == null) {
|
||||
data = readFile(file);
|
||||
data = factory.readFile(file);
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -100,7 +107,7 @@ public class ClientFactory {
|
||||
return data;
|
||||
}
|
||||
|
||||
public synchronized ClientData getInfoFromFile(String file) {
|
||||
public synchronized static ClientData getInfoFromFile(String file) {
|
||||
return getInfoFromFile(file, true);
|
||||
}
|
||||
|
||||
@@ -184,7 +191,7 @@ public class ClientFactory {
|
||||
switch (c) {
|
||||
case "CrcStringTableData": return new CrcStringTableData();
|
||||
case "DatatableData": return new DatatableData();
|
||||
case "ObjectData": return new ObjectData(this);
|
||||
case "ObjectData": return new ObjectData();
|
||||
case "ProfTemplateData": return new ProfTemplateData();
|
||||
case "SlotDescriptorData": return new SlotDescriptorData();
|
||||
case "SlotDefinitionData": return new SlotDefinitionData();
|
||||
|
||||
@@ -39,7 +39,6 @@ import utilities.ByteUtilities;
|
||||
public class ObjectData extends ClientData {
|
||||
|
||||
private Map<String, Object> attributes = new HashMap<String, Object>();
|
||||
private ClientFactory factory;
|
||||
private List<String> parsedFiles = new ArrayList<String>();
|
||||
|
||||
public static final String APPEARANCE_FILE = "appearanceFilename";
|
||||
@@ -50,9 +49,7 @@ public class ObjectData extends ClientData {
|
||||
public static final String PORTAL_LAYOUT = "portalLayoutFilename";
|
||||
public static final String SLOT_DESCRIPTOR = "slotDescriptorFilename";
|
||||
|
||||
public ObjectData(ClientFactory factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
public ObjectData() {}
|
||||
|
||||
@Override
|
||||
public void handleData(String node, ByteBuffer data, int size) {
|
||||
@@ -64,7 +61,7 @@ public class ObjectData extends ClientData {
|
||||
if (parsedFiles.contains(file)) // some DERVXXX were repeated and we do not want to replace any attributes unless they're overriden by a more specific obj
|
||||
break;
|
||||
|
||||
ClientData attrData = factory.getInfoFromFile(file);
|
||||
ClientData attrData = ClientFactory.getInfoFromFile(file);
|
||||
if (attrData == null || !(attrData instanceof ObjectData)) {
|
||||
System.out.println("Could not load attribute data from file " + file + "!");
|
||||
return; // break out of whole method as we should only continue if we have all the extended attributes
|
||||
|
||||
@@ -39,9 +39,7 @@ import resources.objects.SWGObject;
|
||||
import resources.server_info.Log;
|
||||
|
||||
public class BuildoutLoader {
|
||||
|
||||
private static final ClientFactory clientFactory = new ClientFactory();
|
||||
private static final CrcStringTableData crcTable = (CrcStringTableData) clientFactory.getInfoFromFile("misc/object_template_crc_string_table.iff");
|
||||
private static final CrcStringTableData crcTable = (CrcStringTableData) ClientFactory.getInfoFromFile("misc/object_template_crc_string_table.iff");
|
||||
|
||||
public static List <SWGObject> loadAllBuildouts() {
|
||||
List <SWGObject> objects = new LinkedList<SWGObject>();
|
||||
@@ -51,10 +49,10 @@ public class BuildoutLoader {
|
||||
}
|
||||
|
||||
public static List <SWGObject> loadBuildoutsForTerrain(Terrain terrain) {
|
||||
DatatableData table = (DatatableData) clientFactory.getInfoFromFile("datatables/buildout/buildout_scenes.iff");
|
||||
DatatableData table = (DatatableData) ClientFactory.getInfoFromFile("datatables/buildout/buildout_scenes.iff");
|
||||
for (int row = 0; row < table.getRowCount(); row++) {
|
||||
if (table.getCell(row, 0).equals(terrain.name().toLowerCase(Locale.ENGLISH))) {
|
||||
TerrainBuildoutLoader loader = new TerrainBuildoutLoader(clientFactory, crcTable, terrain);
|
||||
TerrainBuildoutLoader loader = new TerrainBuildoutLoader(crcTable, terrain);
|
||||
loader.load(row);
|
||||
return loader.getObjects();
|
||||
}
|
||||
@@ -65,7 +63,7 @@ public class BuildoutLoader {
|
||||
}
|
||||
|
||||
private static List <Terrain> getTerrainsToLoad() {
|
||||
DatatableData table = (DatatableData) clientFactory.getInfoFromFile("datatables/buildout/buildout_scenes.iff");
|
||||
DatatableData table = (DatatableData) ClientFactory.getInfoFromFile("datatables/buildout/buildout_scenes.iff");
|
||||
List <Terrain> terrains = new LinkedList<Terrain>();
|
||||
for (int row = 0; row < table.getRowCount(); row++) {
|
||||
Terrain t = Terrain.getTerrainFromName((String) table.getCell(row, 0));
|
||||
|
||||
@@ -45,15 +45,13 @@ import services.objects.ObjectCreator;
|
||||
class TerrainBuildoutLoader {
|
||||
|
||||
private static final String BASE_PATH = "datatables/buildout/";
|
||||
|
||||
private final ClientFactory clientFactory;
|
||||
|
||||
private final CrcStringTableData crcTable;
|
||||
private final Terrain terrain;
|
||||
private final Map <Long, SWGObject> objectTable;
|
||||
private final List <SWGObject> objects;
|
||||
|
||||
public TerrainBuildoutLoader(ClientFactory clientFactory, CrcStringTableData crcTable, Terrain terrain) {
|
||||
this.clientFactory = clientFactory;
|
||||
public TerrainBuildoutLoader(CrcStringTableData crcTable, Terrain terrain) {
|
||||
this.crcTable = crcTable;
|
||||
this.terrain = terrain;
|
||||
this.objectTable = new Hashtable<Long, SWGObject>(12*1024);
|
||||
@@ -72,7 +70,7 @@ class TerrainBuildoutLoader {
|
||||
private void loadAreas(int sceneNumber) {
|
||||
objects.clear();
|
||||
String file = BASE_PATH+"areas_"+terrain.getName()+".iff";
|
||||
DatatableData areaTable = (DatatableData) clientFactory.getInfoFromFile(file);
|
||||
DatatableData areaTable = (DatatableData) ClientFactory.getInfoFromFile(file);
|
||||
for (int row = 0; row < areaTable.getRowCount(); row++) {
|
||||
BuildoutArea area = new BuildoutArea();
|
||||
area.load(areaTable.getRow(row), sceneNumber, row);
|
||||
@@ -84,7 +82,7 @@ class TerrainBuildoutLoader {
|
||||
|
||||
private void loadArea(BuildoutArea area) {
|
||||
String file = BASE_PATH+terrain.getName()+"/"+area.getName().replace("server", "client")+".iff";
|
||||
DatatableData areaTable = (DatatableData) clientFactory.getInfoFromFile(file);
|
||||
DatatableData areaTable = (DatatableData) ClientFactory.getInfoFromFile(file);
|
||||
BuildoutRow buildoutRow = new BuildoutRow(area);
|
||||
for (int row = 0; row < areaTable.getRowCount(); row++) {
|
||||
buildoutRow.load(areaTable.getRow(row), crcTable);
|
||||
|
||||
@@ -128,17 +128,16 @@ public class CommandService extends Service {
|
||||
}
|
||||
|
||||
private void loadBaseCommands() {
|
||||
final ClientFactory factory = new ClientFactory();
|
||||
final String [] commandTables = new String [] {"command_table", "client_command_table", "command_table_ground"};
|
||||
|
||||
clearCommands();
|
||||
for (String table : commandTables) {
|
||||
loadBaseCommands(factory, table);
|
||||
loadBaseCommands(table);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadBaseCommands(ClientFactory factory, String table) {
|
||||
DatatableData baseCommands = (DatatableData) factory.getInfoFromFile("datatables/command/"+table+".iff");
|
||||
private void loadBaseCommands(String table) {
|
||||
DatatableData baseCommands = (DatatableData) ClientFactory.getInfoFromFile("datatables/command/"+table+".iff");
|
||||
|
||||
for (int row = 0; row < baseCommands.getRowCount(); row++) {
|
||||
Object [] cmdRow = baseCommands.getRow(row);
|
||||
|
||||
@@ -69,9 +69,8 @@ public class MapService extends Service {
|
||||
dynamicMapLocations = new ConcurrentHashMap<>();
|
||||
persistentMapLocations = new ConcurrentHashMap<>();
|
||||
|
||||
ClientFactory clientFactory = new ClientFactory();
|
||||
loadMapCategories(clientFactory);
|
||||
loadMappingTemplates(clientFactory);
|
||||
loadMapCategories();
|
||||
loadMappingTemplates();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,8 +128,8 @@ public class MapService extends Service {
|
||||
player.sendPacket(responseMessage);
|
||||
}
|
||||
|
||||
private void loadMapCategories(ClientFactory clientFactory) {
|
||||
DatatableData table = (DatatableData) clientFactory.getInfoFromFile("datatables/player/planet_map_cat.iff");
|
||||
private void loadMapCategories() {
|
||||
DatatableData table = (DatatableData) ClientFactory.getInfoFromFile("datatables/player/planet_map_cat.iff");
|
||||
for (int row = 0; row < table.getRowCount(); row++) {
|
||||
MapCategory category = new MapCategory();
|
||||
category.setName(table.getCell(row, 0).toString());
|
||||
@@ -144,8 +143,8 @@ public class MapService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private void loadMappingTemplates(ClientFactory clientFactory) {
|
||||
DatatableData table = (DatatableData) clientFactory.getInfoFromFile("map_locations.iff");
|
||||
private void loadMappingTemplates() {
|
||||
DatatableData table = (DatatableData) ClientFactory.getInfoFromFile("map_locations.iff");
|
||||
for (int row = 0; row < table.getRowCount(); row++) {
|
||||
MappingTemplate template = new MappingTemplate();
|
||||
template.setTemplate(ClientFactory.formatToSharedFile(table.getCell(row, 0).toString()));
|
||||
|
||||
@@ -50,9 +50,7 @@ import resources.objects.waypoint.WaypointObject;
|
||||
import resources.objects.weapon.WeaponObject;
|
||||
|
||||
public final class ObjectCreator {
|
||||
|
||||
private static final ClientFactory clientFac = new ClientFactory();
|
||||
|
||||
|
||||
public static final SWGObject createObjectFromTemplate(long objectId, String template) {
|
||||
if (!template.startsWith("object/"))
|
||||
return null;
|
||||
@@ -93,7 +91,7 @@ public final class ObjectCreator {
|
||||
}
|
||||
|
||||
private static void addObjectAttributes(SWGObject obj, String template) {
|
||||
ObjectData attributes = (ObjectData) clientFac.getInfoFromFile(ClientFactory.formatToSharedFile(template));
|
||||
ObjectData attributes = (ObjectData) ClientFactory.getInfoFromFile(ClientFactory.formatToSharedFile(template));
|
||||
|
||||
String stf = (String) attributes.getAttribute(ObjectData.OBJ_STF);
|
||||
String detailStf = (String) attributes.getAttribute(ObjectData.DETAIL_STF);
|
||||
@@ -122,7 +120,7 @@ public final class ObjectCreator {
|
||||
private static void createObjectSlots(SWGObject object) {
|
||||
if (object.getTemplateAttribute(ObjectData.SLOT_DESCRIPTOR) != null) {
|
||||
// These are the slots that the object *HAS*
|
||||
SlotDescriptorData descriptor = (SlotDescriptorData) clientFac.getInfoFromFile((String) object.getTemplateAttribute(ObjectData.SLOT_DESCRIPTOR));
|
||||
SlotDescriptorData descriptor = (SlotDescriptorData) ClientFactory.getInfoFromFile((String) object.getTemplateAttribute(ObjectData.SLOT_DESCRIPTOR));
|
||||
|
||||
for (String slotName : descriptor.getSlots()) {
|
||||
object.getSlots().put(slotName, null);
|
||||
@@ -131,7 +129,7 @@ public final class ObjectCreator {
|
||||
|
||||
if (object.getTemplateAttribute(ObjectData.ARRANGEMENT_FILE) != null) {
|
||||
// This is what slots the created object is able to go into/use
|
||||
SlotArrangementData arrangementData = (SlotArrangementData) clientFac.getInfoFromFile((String) object.getTemplateAttribute(ObjectData.ARRANGEMENT_FILE));
|
||||
SlotArrangementData arrangementData = (SlotArrangementData) ClientFactory.getInfoFromFile((String) object.getTemplateAttribute(ObjectData.ARRANGEMENT_FILE));
|
||||
object.setArrangement(arrangementData.getArrangement());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,6 @@ public class ZoneService extends Service {
|
||||
|
||||
private final Map <String, Player> lockedNames;
|
||||
private final Map <String, ProfTemplateData> profTemplates;
|
||||
private final ClientFactory clientFac;
|
||||
private final NameFilter nameFilter;
|
||||
private final SWGNameGenerator nameGenerator;
|
||||
private final CharacterCreationRestriction creationRestriction;
|
||||
@@ -114,7 +113,6 @@ public class ZoneService extends Service {
|
||||
public ZoneService() {
|
||||
lockedNames = new HashMap<String, Player>();
|
||||
profTemplates = new ConcurrentHashMap<String, ProfTemplateData>();
|
||||
clientFac = new ClientFactory();
|
||||
nameFilter = new NameFilter("namegen/bad_word_list.txt", "namegen/reserved_words.txt", "namegen/fiction_reserved.txt");
|
||||
nameGenerator = new SWGNameGenerator(nameFilter);
|
||||
creationRestriction = new CharacterCreationRestriction(2);
|
||||
@@ -488,13 +486,13 @@ public class ZoneService extends Service {
|
||||
}
|
||||
|
||||
private void loadProfTemplates() {
|
||||
profTemplates.put("crafting_artisan", (ProfTemplateData) clientFac.getInfoFromFile("creation/profession_defaults_combat_brawler.iff"));
|
||||
profTemplates.put("combat_brawler", (ProfTemplateData) clientFac.getInfoFromFile("creation/profession_defaults_combat_brawler.iff"));
|
||||
profTemplates.put("social_entertainer", (ProfTemplateData) clientFac.getInfoFromFile("creation/profession_defaults_social_entertainer.iff"));
|
||||
profTemplates.put("combat_marksman", (ProfTemplateData) clientFac.getInfoFromFile("creation/profession_defaults_combat_marksman.iff"));
|
||||
profTemplates.put("science_medic", (ProfTemplateData) clientFac.getInfoFromFile("creation/profession_defaults_science_medic.iff"));
|
||||
profTemplates.put("outdoors_scout", (ProfTemplateData) clientFac.getInfoFromFile("creation/profession_defaults_outdoors_scout.iff"));
|
||||
profTemplates.put("jedi", (ProfTemplateData) clientFac.getInfoFromFile("creation/profession_defaults_jedi.iff"));
|
||||
profTemplates.put("crafting_artisan", (ProfTemplateData) ClientFactory.getInfoFromFile("creation/profession_defaults_combat_brawler.iff"));
|
||||
profTemplates.put("combat_brawler", (ProfTemplateData) ClientFactory.getInfoFromFile("creation/profession_defaults_combat_brawler.iff"));
|
||||
profTemplates.put("social_entertainer", (ProfTemplateData) ClientFactory.getInfoFromFile("creation/profession_defaults_social_entertainer.iff"));
|
||||
profTemplates.put("combat_marksman", (ProfTemplateData) ClientFactory.getInfoFromFile("creation/profession_defaults_combat_marksman.iff"));
|
||||
profTemplates.put("science_medic", (ProfTemplateData) ClientFactory.getInfoFromFile("creation/profession_defaults_science_medic.iff"));
|
||||
profTemplates.put("outdoors_scout", (ProfTemplateData) ClientFactory.getInfoFromFile("creation/profession_defaults_outdoors_scout.iff"));
|
||||
profTemplates.put("jedi", (ProfTemplateData) ClientFactory.getInfoFromFile("creation/profession_defaults_jedi.iff"));
|
||||
}
|
||||
|
||||
private boolean lockName(String name, Player player) {
|
||||
|
||||
Reference in New Issue
Block a user