Added example.json to run with Cli
This commit is contained in:
parent
27c08eee39
commit
d63ee05b5d
@ -1,4 +1,4 @@
|
||||
#Sat, 25 Jul 2020 01:09:41 +0200
|
||||
#Sat, 25 Jul 2020 03:07:19 +0200
|
||||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processors.list=
|
||||
|
@ -25,12 +25,30 @@
|
||||
*/
|
||||
package opensesim.cli;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Scanner;
|
||||
import opensesim.world.GodWorld;
|
||||
import opensesim.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tube
|
||||
*/
|
||||
public class Main {
|
||||
public static void main(String[] args){
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
System.out.println("OpenSeSim Cli");
|
||||
|
||||
InputStream is;
|
||||
is = Main.class.getResourceAsStream(
|
||||
"/opensesim/resources/files/example.json"
|
||||
);
|
||||
|
||||
// We have to bootstrap with a god world because
|
||||
// there whould be no way to to initialize the world
|
||||
GodWorld godworld = new GodWorld(is);
|
||||
|
||||
System.out.println("finished");
|
||||
}
|
||||
}
|
||||
|
10
src/opensesim/resources/files/example.json
Normal file
10
src/opensesim/resources/files/example.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"version": 0.2,
|
||||
"assets": [
|
||||
{
|
||||
"type": "opensesim.sesim.Assets.FurtureAsset",
|
||||
"symbol": "MSFT",
|
||||
"name": "Hello"
|
||||
}
|
||||
]
|
||||
}
|
@ -25,6 +25,8 @@
|
||||
*/
|
||||
package opensesim.world;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Collection;
|
||||
@ -32,6 +34,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@ -75,8 +78,12 @@ public class GodWorld implements GetJson, World {
|
||||
public static final String ASSET_SYMBOL = "symbol";
|
||||
public static final String ASSET_TYPE = "type";
|
||||
|
||||
public static final String VERSION = "version";
|
||||
|
||||
}
|
||||
|
||||
public static double VERSION = 0.2;
|
||||
|
||||
/* HashSet<AbstractAsset> assetsById = new HashSet<>();
|
||||
HashMap<String, AbstractAsset> assetsBySymbol = new HashMap<>();
|
||||
*/
|
||||
@ -91,7 +98,16 @@ public class GodWorld implements GetJson, World {
|
||||
*/
|
||||
public GodWorld(JSONObject cfg) {
|
||||
init(cfg, false);
|
||||
}
|
||||
|
||||
public GodWorld(InputStream is) throws IOException{
|
||||
String s = new Scanner(is, "UTF-8").useDelimiter("\\A").next();
|
||||
JSONObject cfg = new JSONObject(s);
|
||||
Double version = cfg.getDouble(GodWorld.JKEYS.VERSION);
|
||||
if (version != GodWorld.VERSION) {
|
||||
throw new IOException("File has wrong version.");
|
||||
}
|
||||
init(cfg,false);
|
||||
}
|
||||
|
||||
public Scheduler getScheduler() {
|
||||
@ -186,7 +202,7 @@ public class GodWorld implements GetJson, World {
|
||||
cls = (Class<AbstractAsset>) Class.forName(class_name);
|
||||
a = cls.getConstructor(GodWorld.class, JSONObject.class).newInstance(this, cfg);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
|
||||
Logger.getLogger(GodWorld.class.getName()).log(Level.SEVERE, null, ex);
|
||||
Logger.getLogger(GodWorld.class.getName()).log(Level.SEVERE, class_name, ex);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user