Search in sources :

Example 1 with InvalidUrnException

use of org.terasology.assets.exceptions.InvalidUrnException in project Terasology by MovingBlocks.

the class AbstractEditorScreen method loadAutosave.

/**
 * Resets the editor based on the state of the autosave file.
 */
protected void loadAutosave() {
    if (!disableAutosave) {
        try (JsonReader reader = new JsonReader(new InputStreamReader(Files.newInputStream(getAutosaveFile())))) {
            reader.setLenient(true);
            String autosaveString = new JsonParser().parse(reader).toString();
            JsonObject autosaveObject = new JsonParser().parse(autosaveString).getAsJsonObject();
            String selectedAsset = autosaveObject.get("selectedAsset").getAsString();
            setSelectedAsset(selectedAsset);
            try {
                ResourceUrn urn = new ResourceUrn(selectedAsset);
                setSelectedAssetPath(urn);
            } catch (InvalidUrnException ignored) {
            }
            JsonTree editorContents = JsonTreeConverter.serialize(autosaveObject.get("editorContents"));
            resetState(editorContents);
            setUnsavedChangesPresent(true);
        } catch (NoSuchFileException ignored) {
        } catch (IOException e) {
            logger.warn("Could not load autosaved info", e);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InvalidUrnException(org.terasology.assets.exceptions.InvalidUrnException) JsonTree(org.terasology.rendering.nui.widgets.treeView.JsonTree) NoSuchFileException(java.nio.file.NoSuchFileException) JsonReader(com.google.gson.stream.JsonReader) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) ResourceUrn(org.terasology.assets.ResourceUrn) JsonParser(com.google.gson.JsonParser)

Example 2 with InvalidUrnException

use of org.terasology.assets.exceptions.InvalidUrnException in project Terasology by MovingBlocks.

the class NUIEditorScreen method resetStateInternal.

/**
 * {@inheritDoc}
 */
@Override
protected void resetStateInternal(JsonTree node) {
    getEditor().setTreeViewModel(node, true);
    resetPreviewWidget();
    getEditor().clearHistory();
    updateConfig();
    selectedAsset = selectedAssetPending;
    try {
        ResourceUrn urn = new ResourceUrn(selectedAsset);
        setSelectedAssetPath(urn);
    } catch (InvalidUrnException ignored) {
    }
}
Also used : InvalidUrnException(org.terasology.assets.exceptions.InvalidUrnException) ResourceUrn(org.terasology.assets.ResourceUrn)

Example 3 with InvalidUrnException

use of org.terasology.assets.exceptions.InvalidUrnException in project Terasology by MovingBlocks.

the class NUISkinEditorScreen method resetStateInternal.

/**
 * {@inheritDoc}
 */
@Override
protected void resetStateInternal(JsonTree node) {
    getEditor().setTreeViewModel(node, true);
    resetPreviewWidget();
    getEditor().clearHistory();
    updateConfig();
    selectedAsset = selectedAssetPending;
    try {
        ResourceUrn urn = new ResourceUrn(selectedAsset);
        setSelectedAssetPath(urn);
    } catch (InvalidUrnException ignored) {
    }
}
Also used : InvalidUrnException(org.terasology.assets.exceptions.InvalidUrnException) ResourceUrn(org.terasology.assets.ResourceUrn)

Aggregations

ResourceUrn (org.terasology.assets.ResourceUrn)3 InvalidUrnException (org.terasology.assets.exceptions.InvalidUrnException)3 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JsonReader (com.google.gson.stream.JsonReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 JsonTree (org.terasology.rendering.nui.widgets.treeView.JsonTree)1