Java Code Examples for com.badlogic.gdx.files.FileHandle#writeString()

The following examples show how to use com.badlogic.gdx.files.FileHandle#writeString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProjectController.java    From talos with Apache License 2.0 6 votes vote down vote up
public void saveProject (FileHandle destination) {
    try {
        String data = currentProject.getProjectString();
        destination.writeString(data, false);

        reportProjectFileInterraction(destination);

        TalosMain.Instance().Prefs().putString("lastSave" + currentProject.getExtension(), destination.parent().path());
        TalosMain.Instance().Prefs().flush();

        currentTab.setDirty(false);
        currentTab.setWorthy();
        currentProjectPath = destination.path();
        projectFileName = destination.name();

        if (!currentTab.getFileName().equals(projectFileName)) {
            clearCache(currentTab.getFileName());
            currentTab.setFileName(projectFileName);
            TalosMain.Instance().UIStage().tabbedPane.updateTabTitle(currentTab);
            fileCache.put(projectFileName, data);
        }
    } catch (Exception e) {
        TalosMain.Instance().reportException(e);
    }
}
 
Example 2
Source File: DesktopLauncher.java    From Radix with MIT License 6 votes vote down vote up
public static void main (String[] arg) {
LwjglApplicationConfiguration config;
      FileHandle glConfigFile = new FileHandle("conf/lwjgl.json");
      Gson gson = new GsonBuilder().setPrettyPrinting().create();
      if(!glConfigFile.exists()) {
          config = createDefaultConfig();
          glConfigFile.writeString(gson.toJson(config), false);
      } else {
          try {
              config = gson.fromJson(glConfigFile.readString(), LwjglApplicationConfiguration.class);
          } catch (Exception e) {
              e.printStackTrace();
              System.err.println("Error reading lwjgl config! Using defaults.");
              config = createDefaultConfig();
          }
      }
new LwjglApplication(new RadixClient(), config);
      Gdx.app.setLogLevel(Application.LOG_DEBUG);
  }
 
Example 3
Source File: ProfileManager.java    From Norii with Apache License 2.0 6 votes vote down vote up
public void writeProfileToStorage(String profName, String fileData, boolean overwrite){
    String fullFilename = profName+SAVEGAME_SUFFIX;

    boolean localFileExists = Gdx.files.internal(fullFilename).exists();

    //If we cannot overwrite and the file exists, exit
    if( localFileExists && !overwrite ){
        return;
    }

    FileHandle file =  null;

    if( Gdx.files.isLocalStorageAvailable() ) {
        file = Gdx.files.local(fullFilename);
        file.writeString(fileData, !overwrite);
        
        profilesWithFile.put(profName, file);
    }
}
 
Example 4
Source File: HighScoreManager.java    From FruitCatcher with Apache License 2.0 5 votes vote down vote up
private void persist() {
	FileHandle highScoresFile = Gdx.files.local(SCORES_DATA_FILE);
	
       Json json = new Json();
       String scoresStr = json.toJson(highScores);
       String encScoresStr = Base64Coder.encodeString(scoresStr);
       highScoresFile.writeString(encScoresStr, false);		
}
 
Example 5
Source File: ProfileManagerGDX.java    From Entitas-Java with MIT License 5 votes vote down vote up
@Override
public void persist(P profile) {
    FileHandle profileDataFile = Gdx.files.local(preferencesManager.PROFILE_DATA_FILE);
    Json json = new Json();
    String profileAsText = json.toJson(profile);

    profileAsText = Base64Coder.encodeString(profileAsText);
    profileDataFile.writeString(profileAsText, false);
}
 
Example 6
Source File: Settings.java    From ashley-superjumper with Apache License 2.0 5 votes vote down vote up
public static void save () {
	try {
		FileHandle filehandle = Gdx.files.external(file);
		
		filehandle.writeString(Boolean.toString(soundEnabled)+"\n", false);
		for (int i = 0; i < 5; i++) {
			filehandle.writeString(Integer.toString(highscores[i])+"\n", true);
		}
	} catch (Throwable e) {
	}
}
 
Example 7
Source File: ProjectData.java    From skin-composer with MIT License 5 votes vote down vote up
public void save(FileHandle file) {
    moveImportedFiles(saveFile, file);
    
    if (main.getProjectData().areResourcesRelative()) {
        makeResourcesRelative(file);
    }
    
    saveFile = file;
    putRecentFile(file.path());
    file.writeString(json.prettyPrint(this), false, "UTF8");
    setChangesSaved(true);
}
 
Example 8
Source File: SavedStuff.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
private void loadScore () {
	// Creates correct filename for scores file
	FileHandle handle;
	StringBuilder scoresFileBuilder = new StringBuilder();
	scoresFileBuilder.append(SCORES_STRING);
	scoresFileBuilder.append(String.valueOf(levelNumber));
	if (isFaster) {
		scoresFileBuilder.append(String.valueOf(fasterSpeed));
	} else {
		scoresFileBuilder.append(NO_FAST_STRING);
	}
	scoresFileBuilder.append(FILE_EXT);
	scoresFile = scoresFileBuilder.toString();

	// Checks if scores file exists, creates one if not
	if (Gdx.files.local(scoresFile).exists()) {
		handle = Gdx.files.local(scoresFile);
	} else {
		handle = Gdx.files.local(scoresFile);
		scoreString = Integer.toString(0);
		handle.writeString(scoreString, false);
	}

	scoreString = handle.readString();
	try {
		hiScore = Integer.parseInt(scoreString);
	} catch (NumberFormatException e) {
		hiScore = 0;
	}
}
 
Example 9
Source File: StateManager.java    From FruitCatcher with Apache License 2.0 5 votes vote down vote up
public void persist(GameScreenState gameScreenState, GameState gameState) {
       FileHandle stateDataFile = Gdx.files.local(STATE_DATA_FILE);
       
       StateBundle stBundle = new StateBundle();
       stBundle.gameScreenState = gameScreenState;
       stBundle.gameState = gameState;
       
       Json json = new Json();
       String state = json.toJson(stBundle);
       stateDataFile.writeString(state, false);
       
       //Gdx.app.log("GameScreen", state);
}
 
Example 10
Source File: GLTFExporter.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
private void end(FileHandle file){
	root.bufferViews = binManager.views;
	root.buffers = binManager.flushAllToFiles(file.nameWithoutExtension());
	
	Json json = new Json();
	json.setOutputType(OutputType.json);
	json.setUsePrototypes(true);
	file.writeString(json.prettyPrint(root), false);
	
	reset();
}
 
Example 11
Source File: ProjectController.java    From talos with Apache License 2.0 5 votes vote down vote up
public void exportProject(FileHandle fileHandle) {
    exporthPathCache.put(projectFileName, fileHandle.path());

    String data = currentProject.exportProject();
    fileHandle.writeString(data, false);

    TalosMain.Instance().Prefs().putString("lastExport"+currentProject.getExtension(), fileHandle.parent().path());
    TalosMain.Instance().Prefs().flush();
}
 
Example 12
Source File: SavedStuff.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
public void saveScore (int hiScore) {
	FileHandle handle = Gdx.files.local(scoresFile);
	scoreString = Integer.toString(hiScore);
	handle.writeString(scoreString, false);
}
 
Example 13
Source File: DialogSceneComposerEvents.java    From skin-composer with MIT License 4 votes vote down vote up
public void exportJava(FileHandle saveFile) {
    Main.main.getProjectData().setLastImportExportPath(saveFile.path());
    String java = DialogSceneComposerJavaBuilder.generateJavaFile();
    saveFile.writeString(java, false);
}
 
Example 14
Source File: DialogSceneComposerModel.java    From skin-composer with MIT License 4 votes vote down vote up
public static void saveToJson(FileHandle saveFile) {
    if (!saveFile.extension().toLowerCase(Locale.ROOT).equals("json")) {
        saveFile = saveFile.sibling(saveFile.nameWithoutExtension() + ".json");
    }
    saveFile.writeString(json.prettyPrint(rootActor), false);
}
 
Example 15
Source File: Utils.java    From skin-composer with MIT License 4 votes vote down vote up
public static void writeWarningsToFile(Array<String> warnings, FileHandle file) {
    for (String warning : warnings) {
        String formatted = warning.replaceAll("(?<!\\[)\\[(?!\\[).*?\\]", "") + "\n";
        file.writeString(formatted, true);
    }
}
 
Example 16
Source File: SavedStuff.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
private void loadPreferences () {
	// Loads the preferences saved from the MainMenuScreen.
	String prefString;
	FileHandle prefHandle;
	if (Gdx.files.local(PREFERENCES_FILENAME).exists()) {
		prefHandle = Gdx.files.local(PREFERENCES_FILENAME);
	} else {
		prefHandle = Gdx.files.local(PREFERENCES_FILENAME);
		prefString = DEFAULT_PREF_STRING;
		prefHandle.writeString(prefString, false);
	}
	prefString = prefHandle.readString();

	char one = '1';
	// True if character at string index is '1', false if '0'
	isFaster = (one == prefString.charAt(0));
	isColor = (one == prefString.charAt(1));
	isAnimate = (one == prefString.charAt(2));
	isSound = (one == prefString.charAt(3));
	isOutline = (one == prefString.charAt(4));
	isPermOutline = (one == prefString.charAt(5));
	levelNumber = Character.getNumericValue(prefString.charAt(6));
	fasterSpeed = Character.getNumericValue(prefString.charAt(7));

	if (fasterSpeed == 0) {
		decreaseSpeed = UPDATE_SPEED_DECREASE_ZERO;
	} else if (fasterSpeed == 1) {
		decreaseSpeed = UPDATE_SPEED_DECREASE_ONE;
	} else if (fasterSpeed == 2) {
		decreaseSpeed = UPDATE_SPEED_DECREASE_TWO;
	} else if (fasterSpeed == 3) {
		decreaseSpeed = UPDATE_SPEED_DECREASE_THREE;
	} else if (fasterSpeed == 4) {
		decreaseSpeed = UPDATE_SPEED_DECREASE_FOUR;
	} else if (fasterSpeed == 5) {
		decreaseSpeed = UPDATE_SPEED_DECREASE_FIVE;
	}

	// Initital speed up
	timeToUpdate -= 5 * decreaseSpeed;
}
 
Example 17
Source File: SavedStuff.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
public void loadAllScoresIntoArray () {
	allScores = new int[NUMBER_OF_LEVELS][NUMBER_OF_SPEEDS];
	

	// Creates correct filename for scores file
	FileHandle handle;
	StringBuilder scoresFileBuilder = new StringBuilder();
	
	for(int x = 0; x < NUMBER_OF_LEVELS; x++) {
		for(int y = 0; y < NUMBER_OF_SPEEDS; y++) {
			levelNumber = x;
			fasterSpeed = y;
			if (fasterSpeed == NUMBER_OF_SPEEDS - 1) {
				isFaster = false;
			} else {
				isFaster = true;
			}
			
			scoresFileBuilder.setLength(0);
			scoresFileBuilder.append(SCORES_STRING);
			scoresFileBuilder.append(String.valueOf(levelNumber));
			if (isFaster) {
				scoresFileBuilder.append(String.valueOf(fasterSpeed));
			} else {
				scoresFileBuilder.append(NO_FAST_STRING);
			}
			scoresFileBuilder.append(FILE_EXT);
			scoresFile = scoresFileBuilder.toString();

			// Checks if scores file exists, creates one if not
			if (Gdx.files.local(scoresFile).exists()) {
				handle = Gdx.files.local(scoresFile);
			} else {
				handle = Gdx.files.local(scoresFile);
				scoreString = Integer.toString(0);
				handle.writeString(scoreString, false);
			}

			scoreString = handle.readString();
			try {
				hiScore = Integer.parseInt(scoreString);
			} catch (NumberFormatException e) {
				hiScore = 0;
			}
			allScores[levelNumber][fasterSpeed] = hiScore;
		}
	}	
	loadPreferencesAndScore();
}
 
Example 18
Source File: SavedStuff.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
public void savePreferences () {
	// Creates a string full of preferences.
	StringBuilder stringBuilder = new StringBuilder();
	if (isFaster) {
		stringBuilder.append("1");
	} else {
		stringBuilder.append("0");
	}
	if (isColor) {
		stringBuilder.append("1");
	} else {
		stringBuilder.append("0");
	}
	if (isAnimate) {
		stringBuilder.append("1");
	} else {
		stringBuilder.append("0");
	}
	if (isSound) {
		stringBuilder.append("1");
	} else {
		stringBuilder.append("0");
	}
	if (isOutline) {
		stringBuilder.append("1");
	} else {
		stringBuilder.append("0");
	}
	if (isPermOutline) {
		stringBuilder.append("1");
	} else {
		stringBuilder.append("0");
	}

	String s;
	s = String.valueOf(levelNumber);
	stringBuilder.append(s);
	s = String.valueOf(fasterSpeed);
	stringBuilder.append(s);
	
	String prefString = stringBuilder.toString();
	
	FileHandle handle = Gdx.files.local(PREFERENCES_FILENAME);
	// Saves said preference string.
	handle.writeString(prefString, false);
}
 
Example 19
Source File: PerSpineKeeper.java    From AzurLaneSpineCharacterDecoder with MIT License 4 votes vote down vote up
public boolean TranslateWork() {
    SpineCharacterDecoder decoder = new SpineCharacterDecoder();
    AtlasLoader atlasLoader = new AtlasLoader();
    Map<String, Array<Integer>> atlasInfo = null;
    FileHandle output;
    boolean hasAtlas = false, hasTex = false;
    if (!isAble && !savePath.isDirectory()) return false;
    else {
        if (atlasPath != null) {
            try {
                atlasInfo = atlasLoader.getRegion(atlasPath);
                hasAtlas = true;

                String file_name = atlasPath.nameWithoutExtension().replace(".atlas", "");
                output = Gdx.files.absolute(savePath + "/output/" + file_name + "/" + file_name + ".atlas");
                atlasPath.copyTo(output);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
        if (texPath != null) {
            output = Gdx.files.absolute(savePath + "/output/" + texPath.nameWithoutExtension());
            texPath.copyTo(output);
        }
        if (skelPath!=null){
            String jsonString, path = savePath.path();

            if (hasAtlas)
                jsonString = decoder.decoder(skelPath, atlasInfo,scale);
            else
                jsonString = decoder.decoder(skelPath, null,scale);

            output = Gdx.files.absolute(path + "/output/" + decoder.name + "/" + decoder.name + ".json");
            output.writeString(jsonString, false);

            name = decoder.name;

            if (jsonString != null && jsonString.startsWith("{\"error\""))
                System.out.printf("error to load %s!\n", name);
            System.out.printf("finish:\t%s\nsave at:\n\t%s\n", name,output.path());
        }
    }
    return true;
}
 
Example 20
Source File: MusicEventManager.java    From gdx-soundboard with MIT License 3 votes vote down vote up
/**
 * Save to a file.
 * 
 * @param fileName
 *            The path to the file.
 */
public void save(FileHandle file) {

    final Json json = new Json(JsonWriter.OutputType.json);

    final Container container = new Container(states.values().toArray());

    file.writeString(json.prettyPrint(container), false);
}