Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
serializeToDynamic -> serialize, removed save arguments
Browse files Browse the repository at this point in the history
EspeuteClement committed Jan 24, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 576844c commit 3a6140c
Showing 27 changed files with 75 additions and 78 deletions.
4 changes: 2 additions & 2 deletions hide/Ide.hx
Original file line number Diff line number Diff line change
@@ -1064,7 +1064,7 @@ class Ide {
}

public function savePrefab( file : String, f : hrt.prefab.Prefab ) {
@:privateAccess var content = f.serializeToDynamic();
@:privateAccess var content = f.serialize();
sys.io.File.saveContent(getPath(file), toJSON(content));
}

@@ -1084,7 +1084,7 @@ class Ide {
}
filterRec(prefab);
if( !changed ) return;
@:privateAccess todo.push(function() sys.io.File.saveContent(getPath(path), toJSON(prefab.serializeToDynamic())));
@:privateAccess todo.push(function() sys.io.File.saveContent(getPath(path), toJSON(prefab.serialize())));
});
for( t in todo )
t();
8 changes: 4 additions & 4 deletions hide/comp/CurveEditor.hx
Original file line number Diff line number Diff line change
@@ -747,7 +747,7 @@ class CurveEditor extends hide.comp.Component {
maxLength = c.maxTime;
}

@:privateAccess lastValue = [for (c in curves) c.serializeToDynamic()];
@:privateAccess lastValue = [for (c in curves) c.serialize()];
refresh();
return curves;
}
@@ -1028,14 +1028,14 @@ class CurveEditor extends hide.comp.Component {
}

function beforeChange() {
@:privateAccess lastValue = [for (c in curves) c.serializeToDynamic()];
@:privateAccess lastValue = [for (c in curves) c.serialize()];

for (c in components)
c.beforeChange();
}

function afterChange() {
@:privateAccess var newVal = [for (c in curves) c.serializeToDynamic()];
@:privateAccess var newVal = [for (c in curves) c.serialize()];
var oldVal = lastValue;
undo.change(Custom(function(undo) {
if(undo) {
@@ -1046,7 +1046,7 @@ class CurveEditor extends hide.comp.Component {
for (i in 0...curves.length)
curves[i].load(newVal[i]);
}
@:privateAccess lastValue = [for (c in curves) c.serializeToDynamic()];
@:privateAccess lastValue = [for (c in curves) c.serialize()];
selectedElements = [];
refresh();
onChange(false);
4 changes: 2 additions & 2 deletions hide/comp/SceneEditor.hx
Original file line number Diff line number Diff line change
@@ -2911,14 +2911,14 @@ class SceneEditor {
if(selectedPrefabs == null) return;
if(selectedPrefabs.length == 1) {
var prefab = selectedPrefabs[0];
@:privateAccess view.setClipboard(prefab.serializeToDynamic(), "prefab", { source : view.state.path, name : prefab.name });
@:privateAccess view.setClipboard(prefab.serialize(), "prefab", { source : view.state.path, name : prefab.name });
}
else {
var lib = new hrt.prefab.Prefab(null, null);
for(e in selectedPrefabs) {
lib.children.push(e);
}
@:privateAccess view.setClipboard(lib.serializeToDynamic(), "prefab");
@:privateAccess view.setClipboard(lib.serialize(), "prefab");
}
}

2 changes: 1 addition & 1 deletion hide/comp/cdb/DataFiles.hx
Original file line number Diff line number Diff line change
@@ -298,7 +298,7 @@ class DataFiles {
for( file => pf in prefabs ) {
skip++;
var path = ide.getPath(file);
@:privateAccess var out = ide.toJSON(pf.serializeToDynamic());
@:privateAccess var out = ide.toJSON(pf.serialize());
if( force ) {
var txt = try sys.io.File.getContent(path) catch( e : Dynamic ) null;
if( txt == out ) continue;
7 changes: 3 additions & 4 deletions hide/prefab/EditContext.hx
Original file line number Diff line number Diff line change
@@ -44,11 +44,10 @@ class EditContext {
}

public function makeChanges( p : Prefab, f : Void -> Void ) @:privateAccess {
var current = {};
p.save(current);
var current = p.save();

properties.undo.change(Custom(function(b) {
var old = {}
p.save(old);
var old = p.save();
p.load(current);
current = old;
rebuildProperties();
6 changes: 3 additions & 3 deletions hide/view/FXEditor.hx
Original file line number Diff line number Diff line change
@@ -308,7 +308,7 @@ class FXEditor extends hide.view.FileView {
var viewModes : Array<String>;

override function getDefaultContent() {
@:privateAccess return haxe.io.Bytes.ofString(ide.toJSON(new hrt.prefab.fx.FX(null, null).serializeToDynamic()));
@:privateAccess return haxe.io.Bytes.ofString(ide.toJSON(new hrt.prefab.fx.FX(null, null).serialize()));
}

override function canSave() {
@@ -318,7 +318,7 @@ class FXEditor extends hide.view.FileView {
override function save() {
if( !canSave() )
return;
@:privateAccess var content = ide.toJSON(cast(data, hrt.prefab.Prefab).serializeToDynamic());
@:privateAccess var content = ide.toJSON(cast(data, hrt.prefab.Prefab).serialize());
var newSign = ide.makeSignature(content);
if(newSign != currentSign)
haxe.Timer.delay(saveBackup.bind(content), 0);
@@ -1916,7 +1916,7 @@ class FXEditor extends hide.view.FileView {
class FX2DEditor extends FXEditor {

override function getDefaultContent() {
@:privateAccess return haxe.io.Bytes.ofString(ide.toJSON(new hrt.prefab.fx.FX2D(null, null).save({})));
@:privateAccess return haxe.io.Bytes.ofString(ide.toJSON(new hrt.prefab.fx.FX2D(null, null).save()));
}

static var _2d = FileTree.registerExtension(FX2DEditor, ["fx2d__"], { icon : "sitemap", createNew : "FX 2D" });
2 changes: 1 addition & 1 deletion hide/view/Model.hx
Original file line number Diff line number Diff line change
@@ -150,7 +150,7 @@ class Model extends FileView {
if( !canSave() )
return;
var toSave = root.children[0];
@:privateAccess toSave.save({});
@:privateAccess toSave.save();

save();
}
4 changes: 2 additions & 2 deletions hide/view/Prefab.hx
Original file line number Diff line number Diff line change
@@ -589,7 +589,7 @@ class Prefab extends hide.view.FileView {
}

override function getDefaultContent() {
@:privateAccess return haxe.io.Bytes.ofString(ide.toJSON(new hrt.prefab.Prefab(null, null).serializeToDynamic()));
@:privateAccess return haxe.io.Bytes.ofString(ide.toJSON(new hrt.prefab.Prefab(null, null).serialize()));
}

override function canSave() {
@@ -600,7 +600,7 @@ class Prefab extends hide.view.FileView {
if( !canSave() )
return;

@:privateAccess var content = ide.toJSON(data.serializeToDynamic());
@:privateAccess var content = ide.toJSON(data.serialize());
var newSign = ide.makeSignature(content);
if(newSign != currentSign)
haxe.Timer.delay(saveBackup.bind(content), 0);
4 changes: 2 additions & 2 deletions hrt/prefab/Light.hx
Original file line number Diff line number Diff line change
@@ -105,8 +105,8 @@ class Light extends Object3D {
zNear = 0.02;
}

override function save(to:Dynamic) : Dynamic {
var obj : Dynamic = super.save(to);
override function save() : Dynamic {
var obj : Dynamic = super.save();
if( shadows.mode != None ) {
obj.shadows = Reflect.copy(shadows);
obj.shadows.mode = shadows.mode.getName();
8 changes: 4 additions & 4 deletions hrt/prefab/Material.hx
Original file line number Diff line number Diff line change
@@ -33,8 +33,8 @@ class Material extends Prefab {
this.color = p.color;
}

override function save(obj:Dynamic) : Dynamic {
super.save(obj);
override function save() : Dynamic {
var obj = super.save();
if(color != null && h3d.Vector.fromArray(color).toColor() != 0xffffffff) obj.color = color;
if(mainPassName == "" || mainPassName == null ) Reflect.deleteField(obj, "mainPassName");
return obj;
@@ -248,7 +248,7 @@ class Material extends Prefab {
}

function updateMat() {
var previousMat = this.serializeToDynamic();
var previousMat = this.serialize();
var mat = ctx.scene.findMat(materials, matSelect.val());
if ( mat != null ) {
var previousName = this.name;
@@ -261,7 +261,7 @@ class Material extends Prefab {
this.refMatLib = "";
}

var newMat = this.serializeToDynamic();
var newMat = this.serialize();

ctx.properties.undo.change(Custom(function(undo) {
if( undo ) {
4 changes: 2 additions & 2 deletions hrt/prefab/Model.hx
Original file line number Diff line number Diff line change
@@ -11,9 +11,9 @@ class Model extends Object3D {
super(parent, shared);
}

override function save(to: Dynamic) : Dynamic {
override function save() : Dynamic {
if( retargetIgnore == "" ) retargetIgnore = null;
return super.save(to);
return super.save();
}

override function makeObject(parent3d:h3d.scene.Object):h3d.scene.Object {
21 changes: 8 additions & 13 deletions hrt/prefab/Prefab.hx
Original file line number Diff line number Diff line change
@@ -298,24 +298,19 @@ class Prefab {
Recursively copy this prefab and it's children into a dynamic object, containing
all the serializable properties and the type of the object
**/
function serializeToDynamic() : Dynamic {
var thisClass = Type.getClass(this);
var typeName = getClassTypeName(thisClass);
var dyn : Dynamic = {
type: typeName,
};

save(dyn);
function serialize() : Dynamic {
var ser = save();
ser.type = type;

if (children.length > 0) {
var serChildren = [];
for (child in children) {
serChildren.push(child.serializeToDynamic());
serChildren.push(child.serialize());
}
dyn.children = serChildren;
ser.children = serChildren;
}

return dyn;
return ser;
}

#if editor
@@ -560,8 +555,8 @@ class Prefab {
Save all the properties to the given dynamic object. This is not recursive. Returns the updated dynamic object.
If to is null, a new dynamic object is created automatically and returned by the
**/
function save(to: Dynamic) : Dynamic {
return this.copyToDynamic(to);
function save() : Dynamic {
return this.copyToDynamic({});
}

/**
6 changes: 3 additions & 3 deletions hrt/prefab/Reference.hx
Original file line number Diff line number Diff line change
@@ -18,14 +18,14 @@ class Reference extends Object3D {
}
}

override function save(obj : Dynamic) {
var obj : Dynamic = super.save(obj);
override function save() {
var obj : Dynamic = super.save();
#if editor
if( editMode && refInstance != null ) {
var sheditor = Std.downcast(shared, hide.prefab.ContextShared);
if( sheditor.editor != null ) sheditor.editor.watchIgnoreChanges(source);

var s = refInstance.serializeToDynamic();
var s = refInstance.serialize();
sys.io.File.saveContent(hide.Ide.inst.getPath(source), hide.Ide.inst.toJSON(s));
}
#end
11 changes: 7 additions & 4 deletions hrt/prefab/Unknown.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package hrt.prefab;

// Unknown prefab storage
/**
Allow openning prefabs with a type not found in the project, keeping the data unchanged.
**/
class Unknown extends Prefab {
public var data : Dynamic = null;

@@ -17,7 +19,8 @@ class Unknown extends Prefab {
}
}

override function save(to:Dynamic) {
override function save() {
var to : Dynamic = {};
to.name = name;
for (f in Reflect.fields(data)) {
Reflect.setField(to, f, copyValue(Reflect.getProperty(data, f)));
@@ -36,7 +39,7 @@ class Unknown extends Prefab {
var v:String = v;
return v;
default:
// TODO : oh no
// Fallback hard data copy
return haxe.Json.parse(haxe.Json.stringify(v));
}
default:
@@ -55,7 +58,7 @@ class Unknown extends Prefab {
override function edit( ctx : hide.prefab.EditContext ) {
var props = new hide.Element('
<p>Unknown prefab type : <code>${data.type}</code></p>
<p>This prefab might has been saved in a more recent version of hide (in that case try to update), or this type no longer exists. </p>
<p>This prefab might has been saved in a more recent version of hide (in that case try to update), or this type no longer exists.</p>
<p>No data will be lost if this prefab is saved, but rendering glitches or strange offsets can occur.</p>
');
ctx.properties.add(props, this, function(pname) {
8 changes: 4 additions & 4 deletions hrt/prefab/World.hx
Original file line number Diff line number Diff line change
@@ -165,14 +165,14 @@ class World extends Object3D {
return 0;
}

override function serializeToDynamic() : Dynamic {
override function serialize() : Dynamic {
var tmpChildren = [];

var chunks = new Map();
if ( children.length > 0 ) {
for ( c in children ) {
if ( !isStreamable(c) )
tmpChildren.push(c.serializeToDynamic());
tmpChildren.push(c.serialize());
else {
var object3D = Std.downcast(c, hrt.prefab.Object3D);
if ( object3D == null )
@@ -191,7 +191,7 @@ class World extends Object3D {
chunk.children = [];
chunks.set(data.id, chunk);
}
chunk.children.push(object3D.serializeToDynamic());
chunk.children.push(object3D.serialize());
if ( findChunk(data.id) == null ) {
chunkData.push(data);
}
@@ -233,7 +233,7 @@ class World extends Object3D {
if ( sys.FileSystem.exists(datDir) && sys.FileSystem.readDirectory(datDir).length == 0 )
sys.FileSystem.deleteDirectory(datDir);
#end
var obj : Dynamic = save({});
var obj : Dynamic = save();
obj.children = tmpChildren;
return obj;
}
4 changes: 2 additions & 2 deletions hrt/prefab/fx/Emitter.hx
Original file line number Diff line number Diff line change
@@ -1417,8 +1417,8 @@ class Emitter extends Object3D {
a;
};

override function save(data : Dynamic) {
super.save(data);
override function save() {
var data = super.save();
data.props = Reflect.copy(props);
for(param in PARAMS) {
var f : Dynamic = Reflect.field(props, param.name);
8 changes: 4 additions & 4 deletions hrt/prefab/l3d/Decal.hx
Original file line number Diff line number Diff line change
@@ -31,8 +31,8 @@ class Decal extends Object3D {
@:s var normalFadeEnd : Float = 1;
@:s var refMatLib : String;

override function save(data:Dynamic) : Dynamic {
var obj : Dynamic = super.save(data);
override function save() : Dynamic {
var obj : Dynamic = super.save();
if(blendMode != Alpha) obj.blendMode = blendMode.getIndex();
return obj;
}
@@ -304,7 +304,7 @@ class Decal extends Object3D {
}

function updateMat() {
var previousData = this.serializeToDynamic();
var previousData = this.serialize();
var mat = ctx.scene.findMat(materials, matSelect.val());
if ( mat != null ) {
this.refMatLib = mat.path + "/" + mat.mat.name;
@@ -314,7 +314,7 @@ class Decal extends Object3D {
this.refMatLib = "";
}

var newDecal = this.serializeToDynamic();
var newDecal = this.serialize();

ctx.properties.undo.change(Custom(function(undo) {
if( undo ) {
4 changes: 2 additions & 2 deletions hrt/prefab/l3d/HeightMap.hx
Original file line number Diff line number Diff line change
@@ -626,8 +626,8 @@ class HeightMap extends Object3D {
var albedoProps : Array<h3d.Vector4>;
var texArrayCache : Map<HeightMaPTexturePathKind, { texture : h3d.mat.TextureArray, indexes : Array<Int> }>;

override function save(obj:Dynamic):Dynamic {
var o : Dynamic = super.save(obj);
override function save():Dynamic {
var o : Dynamic = super.save();
o.textures = [for( t in textures ) {
var v : Dynamic = { path : t.path, kind : t.kind };
if( !t.enable ) v.enable = false;
4 changes: 2 additions & 2 deletions hrt/prefab/l3d/Layers2D.hx
Original file line number Diff line number Diff line change
@@ -184,8 +184,8 @@ class Layers2D extends hrt.prefab.Object3D {
#end

#if editor
override function save(obj : Dynamic) : Dynamic {
super.save(obj);
override function save() : Dynamic {
var obj = super.save();

for ( l in layers ) {
var pixels = layerTextures.get(l.name);
Loading

0 comments on commit 3a6140c

Please sign in to comment.