package NET.worlds.scape; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; public class TransAttribute extends Attribute { private Point3 defPos; private Point3 defRAxis; private float defRotation; private Point3 defScale; private int _sharingMode = 57344; private static Object classCookie = new Object(); public TransAttribute(int attrID) { super(attrID); } public TransAttribute() { } @Override protected void noteAddingTo(SuperRoot owner) { WObject w = (WObject)((Sharer)owner).getOwner(); w._transformAttribute = this; this.initDefault(); } @Override public void detach() { WObject w = (WObject)((Sharer)this.getOwner()).getOwner(); w._transformAttribute = null; super.detach(); } @Override public void noteChange() { if (!TCompressor.dontSend) { super.noteChange(); } } @Override public void generateNetData(DataOutputStream s) throws IOException { WObject w = (WObject)this.getOwner().getOwner(); if (this._shorthandVersion == 0) { Point3Temp pos = w.getPosition(); s.writeFloat(pos.x); s.writeFloat(pos.y); s.writeFloat(pos.z); Point3Temp scale = w.getScale(); s.writeFloat(scale.x); s.writeFloat(scale.y); s.writeFloat(scale.z); } else { this.initDefault(); TCompressor.compress(w, this.defPos, this.defRAxis, this.defRotation, this.defScale, this._sharingMode, s); } } private void initDefault() { if (this.defPos == null) { WObject w = (WObject)((Sharer)this.getOwner()).getOwner(); this.defPos = new Point3(w.getPosition()); this.defRAxis = new Point3(); this.defRotation = w.getSpin(this.defRAxis); this.defScale = new Point3(w.getScale()); } } @Override public void setFromNetData(DataInputStream ds, int len) throws IOException { WObject w = (WObject)this.getOwner().getOwner(); this.initDefault(); try { TCompressor.decompress(w, this.defPos, this.defRAxis, this.defRotation, this.defScale, this._sharingMode, len, ds); } catch (IOException var5) { TCompressor.dontSend = false; throw var5; } } public boolean getSharingPosition() { return (this._sharingMode & 32768) != 0; } public void setSharingPosition(boolean b) { if (b) { this._sharingMode |= 32768; } else { this._sharingMode &= -32769; } } public boolean getSharingRotation() { return (this._sharingMode & 16384) != 0; } public void setSharingRotation(boolean b) { if (b) { this._sharingMode |= 16384; } else { this._sharingMode &= -16385; } } public boolean getSharingScale() { return (this._sharingMode & 8192) != 0; } public void setSharingScale(boolean b) { if (b) { this._sharingMode |= 8192; } else { this._sharingMode &= -8193; } } @Override public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException { Object ret = null; switch (index - offset) { case 0: if (mode == 0) { ret = BooleanPropertyEditor.make(new Property(this, index, "Share Position"), "No", "Yes"); } else if (mode == 1) { ret = new Boolean(this.getSharingPosition()); } else if (mode == 2) { this.setSharingPosition((Boolean)value); } break; case 1: if (mode == 0) { ret = BooleanPropertyEditor.make(new Property(this, index, "Share Rotation"), "No", "Yes"); } else if (mode == 1) { ret = new Boolean(this.getSharingRotation()); } else if (mode == 2) { this.setSharingRotation((Boolean)value); } break; case 2: if (mode == 0) { ret = BooleanPropertyEditor.make(new Property(this, index, "Share Scale"), "No", "Yes"); } else if (mode == 1) { ret = new Boolean(this.getSharingScale()); } else if (mode == 2) { this.setSharingScale((Boolean)value); } break; default: ret = super.properties(index, offset + 3, mode, value); } return ret; } @Override public void saveState(Saver s) throws IOException { s.saveVersion(2, classCookie); super.saveState(s); this.initDefault(); s.saveInt(this._sharingMode); s.saveFloat(this.defPos.x); s.saveFloat(this.defPos.y); s.saveFloat(this.defPos.z); s.saveFloat(this.defRAxis.x); s.saveFloat(this.defRAxis.y); s.saveFloat(this.defRAxis.z); s.saveFloat(this.defRotation); s.saveFloat(this.defScale.x); s.saveFloat(this.defScale.y); s.saveFloat(this.defScale.z); } @Override public void restoreState(Restorer r) throws IOException, TooNewException { int vers = r.restoreVersion(classCookie); switch (vers) { case 0: super.restoreState(r); break; case 1: case 2: this.defPos = new Point3(); this.defRAxis = new Point3(); this.defScale = new Point3(); super.restoreState(r); this._sharingMode = r.restoreInt(); this.defPos.x = r.restoreFloat(); this.defPos.y = r.restoreFloat(); this.defPos.z = r.restoreFloat(); this.defRAxis.x = r.restoreFloat(); this.defRAxis.y = r.restoreFloat(); this.defRAxis.z = r.restoreFloat(); this.defRotation = r.restoreFloat(); this.defScale.x = r.restoreFloat(); this.defScale.y = r.restoreFloat(); this.defScale.z = r.restoreFloat(); break; default: throw new TooNewException(); } if (vers < 2) { this._shorthandVersion = vers; } } @Override public int getMaxShorthandVersion() { return 1; } }