Removed ServerFactory and the DataFactory abstraction, as there's only one subclass now

This commit is contained in:
Ziggy
2023-05-28 22:59:39 +02:00
parent f80a5b410d
commit b76b0f4ebe
2 changed files with 33 additions and 96 deletions

View File

@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2023 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
@@ -30,14 +30,17 @@ import com.projectswg.common.data.swgfile.visitors.*;
import com.projectswg.common.data.swgfile.visitors.appearance.*;
import com.projectswg.common.data.swgfile.visitors.shader.CustomizableShaderData;
import com.projectswg.common.data.swgfile.visitors.shader.StaticShaderData;
import me.joshlarson.jlcommon.log.Log;
import java.io.File;
import java.io.IOException;
import java.nio.channels.ClosedChannelException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
public class ClientFactory extends DataFactory {
public class ClientFactory {
private static final ClientFactory INSTANCE = new ClientFactory();
private static final Map <String, ClientData> DATA_MAP = new ConcurrentHashMap<>();
@@ -64,7 +67,34 @@ public class ClientFactory extends DataFactory {
private ClientFactory() {
}
protected ClientData readFile(String filename) {
return readFile(new File(getFolder() + filename));
}
protected ClientData readFile(File file) {
if (!file.isFile()) {
return null;
}
SWGFile swgFile = new SWGFile();
try {
swgFile.read(file);
} catch (IOException e) {
if (!(e instanceof ClosedChannelException))
Log.e(e);
return null;
}
ClientData clientData = createDataObject(swgFile.getType());
if (clientData == null)
return null;
clientData.readIff(swgFile);
return clientData;
}
public static void freeMemory() {
DATA_MAP.clear();
}
@@ -119,7 +149,6 @@ public class ClientFactory extends DataFactory {
// of that instance so the file can be parsed. The type is the name of the folder/node which is then used to get the value associated
// with it in the typeMap (value being the name of the Class preferably). If populateTypeMap() does not contain that node, then null is returned
// and getFileType method will print out what the type is along with a "not implemented!" message.
@Override
protected ClientData createDataObject(String type) {
ClientFactoryType c = TYPE_MAP.get(type);
if (c != null)
@@ -181,7 +210,6 @@ public class ClientFactory extends DataFactory {
//
}
@Override
protected String getFolder() {
return "clientdata/";
}

View File

@@ -1,91 +0,0 @@
/***********************************************************************************
* Copyright (c) 2018 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* This file is part of PSWGCommon. *
* *
* --------------------------------------------------------------------------------*
* *
* PSWGCommon is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* PSWGCommon is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with PSWGCommon. If not, see <http://www.gnu.org/licenses/>. *
***********************************************************************************/
package com.projectswg.common.data.swgfile;
import java.io.File;
import java.io.IOException;
import java.nio.channels.ClosedChannelException;
import me.joshlarson.jlcommon.log.Log;
/**
* Created by Waverunner on 6/9/2015
*/
public abstract class DataFactory {
protected ClientData readFile(String filename) {
return readFile(new File(getFolder() + filename));
}
protected ClientData readFile(File file) {
if (!file.isFile()) {
return null;
}
SWGFile swgFile = new SWGFile();
try {
swgFile.read(file);
} catch (IOException e) {
if (!(e instanceof ClosedChannelException))
Log.e(e);
return null;
}
ClientData clientData = createDataObject(swgFile.getType());
if (clientData == null)
return null;
clientData.readIff(swgFile);
return clientData;
}
protected File writeFile(SWGFile swgFile, ClientData data) {
if (swgFile == null || data == null) {
Log.e("File or data objects cannot be null or empty!");
return null;
}
File save = new File(swgFile.getFileName());
data.writeIff(swgFile);
try {
swgFile.save(save);
} catch (IOException e) {
Log.e(e);
}
return save;
}
protected abstract String getFolder();
protected abstract ClientData createDataObject(String type);
protected ClientData createDataObject(SWGFile swgFile) {
return createDataObject(swgFile.getType());
}
}