World can be imported from JSON

At least for assets.
This commit is contained in:
7u83 2018-12-05 19:13:19 +01:00
parent 53bc93a15c
commit e516770fca
6 changed files with 23 additions and 9 deletions

View File

@ -1,4 +1,4 @@
#Wed, 05 Dec 2018 18:41:22 +0100 #Wed, 05 Dec 2018 19:04:38 +0100
annotation.processing.enabled=true annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false annotation.processing.enabled.in.editor=false
annotation.processing.processors.list= annotation.processing.processors.list=

View File

@ -218,12 +218,12 @@ public class AssetEditorPanel extends javax.swing.JPanel {
); );
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
@Export @Export("decimals")
public String getDeecimals() { public String getDecimals() {
return decimalsField.getValue().toString(); return decimalsField.getValue().toString();
} }
@Import @Import("decimals")
public void setDecimals(String d) { public void setDecimals(String d) {
decimalsField.setValue(Integer.parseInt(d)); decimalsField.setValue(Integer.parseInt(d));
} }
@ -277,6 +277,8 @@ public class AssetEditorPanel extends javax.swing.JPanel {
public boolean save(WorldAdm worldadm ){ public boolean save(WorldAdm worldadm ){
JSONObject jo = Json.get(this); JSONObject jo = Json.get(this);
System.out.printf("ASSETGETTER: %s\n",jo.toString(5));
if (jo.getString(World.JKEYS.ASSET_SYMBOL).length()==0){ if (jo.getString(World.JKEYS.ASSET_SYMBOL).length()==0){
javax.swing.JOptionPane.showMessageDialog(this, "Symbol must not be empty.", javax.swing.JOptionPane.showMessageDialog(this, "Symbol must not be empty.",
"Error", "Error",

View File

@ -178,10 +178,15 @@ public class AssetListDialog extends EscDialog {
AssetEditorDialog.runDialog(this, worldadm, o, null); AssetEditorDialog.runDialog(this, worldadm, o, null);
assetListPanel.reload(); assetListPanel.reload();
}//GEN-LAST:event_newButtonActionPerformed }//GEN-LAST:event_newButtonActionPerformed
private void doneButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_doneButtonActionPerformed private void doneButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_doneButtonActionPerformed
dispose(); dispose();
JSONObject o = worldadm.world.getJson();
Globals.prefs.put("world", o.toString());
}//GEN-LAST:event_doneButtonActionPerformed }//GEN-LAST:event_doneButtonActionPerformed
private void doEdit() { private void doEdit() {

View File

@ -91,8 +91,9 @@ public class SeSimApplication extends javax.swing.JFrame {
// Globals.setLookAndFeel("Metal"); // Globals.setLookAndFeel("Metal");
initComponents(); initComponents();
JSONObject cfg;
worldadm = new WorldAdm(); cfg = new JSONObject(Globals.prefs.get("world","{}"));
worldadm = new WorldAdm(cfg);

View File

@ -90,6 +90,9 @@ public class World implements GetJson {
private void putJson(JSONObject cfg){ private void putJson(JSONObject cfg){
// Read assets // Read assets
JSONArray jassets = cfg.optJSONArray(World.JKEYS.ASSETS); JSONArray jassets = cfg.optJSONArray(World.JKEYS.ASSETS);
if (jassets==null){
jassets=new JSONArray();
}
for (int i=0; i<jassets.length();i++) { for (int i=0; i<jassets.length();i++) {
JSONObject o = jassets.optJSONObject(i); JSONObject o = jassets.optJSONObject(i);
AbstractAsset a; AbstractAsset a;
@ -117,8 +120,9 @@ public class World implements GetJson {
} }
private long masterkey; private long masterkey;
public World(long masterkey){ public World(JSONObject cfg, long masterkey){
this.masterkey=masterkey; this.masterkey=masterkey;
putJson(cfg);
} }
private AbstractAsset createAsset_p(JSONObject cfg) throws SeSimException { private AbstractAsset createAsset_p(JSONObject cfg) throws SeSimException {

View File

@ -25,6 +25,8 @@
*/ */
package opensesim.world; package opensesim.world;
import org.json.JSONObject;
/** /**
* *
* @author tohe * @author tohe
@ -32,9 +34,9 @@ package opensesim.world;
public class WorldAdm { public class WorldAdm {
public World world; public World world;
public long masterKey; public long masterKey;
public WorldAdm(){ public WorldAdm(JSONObject cfg){
masterKey = 123456; masterKey = 123456;
world = new World(masterKey); world = new World(cfg,masterKey);
} }
public World getWorld() { public World getWorld() {