enigma-dev/lgmplugin — pull request #27 by egofree71 (2014-08-27 08:52:01+00:00)
Title: Adding new instance's properties into the preCreationCode * DO NOT MERGE *

I've added the new property 'preCreationCode' into the Instance class. This property contains all the instructions to modify the scale, rotation and color blending of the instance. For testing purpose i've tested these instructions with creationCode, and it works. But it gives an error message with the new property preCreationCode, i think it is because the ENIGMA engine must be modified in order to take into account the new property. Here is the error message :
Stack trace:
java.lang.Error: Invalid memory access
at com.sun.jna.Native.invokeInt(Native Method)
at com.sun.jna.Function.invoke(Function.java:383)
at com.sun.jna.Function.invoke(Function.java:315)
at com.sun.jna.Library$Handler.invoke(Library.java:212)
at com.sun.proxy.$Proxy0.compileEGMf(Unknown Source)
at org.enigma.EnigmaRunner$CompilerThread.run(EnigmaRunner.java:679)

If Robert or TheExdeus are ok with this pull request, we can merge it. Unfortunately the formatter of ECLIPSE has changed all the code. But here is the new code :

StringBuilder sb = new StringBuilder();

for (org.lateralgm.resources.sub.Instance ii : ri) {
Instance oi = oil[i++];

oi.x = ii.properties.get(PInstance.X);
oi.y = ii.properties.get(PInstance.Y);

// Append the new instance's properties
Point2D scale = ii.getScale();

if (scale.getX() != 1.0)
sb.append("image_xscale="
+ String.valueOf(scale.getX()) + ";\r\n");

if (scale.getY() != 1.0)
sb.append("image_yscale="
+ String.valueOf(scale.getY()) + ";\r\n");

Double rotation = ii.getRotation();

if (rotation > 0.0)
sb.append("image_angle=" + String.valueOf(rotation)
+ ";\r\n");

Color color = ii.getColor();

if (!Color.WHITE.equals(color))
sb.append("image_blend=make_color_rgb("
+ String.valueOf(color.getRed()) + ","
+ String.valueOf(color.getGreen()) + ","
+ String.valueOf(color.getBlue()) + ");"
+ "\r\n");

int alpha = ii.getAlpha();

if (alpha < 255)
sb.append("image_alpha="
+ String.valueOf((float) (alpha / 255.0))
+ ";\r\n");

oi.objectId = toId(ii.properties.get(PInstance.OBJECT), -1);
oi.id = ii.properties.get(PInstance.ID);

if (sb.length() > 0)
oi.preCreationCode = sb.toString();