List of usage examples for com.badlogic.gdx.utils Json setIgnoreUnknownFields
public void setIgnoreUnknownFields(boolean ignoreUnknownFields)
From source file:com.bladecoder.engine.model.World.java
License:Apache License
/** * Load the world description in 'world.json'. * /*from w w w. j a v a 2 s . c o m*/ * @throws IOException */ public void loadWorldDesc() throws IOException { if (EngineAssetManager.getInstance().getModelFile(EngineAssetManager.WORLD_FILENAME_JSON).exists()) { SerializationHelper.getInstance().setMode(Mode.MODEL); JsonValue root = new JsonReader().parse(EngineAssetManager.getInstance() .getModelFile(EngineAssetManager.WORLD_FILENAME_JSON).reader("UTF-8")); Json json = new Json(); json.setIgnoreUnknownFields(true); int width = json.readValue("width", Integer.class, root); int height = json.readValue("height", Integer.class, root); // When we know the world width, we can put the scale EngineAssetManager.getInstance().setScale(width, height); float scale = EngineAssetManager.getInstance().getScale(); setWidth((int) (width * scale)); setHeight((int) (height * scale)); setInitChapter(json.readValue("initChapter", String.class, root)); verbs.read(json, root); I18N.loadWorld(EngineAssetManager.MODEL_DIR + "world"); } else { EngineLogger.error("ERROR LOADING WORLD: world.json doesn't exists."); dispose(); throw new IOException("ERROR LOADING WORLD: world.json doesn't exists."); } }
From source file:com.bladecoder.engine.model.World.java
License:Apache License
public void loadChapter(String chapterName) throws IOException { if (!disposed) dispose();/*from w w w.j av a 2s .co m*/ init(); long initTime = System.currentTimeMillis(); SerializationHelper.getInstance().setMode(Mode.MODEL); if (chapterName == null) chapterName = initChapter; currentChapter = initChapter; if (EngineAssetManager.getInstance().getModelFile(chapterName + EngineAssetManager.CHAPTER_EXT).exists()) { JsonValue root = new JsonReader().parse(EngineAssetManager.getInstance() .getModelFile(chapterName + EngineAssetManager.CHAPTER_EXT).reader("UTF-8")); Json json = new Json(); json.setIgnoreUnknownFields(true); read(json, root); I18N.loadChapter(EngineAssetManager.MODEL_DIR + chapterName); } else { EngineLogger.error( "ERROR LOADING CHAPTER: " + chapterName + EngineAssetManager.CHAPTER_EXT + " doesn't exists."); dispose(); throw new IOException( "ERROR LOADING CHAPTER: " + chapterName + EngineAssetManager.CHAPTER_EXT + " doesn't exists."); } EngineLogger.debug("MODEL LOADING TIME (ms): " + (System.currentTimeMillis() - initTime)); }
From source file:com.bladecoder.engine.model.World.java
License:Apache License
public void loadGameState(FileHandle savedFile) throws IOException { EngineLogger.debug("LOADING GAME STATE"); if (!disposed) dispose();/* w w w .java 2 s . c o m*/ init(); if (savedFile.exists()) { SerializationHelper.getInstance().setMode(Mode.STATE); JsonValue root = new JsonReader().parse(savedFile.reader("UTF-8")); Json json = new Json(); json.setIgnoreUnknownFields(true); read(json, root); assetState = AssetState.LOAD_ASSETS; } else { throw new IOException("LOADGAMESTATE: no saved game exists"); } }
From source file:com.github.fauu.helix.manager.AreaManager.java
License:Open Source License
public void loadFromFile(FileHandle file, String name) { Json json = new Json(); json.setIgnoreUnknownFields(true); AreaWrapper areaWrapper = json.fromJson(AreaWrapper.class, file); Tile[][] tiles = new Tile[areaWrapper.length][areaWrapper.width]; int i = 0;/*from w w w .j a v a2 s . co m*/ for (TileWrapper wrapper : areaWrapper.tiles) { Tile tile = new Tile(); tile.setPermissions(wrapper.permissions); if (wrapper.passage != null) { TileAreaPassage areaPassage = new TileAreaPassage(); areaPassage.setTargetAreaName(wrapper.passage.area); areaPassage.setTargetCoords(new IntVector2(wrapper.passage.position.x, wrapper.passage.position.y)); tile.setAreaPassage(areaPassage); } tiles[i / areaWrapper.width][i % areaWrapper.width] = tile; i++; } String modelPath = "model/" + name + ".g3db"; assetManager.load(modelPath, Model.class); assetManager.finishLoading(); Model model = assetManager.get(modelPath, Model.class); for (Material m : model.materials) { m.set(new FloatAttribute(FloatAttribute.AlphaTest, 0.1f)); } Entity area = world.createEntity().edit().add(new AreaTypeComponent(areaWrapper.type)) .add(new TilesComponent(tiles)) .add(new DimensionsComponent(new IntVector2(areaWrapper.width, areaWrapper.length))) .add(new NameComponent(name)).add(new DisplayableComponent(new AreaDisplayable(model))) .add(new VisibilityComponent()).getEntity(); world.getManager(TagManager.class).register("area", area); this.area = area; }
From source file:com.kotcrab.vis.editor.module.editor.DonateReminderModule.java
License:Apache License
@Override public void init() { FileHandle storage = fileAccess.getMetadataFolder(); FileHandle storageFile = storage.child("donateReminder.json"); Json json = new Json(); json.setIgnoreUnknownFields(true); json.addClassTag("EditorRunCounter", EditorRunCounter.class); EditorRunCounter runCounter;//from w w w . j a v a2s . c o m try { if (storageFile.exists()) { runCounter = json.fromJson(EditorRunCounter.class, storageFile); } else runCounter = new EditorRunCounter(); } catch (SerializationException ignored) { runCounter = new EditorRunCounter(); } runCounter.counter++; if (runCounter.counter % 50 == 0) { VisTable table = new VisTable(true); table.add("If you like VisEditor please consider").spaceRight(3); table.add(new LinkLabel("donating.", DONATE_URL)); LinkLabel hide = new LinkLabel("Hide"); table.add(hide); menuBar.setUpdateInfoTableContent(table); hide.setListener(labelUrl -> menuBar.setUpdateInfoTableContent(null)); } json.toJson(runCounter, storageFile); }
From source file:com.o2d.pkayjava.editor.proxy.ProjectManager.java
License:Apache License
public void openProjectAndLoadAllData(String projectName, String resolution) { String projectPath = currentWorkingPath + "/" + projectName; String prjFilePath = projectPath + "/project.pit"; PreferencesManager prefs = PreferencesManager.getInstance(); prefs.buildRecentHistory();//from w w w. j a v a2 s . com prefs.pushHistory(prjFilePath); facade.sendNotification(Overlap2DMenuBar.RECENT_LIST_MODIFIED); File prjFile = new File(prjFilePath); if (prjFile.exists() && !prjFile.isDirectory()) { FileHandle projectFile = Gdx.files.internal(prjFilePath); String projectContents = null; try { projectContents = FileUtils.readFileToString(projectFile.file()); Json json = new Json(); json.setIgnoreUnknownFields(true); ProjectVO vo = json.fromJson(ProjectVO.class, projectContents); goThroughVersionMigrationProtocol(projectPath, vo); currentProjectVO = vo; String prjInfoFilePath = projectPath + "/project.dt"; FileHandle projectInfoFile = Gdx.files.internal(prjInfoFilePath); String projectInfoContents = FileUtils.readFileToString(projectInfoFile.file()); ProjectInfoVO voInfo = json.fromJson(ProjectInfoVO.class, projectInfoContents); currentProjectInfoVO = voInfo; } catch (IOException e) { e.printStackTrace(); } ResolutionManager resolutionManager = facade.retrieveProxy(ResolutionManager.NAME); if (resolution == null) { resolutionManager.currentResolutionName = currentProjectVO.lastOpenResolution.isEmpty() ? "orig" : currentProjectVO.lastOpenResolution; } else { resolutionManager.currentResolutionName = resolution; currentProjectVO.lastOpenResolution = resolutionManager.currentResolutionName; saveCurrentProject(); } checkForConsistancy(); loadProjectData(projectName); } }
From source file:com.o2d.pkayjava.editor.proxy.ProjectManager.java
License:Apache License
private void checkForConsistancy() { // check if current project requires cleanup // Cleanup unused meshes // 1. open all scenes make list of mesh_id's and then remove all unused meshes HashSet<String> uniqueMeshIds = new HashSet<String>(); FileHandle sourceDir = new FileHandle(currentWorkingPath + "/" + currentProjectVO.projectName + "/scenes/"); for (FileHandle entry : sourceDir.list(Overlap2DUtils.DT_FILTER)) { if (!entry.file().isDirectory()) { Json json = new Json(); json.setIgnoreUnknownFields(true); SceneVO sceneVO = json.fromJson(SceneVO.class, entry); if (sceneVO.composite == null) continue; ArrayList<MainItemVO> items = sceneVO.composite.getAllItems(); for (CompositeItemVO libraryItem : currentProjectInfoVO.libraryItems.values()) { if (libraryItem.composite == null) continue; items = libraryItem.composite.getAllItems(); }//from w w w . ja v a 2s . c o m } } }
From source file:com.uwsoft.editor.proxy.ProjectManager.java
License:Apache License
public void openProjectAndLoadAllData(String projectName, String resolution) { String projectPath = currentWorkingPath + "/" + projectName; String prjFilePath = projectPath + "/project.pit"; PreferencesManager prefs = PreferencesManager.getInstance(); prefs.buildRecentHistory();//from w ww .jav a2s .co m prefs.pushHistory(prjFilePath); facade.sendNotification(Overlap2DMenuBar.RECENT_LIST_MODIFIED); File prjFile = new File(prjFilePath); if (prjFile.exists() && !prjFile.isDirectory()) { FileHandle projectFile = Gdx.files.internal(prjFilePath); String projectContents = null; try { projectContents = FileUtils.readFileToString(projectFile.file()); Json json = new Json(); ProjectVO vo = json.fromJson(ProjectVO.class, projectContents); goThroughVersionMigrationProtocol(projectPath, vo); json.setIgnoreUnknownFields(true); currentProjectVO = vo; String prjInfoFilePath = projectPath + "/project.dt"; FileHandle projectInfoFile = Gdx.files.internal(prjInfoFilePath); String projectInfoContents = FileUtils.readFileToString(projectInfoFile.file()); ProjectInfoVO voInfo = json.fromJson(ProjectInfoVO.class, projectInfoContents); currentProjectInfoVO = voInfo; } catch (IOException e) { e.printStackTrace(); } ResolutionManager resolutionManager = facade.retrieveProxy(ResolutionManager.NAME); if (resolution == null) { resolutionManager.currentResolutionName = currentProjectVO.lastOpenResolution.isEmpty() ? "orig" : currentProjectVO.lastOpenResolution; } else { resolutionManager.currentResolutionName = resolution; currentProjectVO.lastOpenResolution = resolutionManager.currentResolutionName; saveCurrentProject(); } checkForConsistancy(); loadProjectData(projectName); } }
From source file:net.mwplay.cocostudio.ui.CocoStudioUIEditor.java
License:Apache License
/** * @param jsonFile ui??json/*from ww w . ja va2 s .c om*/ * @param textureAtlas ?, null??. * @param ttfs ? * @param bitmapFonts ? * @param defaultFont ttf */ public CocoStudioUIEditor(FileHandle jsonFile, Map<String, FileHandle> ttfs, Map<String, BitmapFont> bitmapFonts, FileHandle defaultFont, Collection<TextureAtlas> textureAtlas) { this.textureAtlas = textureAtlas; this.ttfs = ttfs; this.bitmapFonts = bitmapFonts; this.defaultFont = defaultFont; parsers = new HashMap<>(); addParser(new CCButton()); addParser(new CCCheckBox()); addParser(new CCImageView()); addParser(new CCLabel()); addParser(new CCLabelBMFont()); addParser(new CCPanel()); addParser(new CCScrollView()); addParser(new CCTextField()); addParser(new CCLoadingBar()); addParser(new CCTextAtlas()); addParser(new CCLayer()); addParser(new CCLabelAtlas()); addParser(new CCSpriteView()); addParser(new CCNode()); addParser(new CCSlider()); addParser(new CCParticle()); addParser(new CCProjectNode()); addParser(new CCPageView()); addParser(new CCTImageView()); actors = new HashMap<String, Array<Actor>>(); actionActors = new HashMap<Integer, Actor>(); //animations = new HashMap<String, Map<Actor, Action>>(); actorActionMap = new HashMap<Actor, Action>(); dirName = jsonFile.parent().toString(); if (!dirName.equals("")) { dirName += File.separator; } String json = jsonFile.readString("utf-8"); Json jj = new Json(); jj.setIgnoreUnknownFields(true); export = jj.fromJson(CCExport.class, json); }
From source file:net.mwplay.cocostudio.ui.CocoStudioUIEditor.java
License:Apache License
public static List<String> getResources(FileHandle jsonFile) { dirName = jsonFile.parent().toString(); if (!dirName.equals("")) { dirName += File.separator; }//from www . j a va 2 s . co m String json = jsonFile.readString("utf-8"); Json jj = new Json(); jj.setIgnoreUnknownFields(true); CCExport export = jj.fromJson(CCExport.class, json); return export.getContent().getContent().getUsedResources(); }