package org.xtx.ut4converter.t3d;

import org.xtx.ut4converter.MapConverter;
import org.xtx.ut4converter.export.UTPackageExtractor;
import org.xtx.ut4converter.ucore.UPackageRessource;

/**
 * Special event trigger in Unreal Engine 1 (Unreal 1)
 */
public class T3DSpecialEvent extends T3DActor {

    /**
     * Means will be broadcast to all other players
     */
    private Boolean bBroadcast;

    private Boolean bPlayerViewRot;

    private Float damage;

    private String damageString;

    private String damageType;

    private String message;

    private UPackageRessource sound;

    public T3DSpecialEvent(final MapConverter mc, final String t3dClass) {
        super(mc, t3dClass);
    }

    @Override
    public boolean analyseT3DData(String line) {
        if (line.startsWith("bBroadcast=")) {
            this.bBroadcast = T3DUtils.getBoolean(line);
        }
        else if (line.startsWith("bPlayerViewRot=")) {
            this.bBroadcast = T3DUtils.getBoolean(line);
        }
        else if (line.startsWith("Damage=")) {
            this.damage = T3DUtils.getFloat(line);
        }
        else if (line.startsWith("DamageString=")) {
            this.damageString = T3DUtils.getString(line);
        }
        else if (line.startsWith("DamageType=")) {
            this.damageType = T3DUtils.getString(line);
        }
        else if (line.startsWith("Message=")) {
            this.message = T3DUtils.getString(line);
        }
        else if (line.startsWith("Sound=")) {
            this.sound = mapConverter.getUPackageRessource(line.split("\'")[1], T3DRessource.Type.SOUND);
        }

        else {
            return super.analyseT3DData(line);
        }

        return true;
    }

    @Override
    public void convert() {
        if (mapConverter.convertSounds() && sound != null) {
            sound.export(UTPackageExtractor.getExtractor(mapConverter, sound));
        }

        super.convert();
    }

    @Override
    public String toString() {

        sbf.append(IDT).append("Begin Actor Class=Dispatcher_C \n");

        sbf.append(IDT).append("\tBegin Object Class=SceneComponent Name=\"DefaultSceneRoot\"\n");
        sbf.append(IDT).append("\tEnd Object\n");

        sbf.append(IDT).append("\tBegin Object Name=\"DefaultSceneRoot\"\n");
        writeLocRotAndScale();
        sbf.append(IDT).append("\tEnd Object\n");

        sbf.append(IDT).append("\tDefaultSceneRoot=DefaultSceneRoot\n");


        if(bBroadcast != null){
            sbf.append(IDT).append("\tbBroadcast=").append(bBroadcast).append("\n");
        }

        if(bPlayerViewRot != null){
            sbf.append(IDT).append("\tbPlayerViewRot=").append(bPlayerViewRot).append("\n");
        }

        if(damage != null){
            sbf.append(IDT).append("\tDamage=").append(damage).append("\n");
        }

        if(damageString != null){
            sbf.append(IDT).append("\tDamageString=").append(damageString).append("\n");
        }

        if(message != null){
            sbf.append(IDT).append("\tMessage=").append(message).append("\n");
        }

        if(sound != null){
            sbf.append(IDT).append("\tSound=SoundCue'").append(sound.getConvertedName(mapConverter)).append("'\n");
        }

        sbf.append(IDT).append("\tRootComponent=DefaultSceneRoot\n");

        writeEndActor();

        return super.toString();
    }
}

@@ -73,116 +73,8 @@
 ter;
-%0Aimport org.xtx.ut4converter.export.UTPackageExtractor;%0Aimport org.xtx.ut4converter.ucore.UPackageRessource;
 %0A%0A/*
@@ -187,306 +187,8 @@
  %7B%0A%0A
-    /**%0A     * Means will be broadcast to all other players%0A     */%0A    private Boolean bBroadcast;%0A%0A    private Boolean bPlayerViewRot;%0A%0A    private Float damage;%0A%0A    private String damageString;%0A%0A    private String damageType;%0A%0A    private String message;%0A%0A    private UPackageRessource sound;%0A%0A
     
@@ -291,178 +291,82 @@
 s);%0A
+%0A
     
-%7D%0A%0A
     
-@Override%0A    public boolean analyseT3DData(String line) %7B%0A        if (line.startsWith(%22bBroadcast=%22)) %7B%0A            this.bBroadcast = T3DUtils.get
+registerSimpleProperty(%22bBroadcast%22, Boolean.class, 
 Boolean
-(line
+.FALSE
 );%0A 
@@ -376,119 +376,77 @@
     
-%7D%0A        else if (line.startsWith(%22bPlayerViewRot=%22)) %7B%0A            this.bBroadcast = T3DUtils.get
+registerSimpleProperty(%22bPlayerViewRot%22, Boolean.class, 
 Boolean
-(line
+.FALSE
 );%0A 
@@ -456,947 +456,310 @@
     
-%7D%0A        else if (line.startsWith(%22Damage=%22)) %7B%0A            this.damage = T3DUtils.getFloat(line);%0A        %7D%0A        else if (line.startsWith(%22DamageString=%22)) %7B%0A            this.damageString = T3DUtils.getString(line);%0A        %7D%0A        else if (line.startsWith(%22DamageType=%22)) %7B%0A            this.damageType = T3DUtils.getString(line);%0A        %7D%0A        else if (line.startsWith(%22Message=%22)) %7B%0A            this.message = T3DUtils.getString(line);%0A        %7D%0A        else if (line.startsWith(%22Sound=%22)) %7B%0A            this.sound = mapConverter.getUPackageRessource(line.split(%22%5C'%22)%5B1%5D, T3DRessource.Type.SOUND);%0A        %7D%0A%0A        else %7B%0A            return super.analyseT3DData(line);%0A        %7D%0A%0A        return true;%0A    %7D%0A%0A    @Override%0A    public void convert() %7B%0A        if (mapConverter.convertSounds() && sound != null) %7B%0A            sound.export(UTPackageExtractor.getExtractor(mapConverter, sound));%0A        %7D%0A%0A        super.convert(
+registerSimpleProperty(%22Damage%22, Float.class, 0f);%0A        registerSimpleProperty(%22DamageString%22, String.class);%0A        registerSimpleProperty(%22DamageType%22, String.class);%0A        registerSimpleProperty(%22Message%22, String.class);%0A        registerSimplePropertyRessource(%22Sound%22, T3DRessource.Type.SOUND
 );%0A 
@@ -1264,25 +1264,24 @@
 t%5Cn%22);%0A%0A
-%0A
         
 if(bBroa
@@ -1276,789 +1276,32 @@
     
-if(bBroadcast != null)%7B%0A            sbf.append(IDT).append(%22%5CtbBroadcast=%22).append(bBroadcast).append(%22%5Cn%22);%0A        %7D%0A%0A        if(bPlayerViewRot != null)%7B%0A            sbf.append(IDT).append(%22%5CtbPlayerViewRot=%22).append(bPlayerViewRot).append(%22%5Cn%22);%0A        %7D%0A%0A        if(damage != null)%7B%0A            sbf.append(IDT).append(%22%5CtDamage=%22).append(damage).append(%22%5Cn%22);%0A        %7D%0A%0A        if(damageString != null)%7B%0A            sbf.append(IDT).append(%22%5CtDamageString=%22).append(damageString).append(%22%5Cn%22);%0A        %7D%0A%0A        if(message != null)%7B%0A            sbf.append(IDT).append(%22%5CtMessage=%22).append(message).append(%22%5Cn%22);%0A        %7D%0A%0A        if(sound != null)%7B%0A            sbf.append(IDT).append(%22%5CtSound=SoundCue'%22).append(sound.getConvertedName(mapConverter)).append(%22'%5Cn%22);%0A        %7D
+writeSimpleProperties();
 %0A%0A  

Refactor specialevent