1 /* 2 Inochi2D Part extended with layer information 3 4 Copyright © 2020, Inochi2D Project 5 Distributed under the 2-Clause BSD License, see LICENSE file. 6 7 Authors: Luna Nielsen 8 */ 9 module creator.ext.nodes.expart; 10 import inochi2d.core.nodes.part; 11 import inochi2d.core.nodes; 12 import inochi2d.core; 13 import inochi2d.fmt.serialize; 14 import std.stdio : writeln; 15 import inochi2d.math; 16 17 @TypeId("Part") 18 class ExPart : Part { 19 protected: 20 override 21 void serializeSelf(ref InochiSerializer serializer) { 22 super.serializeSelf(serializer); 23 serializer.putKey("psdLayerPath"); 24 serializer.putValue(layerPath); 25 } 26 27 override 28 SerdeException deserializeFromFghj(Fghj data) { 29 auto err = super.deserializeFromFghj(data); 30 if (err) return err; 31 32 if (!data["psdLayerPath"].isEmpty) data["psdLayerPath"].deserializeValue(layerPath); 33 return null; 34 } 35 36 37 public: 38 /** 39 Layer path to match against, should be in the following format: 40 /<layer group>/../<layer> 41 For single layers just the layer name suffices. 42 43 Note that matches will fail if the structure of the PSD changes. 44 */ 45 string layerPath; 46 47 this(Node parent = null) { super(parent); } 48 this(MeshData data, Texture[] textures, Node parent = null) { super(data, textures, parent); } 49 } 50 51 /** 52 Creates a basic ExPart 53 */ 54 ExPart incCreateExPart(Texture tex, Node parent = null, string name = "New Part") { 55 MeshData data = MeshData([ 56 vec2(-(tex.width/2), -(tex.height/2)), 57 vec2(-(tex.width/2), tex.height/2), 58 vec2(tex.width/2, -(tex.height/2)), 59 vec2(tex.width/2, tex.height/2), 60 ], 61 [ 62 vec2(0, 0), 63 vec2(0, 1), 64 vec2(1, 0), 65 vec2(1, 1), 66 ], 67 [ 68 0, 1, 2, 69 2, 1, 3 70 ]); 71 ExPart p = new ExPart(data, [tex], parent); 72 p.name = name; 73 return p; 74 } 75 76 void incRegisterExPart() { 77 inRegisterNodeType!ExPart(); 78 }