Skip to content

Commit c51d011

Browse files
committed
added autoclean cache of edited objects.
1 parent d41db98 commit c51d011

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

src/main/java/com/ss/editor/ui/component/editor/impl/AbstractFileEditor.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
import static com.ss.rlib.util.ObjectUtils.notNull;
44
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
5+
6+
import com.jme3.asset.AssetKey;
7+
import com.jme3.asset.ModelKey;
58
import com.jme3.math.Vector3f;
9+
import com.jme3.scene.Spatial;
610
import com.ss.editor.JmeApplication;
711
import com.ss.editor.Messages;
812
import com.ss.editor.analytics.google.GAEvent;
@@ -20,6 +24,7 @@
2024
import com.ss.editor.ui.event.impl.FileChangedEvent;
2125
import com.ss.editor.ui.util.DynamicIconSupport;
2226
import com.ss.editor.ui.util.UiUtils;
27+
import com.ss.editor.util.EditorUtil;
2328
import com.ss.rlib.logging.Logger;
2429
import com.ss.rlib.logging.LoggerManager;
2530
import com.ss.rlib.ui.util.FXUtils;
@@ -383,6 +388,23 @@ public void save(@Nullable final Consumer<@NotNull FileEditor> callback) {
383388
*/
384389
@BackgroundThread
385390
protected void doSave(@NotNull final Path toStore) throws IOException {
391+
392+
final Path assetFile = notNull(EditorUtil.getAssetFile(getEditFile()));
393+
final String assetPath = EditorUtil.toAssetPath(assetFile);
394+
395+
EditorUtil.getAssetManager()
396+
.deleteFromCache(getFileKey(assetPath));
397+
}
398+
399+
/**
400+
* Get an asset key to remove cache of this file.
401+
*
402+
* @param assetPath the asset path.
403+
* @return the asset key.
404+
*/
405+
@FromAnyThread
406+
protected @NotNull AssetKey<?> getFileKey(@NotNull final String assetPath) {
407+
return new ModelKey(assetPath);
386408
}
387409

388410
/**

src/main/java/com/ss/editor/ui/component/editor/impl/material/MaterialFileEditor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import static com.ss.editor.util.EditorUtil.toAssetPath;
88
import static com.ss.editor.util.MaterialUtils.updateMaterialIdNeed;
99
import static com.ss.rlib.util.ObjectUtils.notNull;
10+
11+
import com.jme3.asset.AssetKey;
1012
import com.jme3.asset.AssetManager;
1113
import com.jme3.asset.MaterialKey;
1214
import com.jme3.asset.TextureKey;
@@ -132,6 +134,12 @@ public void doSave(@NotNull final Path toStore) throws IOException {
132134
}
133135
}
134136

137+
@Override
138+
@FromAnyThread
139+
protected @NotNull AssetKey<?> getFileKey(@NotNull final String assetPath) {
140+
return new MaterialKey(assetPath);
141+
}
142+
135143
@Override
136144
@FxThread
137145
protected void handleExternalChanges() {

src/main/java/com/ss/editor/ui/component/editor/impl/scene/AbstractSceneFileEditor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import static com.ss.rlib.util.ClassUtils.unsafeCast;
99
import static com.ss.rlib.util.ObjectUtils.notNull;
1010
import static javafx.collections.FXCollections.observableArrayList;
11+
12+
import com.jme3.asset.AssetKey;
1113
import com.jme3.asset.AssetManager;
1214
import com.jme3.asset.MaterialKey;
1315
import com.jme3.asset.ModelKey;
@@ -939,6 +941,12 @@ public void doSave(@NotNull final Path toStore) throws IOException {
939941
}
940942
}
941943

944+
@Override
945+
@FromAnyThread
946+
protected @NotNull AssetKey<?> getFileKey(@NotNull final String assetPath) {
947+
return new ModelKey(assetPath);
948+
}
949+
942950
@Override
943951
@FxThread
944952
protected boolean needToolbar() {

src/main/java/com/ss/editor/ui/component/log/OutputStreamWrapper.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ public class OutputStreamWrapper extends PrintStream {
1616
@NotNull
1717
private final Consumer<String> consumer;
1818

19-
/**
20-
* Instantiates a new Output stream wrapper.
21-
*
22-
* @param out the out
23-
* @param consumer the consumer
24-
*/
2519
public OutputStreamWrapper(@NotNull final OutputStream out, @NotNull final Consumer<String> consumer) {
2620
super(out);
2721
this.consumer = consumer;

0 commit comments

Comments
 (0)