public override bool doTool()
 {
     if (changeScale)
     {
         elementReference.setScale(scale);
     }
     if (changePosition)
     {
         elementReference.setPosition(x, y);
     }
     return(true);
 }
Exemplo n.º 2
0
        private void InitPlayerContext()
        {
            var scene = GetChapterTarget(CurrentTarget) as Scene;

            if (scene == null)
            {
                playerContext = new ElementReference("Player", 0, 0, -1);
            }
            else
            {
                var trajectory = scene.getTrajectory();

                var playerPosition = new Vector2(scene.getPositionX(), scene.getPositionY());
                var scale          = scene.getPlayerScale();
                if (trajectory != null)
                {
                    Trajectory.Node pos = scene.getTrajectory().getInitial();
                    playerPosition = new Vector2(pos.getX(), pos.getY());
                    scale          = pos.getScale();
                }

                playerContext = new ElementReference("Player", (int)playerPosition.x, (int)playerPosition.y, scene.getPlayerLayer());
                playerContext.setScale(scale);
            }
        }
Exemplo n.º 3
0
    private void instanceElement <T>(ElementReference context) where T : Element
    {
        if (!ConditionChecker.check(context.getConditions()))
        {
            return;
        }

        if (!contexts.ContainsKey(context))
        {
            ElementReference new_context = new ElementReference(context.getTargetId(), context.getX(), context.getY());
            new_context.setScale(context.getScale());
            contexts.Add(context, new_context);
        }

        context = contexts [context];

        GameObject base_prefab;
        Transform  parent;
        Element    element;

        switch (typeof(T).ToString())
        {
        case "Atrezzo":
            base_prefab = Atrezzo_Prefab;
            parent      = Atrezzos;
            element     = Game.Instance.GameState.getAtrezzo(context.getTargetId());
            break;

        case "NPC":
            base_prefab = Character_Prefab;
            parent      = Characters;
            element     = Game.Instance.GameState.getCharacter(context.getTargetId());
            break;

        case "Item":
            base_prefab = Object_Prefab;
            parent      = Objects;
            element     = Game.Instance.GameState.getObject(context.getTargetId());
            break;

        default:
            return;
        }

        GameObject ret   = GameObject.Instantiate(base_prefab);
        Transform  trans = ret.GetComponent <Transform> ();

        ret.GetComponent <Representable> ().Context = context;
        ret.GetComponent <Representable> ().Element = element;
        trans.SetParent(parent);
    }
        private void performAddElement(int type, string id)
        {
            var elementType = controller.IdentifierSummary.getType(id);

            if (elementType != null)
            {
                ElementReference newElementReference = new ElementReference(id, 50, 50);
                int counter = count(newElementReference);
                getReferencesList(elementType).Add(newElementReference);
                ElementReferenceDataControl erdc = new ElementReferenceDataControl(sceneDataControl, newElementReference, type, counter);
                var defaultPos = sceneDataControl.getDefaultInitialPosition();
                newElementReference.setPosition((int)defaultPos.x, (int)defaultPos.y);
                newElementReference.setScale(sceneDataControl.getElementAppropiateScale(erdc.getReferencedElementDataControl() as DataControlWithResources));
                ElementContainer ec = new ElementContainer(erdc, -1, null);
                lastElementContainer = ec;
                reassignLayerAllReferencesDataControl(insertInOrder(ec, false));
            }
        }
Exemplo n.º 5
0
    public override void ParseElement(XmlElement element)
    {
        XmlNodeList
            resourcess = element.SelectNodes("resources"),
            assets,
            conditions,
            effects,
            postseffects,
            notseffect,
            defaultsinitialsposition = element.SelectNodes("default-initial-position"),
            exits = element.SelectNodes("exits/exit"),
            exitslook,
            nextsscene = element.SelectNodes("next-scene"),
            points,
            objectsrefs    = element.SelectNodes("objects/object-ref"),
            charactersrefs = element.SelectNodes("characters/character-ref"),
            atrezzosrefs   = element.SelectNodes("atrezzo/atrezzo-ref"),
            activesareas   = element.SelectNodes("active-areas/active-area"),
            barriers       = element.SelectNodes("barrier"),
            trajectorys    = element.SelectNodes("trajectory");

        string tmpArgVal;

        string sceneId      = "";
        bool   initialScene = false;
        int    playerLayer  = -1;
        float  playerScale  = 1.0f;

        tmpArgVal = element.GetAttribute("id");
        if (!string.IsNullOrEmpty(tmpArgVal))
        {
            sceneId = tmpArgVal;
        }
        tmpArgVal = element.GetAttribute("start");
        if (!string.IsNullOrEmpty(tmpArgVal))
        {
            initialScene = tmpArgVal.Equals("yes");
        }
        tmpArgVal = element.GetAttribute("playerLayer");
        if (!string.IsNullOrEmpty(tmpArgVal))
        {
            playerLayer = int.Parse(tmpArgVal);
        }
        tmpArgVal = element.GetAttribute("playerScale");
        if (!string.IsNullOrEmpty(tmpArgVal))
        {
            playerScale = float.Parse(tmpArgVal, CultureInfo.InvariantCulture);
        }

        scene = new Scene(sceneId);
        scene.setPlayerLayer(playerLayer);
        scene.setPlayerScale(playerScale);
        if (initialScene)
        {
            chapter.setTargetId(sceneId);
        }

        if (element.SelectSingleNode("name") != null)
        {
            scene.setName(element.SelectSingleNode("name").InnerText);
        }
        if (element.SelectSingleNode("documentation") != null)
        {
            scene.setDocumentation(element.SelectSingleNode("documentation").InnerText);
        }

        foreach (XmlElement el in resourcess)
        {
            currentResources = new ResourcesUni();
            tmpArgVal        = el.GetAttribute("name");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                currentResources.setName(el.GetAttribute(tmpArgVal));
            }

            assets = el.SelectNodes("asset");
            foreach (XmlElement ell in assets)
            {
                string type = "";
                string path = "";

                tmpArgVal = ell.GetAttribute("type");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    type = tmpArgVal;
                }
                tmpArgVal = ell.GetAttribute("uri");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    path = tmpArgVal;
                }
                currentResources.addAsset(type, path);
            }

            conditions = el.SelectNodes("condition");
            foreach (XmlElement ell in conditions)
            {
                currentConditions = new Conditions();
                new ConditionSubParser_(currentConditions, chapter).ParseElement(ell);
                currentResources.setConditions(currentConditions);
            }

            scene.addResources(currentResources);
        }

        foreach (XmlElement el in defaultsinitialsposition)
        {
            int x = int.MinValue, y = int.MinValue;

            tmpArgVal = el.GetAttribute("x");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                x = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("y");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                y = int.Parse(tmpArgVal);
            }

            scene.setDefaultPosition(x, y);
        }

        foreach (XmlElement el in exits)
        {
            int    x = 0, y = 0, width = 0, height = 0;
            bool   rectangular = true;
            int    influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0;
            bool   hasInfluence = false;
            string idTarget = "";
            int    destinyX = int.MinValue, destinyY = int.MinValue;
            int    transitionType = 0, transitionTime = 0;
            bool   notEffects = false;

            tmpArgVal = el.GetAttribute("rectangular");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                rectangular = tmpArgVal.Equals("yes");
            }
            tmpArgVal = el.GetAttribute("x");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                x = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("y");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                y = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("width");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                width = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("height");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                height = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("hasInfluenceArea");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                hasInfluence = tmpArgVal.Equals("yes");
            }
            tmpArgVal = el.GetAttribute("influenceX");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceX = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceY");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceY = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceWidth");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceWidth = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceHeight");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceHeight = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("idTarget");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                idTarget = tmpArgVal;
            }
            tmpArgVal = el.GetAttribute("destinyX");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                destinyX = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("destinyY");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                destinyY = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("transitionType");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                transitionType = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("transitionTime");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                transitionTime = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("not-effects");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                notEffects = tmpArgVal.Equals("yes");
            }

            currentExit = new Exit(rectangular, x, y, width, height);
            currentExit.setNextSceneId(idTarget);
            currentExit.setDestinyX(destinyX);
            currentExit.setDestinyY(destinyY);
            currentExit.setTransitionTime(transitionTime);
            currentExit.setTransitionType(transitionType);
            currentExit.setHasNotEffects(notEffects);
            if (hasInfluence)
            {
                InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight);
                currentExit.setInfluenceArea(influenceArea);
            }

            exitslook = el.SelectNodes("exit-look");
            foreach (XmlElement ell in exitslook)
            {
                currentExitLook = new ExitLook();
                string text       = null;
                string cursorPath = null;
                string soundPath  = null;

                tmpArgVal = ell.GetAttribute("text");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    text = tmpArgVal;
                }
                tmpArgVal = ell.GetAttribute("cursor-path");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    cursorPath = tmpArgVal;
                }
                tmpArgVal = ell.GetAttribute("sound-path");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    soundPath = tmpArgVal;
                }

                currentExitLook.setCursorPath(cursorPath);
                currentExitLook.setExitText(text);
                if (soundPath != null)
                {
                    currentExitLook.setSoundPath(soundPath);
                }
                currentExit.setDefaultExitLook(currentExitLook);
            }

            if (el.SelectSingleNode("documentation") != null)
            {
                currentExit.setDocumentation(el.SelectSingleNode("documentation").InnerText);
            }

            points = el.SelectNodes("point");
            foreach (XmlElement ell in points)
            {
                int x_ = 0;
                int y_ = 0;

                tmpArgVal = ell.GetAttribute("x");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    x_ = int.Parse(tmpArgVal);
                }
                tmpArgVal = ell.GetAttribute("y");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    y_ = int.Parse(tmpArgVal);
                }
                currentPoint = new Vector2(x_, y_);
                currentExit.addPoint(currentPoint);
            }

            conditions = el.SelectNodes("condition");
            foreach (XmlElement ell in conditions)
            {
                currentConditions = new Conditions();
                new ConditionSubParser_(currentConditions, chapter).ParseElement(ell);
                currentExit.setConditions(currentConditions);
            }


            effects = el.SelectNodes("effect");
            foreach (XmlElement ell in effects)
            {
                currentEffects = new Effects();
                new EffectSubParser_(currentEffects, chapter).ParseElement(ell);
                currentExit.setEffects(currentEffects);
            }

            notseffect = el.SelectNodes("not-effect");
            foreach (XmlElement ell in notseffect)
            {
                currentEffects = new Effects();
                new EffectSubParser_(currentEffects, chapter).ParseElement(ell);
                currentExit.setNotEffects(currentEffects);
            }

            postseffects = el.SelectNodes("post-effect");
            foreach (XmlElement ell in postseffects)
            {
                currentEffects = new Effects();
                new EffectSubParser_(currentEffects, chapter).ParseElement(ell);
                currentExit.setPostEffects(currentEffects);
            }


            if (currentExit.getNextScenes().Count > 0)
            {
                foreach (NextScene nextScene in currentExit.getNextScenes())
                {
                    Exit exit = (Exit)currentExit;
                    exit.setNextScenes(new List <NextScene>());
                    exit.setDestinyX(nextScene.getPositionX());
                    exit.setDestinyY(nextScene.getPositionY());
                    exit.setEffects(nextScene.getEffects());
                    exit.setPostEffects(nextScene.getPostEffects());
                    if (exit.getDefaultExitLook() == null)
                    {
                        exit.setDefaultExitLook(nextScene.getExitLook());
                    }
                    else
                    {
                        if (nextScene.getExitLook() != null)
                        {
                            if (nextScene.getExitLook().getExitText() != null &&
                                !nextScene.getExitLook().getExitText().Equals(""))
                            {
                                exit.getDefaultExitLook().setExitText(nextScene.getExitLook().getExitText());
                            }
                            if (nextScene.getExitLook().getCursorPath() != null &&
                                !nextScene.getExitLook().getCursorPath().Equals(""))
                            {
                                exit.getDefaultExitLook().setCursorPath(nextScene.getExitLook().getCursorPath());
                            }
                        }
                    }
                    exit.setHasNotEffects(false);
                    exit.setConditions(nextScene.getConditions());
                    exit.setNextSceneId(nextScene.getTargetId());
                    scene.addExit(exit);
                }
            }
            else
            {
                scene.addExit(currentExit);
            }
        }


        foreach (XmlElement el in nextsscene)
        {
            string idTarget = "";
            int    x = int.MinValue, y = int.MinValue;
            int    transitionType = 0, transitionTime = 0;


            tmpArgVal = el.GetAttribute("idTarget");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                idTarget = tmpArgVal;
            }
            tmpArgVal = el.GetAttribute("x");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                x = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("y");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                y = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("transitionType");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                transitionType = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("transitionTime");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                transitionTime = int.Parse(tmpArgVal);
            }

            currentNextScene = new NextScene(idTarget, x, y);
            currentNextScene.setTransitionType((NextSceneEnumTransitionType)transitionType);
            currentNextScene.setTransitionTime(transitionTime);

            currentNextScene.setExitLook(currentExitLook);


            conditions = el.SelectNodes("condition");
            foreach (XmlElement ell in conditions)
            {
                currentConditions = new Conditions();
                new ConditionSubParser_(currentConditions, chapter).ParseElement(ell);
                currentNextScene.setConditions(currentConditions);
            }

            effects = el.SelectNodes("effect");
            foreach (XmlElement ell in effects)
            {
                currentEffects = new Effects();
                new EffectSubParser_(currentEffects, chapter).ParseElement(ell);
                currentNextScene.setEffects(currentEffects);
            }
            postseffects = el.SelectNodes("post-effect");
            foreach (XmlElement ell in effects)
            {
                currentEffects = new Effects();
                new EffectSubParser_(currentEffects, chapter).ParseElement(ell);
                currentNextScene.setPostEffects(currentEffects);
            }
        }


        foreach (XmlElement el in objectsrefs)
        {
            string idTarget = "";
            int    x = 0, y = 0;
            float  scale = 0;
            int    layer = 0;
            int    influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0;
            bool   hasInfluence = false;

            tmpArgVal = el.GetAttribute("idTarget");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                idTarget = tmpArgVal;
            }
            tmpArgVal = el.GetAttribute("x");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                x = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("y");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                y = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("scale");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                scale = float.Parse(tmpArgVal, CultureInfo.InvariantCulture);
            }
            tmpArgVal = el.GetAttribute("layer");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                layer = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("hasInfluenceArea");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                hasInfluence = tmpArgVal.Equals("yes");
            }
            tmpArgVal = el.GetAttribute("layer");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                layer = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceX");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceX = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceY");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceY = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceWidth");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceWidth = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceHeight");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceHeight = int.Parse(tmpArgVal);
            }

            // This is for maintain the back-compatibility: in previous dtd versions layer has -1 as default value and this is
            // an erroneous value. This reason, if this value is -1, it will be changed to 0. Now in dtd there are not default value
            // for layer
            if (layer == -1)
            {
                layer = 0;
            }

            currentElementReference = new ElementReference(idTarget, x, y, layer);
            if (hasInfluence)
            {
                InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight);
                currentElementReference.setInfluenceArea(influenceArea);
            }
            if (scale > 0.001 || scale < -0.001)
            {
                currentElementReference.setScale(scale);
            }

            if (el.SelectSingleNode("documentation") != null)
            {
                currentElementReference.setDocumentation(el.SelectSingleNode("documentation").InnerText);
            }

            conditions = el.SelectNodes("condition");
            foreach (XmlElement ell in conditions)
            {
                currentConditions = new Conditions();
                new ConditionSubParser_(currentConditions, chapter).ParseElement(ell);
                currentElementReference.setConditions(currentConditions);
            }

            scene.addItemReference(currentElementReference);
        }

        foreach (XmlElement el in charactersrefs)
        {
            string idTarget = "";
            int    x = 0, y = 0;
            float  scale = 0;
            int    layer = 0;
            int    influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0;
            bool   hasInfluence = false;

            tmpArgVal = el.GetAttribute("idTarget");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                idTarget = tmpArgVal;
            }
            tmpArgVal = el.GetAttribute("x");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                x = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("y");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                y = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("scale");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                scale = float.Parse(tmpArgVal, CultureInfo.InvariantCulture);
            }
            tmpArgVal = el.GetAttribute("layer");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                layer = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("hasInfluenceArea");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                hasInfluence = tmpArgVal.Equals("yes");
            }
            tmpArgVal = el.GetAttribute("layer");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                layer = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceX");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceX = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceY");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceY = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceWidth");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceWidth = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceHeight");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceHeight = int.Parse(tmpArgVal);
            }

            // This is for maintain the back-compatibility: in previous dtd versions layer has -1 as default value and this is
            // an erroneous value. This reason, if this value is -1, it will be changed to 0. Now in dtd there are not default value
            // for layer
            if (layer == -1)
            {
                layer = 0;
            }

            currentElementReference = new ElementReference(idTarget, x, y, layer);
            if (hasInfluence)
            {
                InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight);
                currentElementReference.setInfluenceArea(influenceArea);
            }
            if (scale > 0.001 || scale < -0.001)
            {
                currentElementReference.setScale(scale);
            }

            if (el.SelectSingleNode("documentation") != null)
            {
                currentElementReference.setDocumentation(el.SelectSingleNode("documentation").InnerText);
            }

            conditions = el.SelectNodes("condition");
            foreach (XmlElement ell in conditions)
            {
                currentConditions = new Conditions();
                new ConditionSubParser_(currentConditions, chapter).ParseElement(ell);
                currentElementReference.setConditions(currentConditions);
            }

            scene.addCharacterReference(currentElementReference);
        }

        foreach (XmlElement el in atrezzosrefs)
        {
            string idTarget = "";
            int    x = 0, y = 0;
            float  scale = 0;
            int    layer = 0;
            int    influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0;
            bool   hasInfluence = false;

            tmpArgVal = el.GetAttribute("idTarget");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                idTarget = tmpArgVal;
            }
            tmpArgVal = el.GetAttribute("x");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                x = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("y");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                y = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("scale");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                scale = float.Parse(tmpArgVal, CultureInfo.InvariantCulture);
            }
            tmpArgVal = el.GetAttribute("layer");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                layer = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("hasInfluenceArea");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                hasInfluence = tmpArgVal.Equals("yes");
            }
            tmpArgVal = el.GetAttribute("layer");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                layer = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceX");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceX = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceY");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceY = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceWidth");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceWidth = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceHeight");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceHeight = int.Parse(tmpArgVal);
            }


            // This is for maintain the back-compatibility: in previous dtd versions layer has -1 as default value and this is
            // an erroneous value. This reason, if this value is -1, it will be changed to 0. Now in dtd there are not default value
            // for layer
            if (layer == -1)
            {
                layer = 0;
            }

            currentElementReference = new ElementReference(idTarget, x, y, layer);
            if (hasInfluence)
            {
                InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight);
                currentElementReference.setInfluenceArea(influenceArea);
            }
            if (scale > 0.001 || scale < -0.001)
            {
                currentElementReference.setScale(scale);
            }

            if (el.SelectSingleNode("documentation") != null)
            {
                currentElementReference.setDocumentation(el.SelectSingleNode("documentation").InnerText);
            }

            conditions = el.SelectNodes("condition");
            foreach (XmlElement ell in conditions)
            {
                currentConditions = new Conditions();
                new ConditionSubParser_(currentConditions, chapter).ParseElement(ell);
                currentElementReference.setConditions(currentConditions);
            }

            scene.addAtrezzoReference(currentElementReference);
        }

        foreach (XmlElement el in activesareas)
        {
            new ActiveAreaSubParser_(chapter, scene, scene.getActiveAreas().Count).ParseElement(el);
        }

        foreach (XmlElement el in barriers)
        {
            new BarrierSubParser_(chapter, scene, scene.getBarriers().Count).ParseElement(el);
        }

        foreach (XmlElement el in trajectorys)
        {
            new TrajectorySubParser_(chapter, scene).ParseElement(el);
        }



        if (scene != null)
        {
            TrajectoryFixer.fixTrajectory(scene);
        }
        chapter.addScene(scene);
    }
Exemplo n.º 6
0
        //private SlidesceneResource current_resource;

        public void RenderScene()
        {
            switch (sd.getType())
            {
            case GeneralScene.GeneralSceneSceneType.VIDEOSCENE:
                movie       = ResourceManager.Instance.getVideo(((Videoscene)sd).getResources()[0].getAssetPath(Videoscene.RESOURCE_TYPE_VIDEO));
                movieplayer = MovieState.LOADING;
                this.transform.FindChild("Background").localPosition = new Vector3(40, 30, 20);
                break;

            case GeneralScene.GeneralSceneSceneType.SCENE:

                loadParents();

                Scene rsd = (Scene)sd;
                foreach (ResourcesUni sr in rsd.getResources())
                {
                    if (ConditionChecker.check(sr.getConditions()))
                    {
                        Texture2D tmp = ResourceManager.Instance.getImage(sr.getAssetPath(Scene.RESOURCE_TYPE_BACKGROUND));

                        Transform background = this.transform.FindChild("Background");
                        background.GetComponent <Renderer>().material.mainTexture = tmp;
                        float scale = (tmp.width / (tmp.height / 600f)) / 800f;

                        this.transform.position         = new Vector3(40, 30, 20);
                        background.localPosition        = new Vector3(((80 * scale) - 80) / 2f, 0, 20);
                        background.transform.localScale = new Vector3(scale * 80, 60, 1);
                        break;
                    }
                }

                //###################### CHARACTERS ######################
                deleteChilds(Characters);
                foreach (ElementReference context in rsd.getCharacterReferences())
                {
                    instanceElement <NPC>(context);
                }

                //###################### OBJECTS ######################
                deleteChilds(Objects);
                foreach (ElementReference context in rsd.getItemReferences())
                {
                    instanceElement <Item>(context);
                }

                //###################### ATREZZOS ######################
                deleteChilds(Atrezzos);
                foreach (ElementReference context in rsd.getAtrezzoReferences())
                {
                    instanceElement <Atrezzo>(context);
                }

                //###################### ACTIVEAREAS ######################
                deleteChilds(ActiveAreas);

                foreach (ActiveArea ad in rsd.getActiveAreas())
                {
                    if (ConditionChecker.check(ad.getConditions()))
                    {
                        instanceRectangle <ActiveArea>(ad);
                    }
                }

                //###################### EXITS ######################
                deleteChilds(Exits);

                foreach (Exit exit in rsd.getExits())
                {
                    if (exit.isHasNotEffects() || ConditionChecker.check(exit.getConditions()))
                    {
                        instanceRectangle <Exit>(exit);
                    }
                }


                if (!Game.Instance.GameState.isFirstPerson())
                {
                    if (rsd.getTrajectory() == null)
                    {
                        break;
                    }

                    trajectory = new TrajectoryHandler(rsd.getTrajectory());
                    if (player_context == null)
                    {
                        //Vector2 pos = LineHandler.nodeToVector2 (lines [lines.Count-1].end);
                        Trajectory.Node pos = trajectory.getLastNode();
                        player_context = new ElementReference("Player", pos.getX(), pos.getY(), rsd.getPlayerLayer());
                        player_context.setScale(pos.getScale());
                    }
                    /*GameObject.Destroy(this.transform.FindChild ("Player"));*/

                    var player = GameObject.Instantiate(Player_Prefab).GetComponent <PlayerMB>();
                    player.transform.parent = Characters;
                    player.Element          = Game.Instance.GameState.getPlayer();
                    player.Context          = player_context;
                }

                break;

            case GeneralScene.GeneralSceneSceneType.SLIDESCENE:
                Slidescene ssd = (Slidescene)sd;
                foreach (ResourcesUni r in ssd.getResources())
                {
                    if (ConditionChecker.check(r.getConditions()))
                    {
                        this.slides = ResourceManager.Instance.getAnimation(r.getAssetPath(Slidescene.RESOURCE_TYPE_SLIDES));
                        this.transform.FindChild("Background").GetComponent <Renderer>().material.mainTexture = this.slides.frames[0].Image;
                        this.transform.position = new Vector3(40, 30, 20);
                        break;
                    }
                }
                break;
            }
        }
Exemplo n.º 7
0
    //private SlidesceneResource current_resource;

    public void renderScene()
    {
        ElementReference auxEleRef;

        switch (sd.getType())
        {
        case GeneralScene.GeneralSceneSceneType.VIDEOSCENE:
            StartCoroutine(loadMovie());
            this.transform.FindChild("Background").localPosition = new Vector3(40, 30, 20);
            break;

        case GeneralScene.GeneralSceneSceneType.SCENE:
            Scene rsd = (Scene)sd;
            foreach (ResourcesUni sr in rsd.getResources())
            {
                if (ConditionChecker.check(sr.getConditions()))
                {
                    Texture2DHolder th  = new Texture2DHolder(sr.getAssetPath(Scene.RESOURCE_TYPE_BACKGROUND));
                    Texture2D       tmp = th.Texture;

                    Transform background = this.transform.FindChild("Background");
                    background.GetComponent <Renderer> ().material.mainTexture = tmp;
                    float scale = (tmp.width / (tmp.height / 600f)) / 800f;

                    this.transform.position         = new Vector3(40, 30, 20);
                    background.localPosition        = new Vector3(((80 * scale) - 80) / 2f, 0, 20);
                    background.transform.localScale = new Vector3(scale * 80, 60, 1);
                    break;
                }
            }

            Transform characters = this.transform.FindChild("Characters");
            foreach (Transform child in characters)
            {
                GameObject.Destroy(child.gameObject);
            }

            foreach (ElementReference cr in rsd.getCharacterReferences())
            {
                if (ConditionChecker.check(cr.getConditions()))
                {
                    GameObject ret   = GameObject.Instantiate(Character_Prefab);
                    Transform  trans = ret.GetComponent <Transform> ();
                    ret.GetComponent <CharacterMB> ().context  = cr;
                    ret.GetComponent <CharacterMB> ().charData = Game.Instance.getCharacter(cr.getTargetId());
                    trans.SetParent(characters);
                }
            }

            Transform objects = this.transform.FindChild("Objects");
            foreach (Transform child in objects)
            {
                GameObject.Destroy(child.gameObject);
            }

            List <ElementReference> items = rsd.getItemReferences();

            ElementReference tmpElement;
            foreach (ElementReference ir in rsd.getItemReferences())
            {
                if (ConditionChecker.check(ir.getConditions()))
                {
                    if (!contexts.ContainsKey(ir))
                    {
                        tmpElement = new ElementReference(ir.getTargetId(), ir.getX(), ir.getY());
                        tmpElement.setScale(ir.getScale());
                        contexts.Add(ir, tmpElement);
                    }

                    GameObject ret   = GameObject.Instantiate(Object_Prefab);
                    Transform  trans = ret.GetComponent <Transform> ();
                    ret.GetComponent <ObjectMB> ().context = contexts[ir];
                    ret.GetComponent <ObjectMB> ().objData = Game.Instance.getObject(ir.getTargetId());
                    trans.SetParent(objects);
                }
            }

            Transform atrezzos = this.transform.FindChild("Atrezzos");
            foreach (Transform child in atrezzos)
            {
                GameObject.Destroy(child.gameObject);
            }

            foreach (ElementReference ir in rsd.getAtrezzoReferences())
            {
                if (ConditionChecker.check(ir.getConditions()))
                {
                    GameObject ret   = GameObject.Instantiate(Atrezzo_Prefab);
                    Transform  trans = ret.GetComponent <Transform> ();
                    ret.GetComponent <AtrezzoMB> ().context = ir;
                    ret.GetComponent <AtrezzoMB> ().atrData = Game.Instance.getAtrezzo(ir.getTargetId());
                    trans.SetParent(atrezzos);
                }
            }

            Transform activeareas = this.transform.FindChild("ActiveAreas");
            foreach (Transform child in activeareas)
            {
                GameObject.Destroy(child.gameObject);
            }

            foreach (ActiveArea ad in rsd.getActiveAreas())
            {
                if (ConditionChecker.check(ad.getConditions()))
                {
                    GameObject ret   = GameObject.Instantiate(ActiveArea_Prefab);
                    Transform  trans = ret.GetComponent <Transform> ();
                    ret.GetComponent <ActiveAreaMB> ().aaData = ad;
                    trans.localScale = new Vector3(ad.getWidth() / 10f, ad.getHeight() / 10f, 1);
                    Vector2 tmppos = new Vector2(ad.getX(), ad.getY()) / 10 + (new Vector2(trans.localScale.x, trans.localScale.y)) / 2;

                    trans.localPosition = new Vector2(tmppos.x, 60 - tmppos.y);
                    trans.SetParent(activeareas);
                }
            }

            Transform exits = this.transform.FindChild("Exits");
            foreach (Transform child in exits)
            {
                GameObject.Destroy(child.gameObject);
            }

            foreach (Exit ed in rsd.getExits())
            {
                if (ed.isHasNotEffects() || ConditionChecker.check(ed.getConditions()))
                {
                    GameObject ret   = GameObject.Instantiate(Exit_Prefab);
                    Transform  trans = ret.GetComponent <Transform> ();
                    ret.GetComponent <ExitMB> ().exitData = ed;
                    trans.localScale = new Vector3(ed.getWidth() / 10f, ed.getHeight() / 10f, 1);
                    Vector2 tmppos = new Vector2(ed.getX(), ed.getY()) / 10 + (new Vector2(trans.localScale.x, trans.localScale.y)) / 2;

                    trans.localPosition = new Vector2(tmppos.x, 60 - tmppos.y);
                    trans.SetParent(exits);
                }
            }

            if (!Game.Instance.isFirstPerson())
            {
                lines = new List <LineHandler> ();
                foreach (Trajectory.Side side in rsd.getTrajectory().getSides())
                {
                    lines.Add(new LineHandler(rsd.getTrajectory().getNodeForId(side.getIDStart())
                                              , rsd.getTrajectory().getNodeForId(side.getIDEnd())
                                              , side));
                }
                updateNeighbours();

                if (player_context == null)
                {
                    //Vector2 pos = LineHandler.nodeToVector2 (lines [lines.Count-1].end);
                    Trajectory.Node pos = lines [lines.Count - 1].end;
                    player_context = new ElementReference("Player", pos.getX(), pos.getY(), rsd.getPlayerLayer());
                    player_context.setScale(pos.getScale());
                }
                /*GameObject.Destroy(this.transform.FindChild ("Player"));*/

                player = GameObject.Instantiate(Player_Prefab).GetComponent <PlayerMB>();
                player.transform.parent = characters;
                player.playerData       = Game.Instance.getPlayer();
                player.context          = player_context;
            }

            break;

        case GeneralScene.GeneralSceneSceneType.SLIDESCENE:
            Slidescene ssd = (Slidescene)sd;
            foreach (ResourcesUni r in ssd.getResources())
            {
                if (ConditionChecker.check(r.getConditions()))
                {
                    this.slides = new eAnim(r.getAssetPath(Slidescene.RESOURCE_TYPE_SLIDES));
                    this.transform.FindChild("Background").GetComponent <Renderer> ().material.mainTexture = this.slides.frames[0].Image;
                    this.transform.position = new Vector3(40, 30, 20);
                    break;
                }
            }
            break;
        }
    }
Exemplo n.º 8
0
    /*
     * (non-Javadoc)
     *
     * @see es.eucm.eadventure.engine.cargador.subparsers.SubParser#startElement(java.lang.string, java.lang.string,
     *      java.lang.string, org.xml.sax.Attributes)
     */
    public override void startElement(string namespaceURI, string sName, string qName, Dictionary <string, string> attrs)
    {
        Debug.Log("START: " + sName + " " + qName + " sub:" + subParsing + ", reading: " + reading);
        // If no element is being parsed
        if (subParsing == SUBPARSING_NONE)
        {
            // If it is a scene tag, create a new scene with its id
            if (qName.Equals("scene"))
            {
                string sceneId      = "";
                bool   initialScene = false;
                int    playerLayer  = -1;
                float  playerScale  = 1.0f;

                foreach (KeyValuePair <string, string> entry in attrs)
                {
                    if (entry.Key.Equals("id"))
                    {
                        sceneId = entry.Value.ToString();
                    }
                    if (entry.Key.Equals("start"))
                    {
                        initialScene = entry.Value.ToString().Equals("yes");
                    }
                    if (entry.Key.Equals("playerLayer"))
                    {
                        playerLayer = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("playerScale"))
                    {
                        playerScale = float.Parse(entry.Value.ToString(), CultureInfo.InvariantCulture);
                    }
                }

                scene = new Scene(sceneId);
                scene.setPlayerLayer(playerLayer);
                scene.setPlayerScale(playerScale);
                if (initialScene)
                {
                    chapter.setTargetId(sceneId);
                }
            }

            // If it is a resources tag, create the new resources
            else if (qName.Equals("resources"))
            {
                currentResources = new ResourcesUni();

                foreach (KeyValuePair <string, string> entry in attrs)
                {
                    if (entry.Key.Equals("name"))
                    {
                        currentResources.setName(entry.Value.ToString());
                    }
                }

                reading = READING_RESOURCES;
            }

            // If it is an asset tag, read it and add it to the current resources
            else if (qName.Equals("asset"))
            {
                string type = "";
                string path = "";

                foreach (KeyValuePair <string, string> entry in attrs)
                {
                    if (entry.Key.Equals("type"))
                    {
                        type = entry.Value.ToString();
                    }
                    if (entry.Key.Equals("uri"))
                    {
                        path = entry.Value.ToString();
                    }
                }

                currentResources.addAsset(type, path);
            }

            // If it is a default-initial-position tag, store it in the scene
            else if (qName.Equals("default-initial-position"))
            {
                int x = int.MinValue, y = int.MinValue;

                foreach (KeyValuePair <string, string> entry in attrs)
                {
                    if (entry.Key.Equals("x"))
                    {
                        x = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("y"))
                    {
                        y = int.Parse(entry.Value.ToString());
                    }
                }

                scene.setDefaultPosition(x, y);
            }

            // If it is an exit tag, create the new exit
            else if (qName.Equals("exit"))
            {
                int    x = 0, y = 0, width = 0, height = 0;
                bool   rectangular = true;
                int    influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0;
                bool   hasInfluence = false;
                string idTarget = "";
                int    destinyX = int.MinValue, destinyY = int.MinValue;
                int    transitionType = 0, transitionTime = 0;
                bool   notEffects = false;

                foreach (KeyValuePair <string, string> entry in attrs)
                {
                    if (entry.Key.Equals("rectangular"))
                    {
                        rectangular = entry.Value.ToString().Equals("yes");
                    }
                    if (entry.Key.Equals("x"))
                    {
                        x = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("y"))
                    {
                        y = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("width"))
                    {
                        width = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("height"))
                    {
                        height = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("hasInfluenceArea"))
                    {
                        hasInfluence = entry.Value.ToString().Equals("yes");
                    }
                    if (entry.Key.Equals("influenceX"))
                    {
                        influenceX = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("influenceY"))
                    {
                        influenceY = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("influenceWidth"))
                    {
                        influenceWidth = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("influenceHeight"))
                    {
                        influenceHeight = int.Parse(entry.Value.ToString());
                    }

                    if (entry.Key.Equals("idTarget"))
                    {
                        idTarget = entry.Value.ToString();
                    }
                    if (entry.Key.Equals("destinyX"))
                    {
                        destinyX = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("destinyY"))
                    {
                        destinyY = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("transitionType"))
                    {
                        transitionType = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("transitionTime"))
                    {
                        transitionTime = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("not-effects"))
                    {
                        notEffects = entry.Value.ToString().Equals("yes");
                    }
                }

                currentExit = new Exit(rectangular, x, y, width, height);
                currentExit.setNextSceneId(idTarget);
                currentExit.setDestinyX(destinyX);
                currentExit.setDestinyY(destinyY);
                currentExit.setTransitionTime(transitionTime);
                currentExit.setTransitionType(transitionType);
                currentExit.setHasNotEffects(notEffects);
                if (hasInfluence)
                {
                    InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight);
                    currentExit.setInfluenceArea(influenceArea);
                }
                reading = READING_EXIT;
            }

            else if (qName.Equals("exit-look"))
            {
                currentExitLook = new ExitLook();
                string text       = null;
                string cursorPath = null;
                string soundPath  = null;
                foreach (KeyValuePair <string, string> entry in attrs)
                {
                    if (entry.Key.Equals("text"))
                    {
                        text = entry.Value.ToString();
                    }
                    if (entry.Key.Equals("cursor-path"))
                    {
                        cursorPath = entry.Value.ToString();
                    }
                    if (entry.Key.Equals("sound-path"))
                    {
                        soundPath = entry.Value.ToString();
                    }
                }
                currentExitLook.setCursorPath(cursorPath);
                currentExitLook.setExitText(text);
                if (soundPath != null)
                {
                    currentExitLook.setSoundPath(soundPath);
                }
                //  Debug.Log("311" + currentExitLook.getExitText());
            }

            // If it is a next-scene tag, create the new next scene
            else if (qName.Equals("next-scene"))
            {
                string idTarget = "";
                int    x = int.MinValue, y = int.MinValue;
                int    transitionType = 0, transitionTime = 0;

                foreach (KeyValuePair <string, string> entry in attrs)
                {
                    if (entry.Key.Equals("idTarget"))
                    {
                        idTarget = entry.Value.ToString();
                    }
                    if (entry.Key.Equals("x"))
                    {
                        x = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("y"))
                    {
                        y = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("transitionType"))
                    {
                        transitionType = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("transitionTime"))
                    {
                        transitionTime = int.Parse(entry.Value.ToString());
                    }
                }

                currentNextScene = new NextScene(idTarget, x, y);
                currentNextScene.setTransitionType((NextSceneEnumTransitionType)transitionType);
                currentNextScene.setTransitionTime(transitionTime);
                reading = READING_NEXT_SCENE;
            }

            else if (qName.Equals("point"))
            {
                int x = 0;
                int y = 0;

                foreach (KeyValuePair <string, string> entry in attrs)
                {
                    if (entry.Key.Equals("x"))
                    {
                        x = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("y"))
                    {
                        y = int.Parse(entry.Value.ToString());
                    }
                }

                currentPoint = new Vector2(x, y);
            }

            // If it is a object-ref or character-ref, create the new element reference
            else if (qName.Equals("object-ref") || qName.Equals("character-ref") || qName.Equals("atrezzo-ref"))
            {
                Debug.Log("SceneReference Start");
                string idTarget = "";
                int    x = 0, y = 0;
                float  scale = 0;
                int    layer = 0;
                int    influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0;
                bool   hasInfluence = false;

                foreach (KeyValuePair <string, string> entry in attrs)
                {
                    if (entry.Key.Equals("idTarget"))
                    {
                        idTarget = entry.Value.ToString();
                    }
                    if (entry.Key.Equals("x"))
                    {
                        x = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("y"))
                    {
                        y = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("scale"))
                    {
                        scale = float.Parse(entry.Value.ToString(), CultureInfo.InvariantCulture);
                    }
                    if (entry.Key.Equals("layer"))
                    {
                        layer = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("hasInfluenceArea"))
                    {
                        hasInfluence = entry.Value.ToString().Equals("yes");
                    }
                    if (entry.Key.Equals("influenceX"))
                    {
                        influenceX = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("influenceY"))
                    {
                        influenceY = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("influenceWidth"))
                    {
                        influenceWidth = int.Parse(entry.Value.ToString());
                    }
                    if (entry.Key.Equals("influenceHeight"))
                    {
                        influenceHeight = int.Parse(entry.Value.ToString());
                    }
                }

                // This is for maintain the back-compatibility: in previous dtd versions layer has -1 as default value and this is
                // an erroneous value. This reason, if this value is -1, it will be changed to 0. Now in dtd there are not default value
                // for layer
                if (layer == -1)
                {
                    layer = 0;
                }

                currentElementReference = new ElementReference(idTarget, x, y, layer);
                if (hasInfluence)
                {
                    InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight);
                    currentElementReference.setInfluenceArea(influenceArea);
                }
                if (scale > 0.001 || scale < -0.001)
                {
                    currentElementReference.setScale(scale);
                }
                reading = READING_ELEMENT_REFERENCE;
            }

            // If it is a condition tag, create the new condition, the subparser and switch the state
            else if (qName.Equals("condition"))
            {
                currentConditions = new Conditions();
                subParser         = new ConditionSubParser(currentConditions, chapter);
                subParsing        = SUBPARSING_CONDITION;
            }

            // If it is a effect tag, create the new effect, the subparser and switch the state
            else if (qName.Equals("effect"))
            {
                currentEffects = new Effects();
                subParser      = new EffectSubParser(currentEffects, chapter);
                subParsing     = SUBPARSING_EFFECT;
            }

            // If it is a post-effect tag, create the new effect, the subparser and switch the state
            else if (qName.Equals("post-effect"))
            {
                currentEffects = new Effects();
                subParser      = new EffectSubParser(currentEffects, chapter);
                subParsing     = SUBPARSING_EFFECT;
            }

            // If it is a post-effect tag, create the new effect, the subparser and switch the state
            else if (qName.Equals("not-effect"))
            {
                currentEffects = new Effects();
                subParser      = new EffectSubParser(currentEffects, chapter);
                subParsing     = SUBPARSING_EFFECT;
            }

            // If it is a post-effect tag, create the new effect, the subparser and switch the state
            else if (qName.Equals("active-area"))
            {
                subParsing = SUBPARSING_ACTIVE_AREA;
                subParser  = new ActiveAreaSubParser(chapter, scene, scene.getActiveAreas().Count);
            }

            // If it is a post-effect tag, create the new effect, the subparser and switch the state
            else if (qName.Equals("barrier"))
            {
                subParsing = SUBPARSING_BARRIER;
                subParser  = new BarrierSubParser(chapter, scene, scene.getBarriers().Count);
            }

            else if (qName.Equals("trajectory"))
            {
                subParsing = SUBPARSING_TRAJECTORY;
                subParser  = new TrajectorySubParser(chapter, scene);
            }
        }

        // If it is subparsing an effect or condition, spread the call
        if (subParsing != SUBPARSING_NONE)
        {
            subParser.startElement(namespaceURI, sName, qName, attrs);
        }
    }
Exemplo n.º 9
0
    public override void ParseElement(XmlElement element)
    {
        XmlNodeList
            resourcess = element.SelectNodes("resources"),
            assets,
            conditions,
            effects,
            postseffects,
            notseffect,
            defaultsinitialsposition = element.SelectNodes("default-initial-position"),
            exits = element.SelectNodes("exits/exit"),
            exitslook,
            nextsscene = element.SelectNodes("next-scene"),
            points,
            objectsrefs = element.SelectNodes("objects/object-ref"),
            charactersrefs = element.SelectNodes("characters/character-ref"),
            atrezzosrefs = element.SelectNodes("atrezzo/atrezzo-ref"),
            activesareas = element.SelectNodes("active-areas/active-area"),
            barriers = element.SelectNodes("barrier"),
            trajectorys = element.SelectNodes("trajectory");

        string tmpArgVal;

        string sceneId = "";
        bool initialScene = false;
        int playerLayer = -1;
        float playerScale = 1.0f;

        tmpArgVal = element.GetAttribute("id");
        if (!string.IsNullOrEmpty(tmpArgVal))
        {
            sceneId = tmpArgVal;
        }
        tmpArgVal = element.GetAttribute("start");
        if (!string.IsNullOrEmpty(tmpArgVal))
        {
            initialScene = tmpArgVal.Equals("yes");
        }
        tmpArgVal = element.GetAttribute("playerLayer");
        if (!string.IsNullOrEmpty(tmpArgVal))
        {
            playerLayer = int.Parse(tmpArgVal);
        }
        tmpArgVal = element.GetAttribute("playerScale");
        if (!string.IsNullOrEmpty(tmpArgVal))
        {
            playerScale = float.Parse(tmpArgVal, CultureInfo.InvariantCulture);
        }

        scene = new Scene(sceneId);
        scene.setPlayerLayer(playerLayer);
        scene.setPlayerScale(playerScale);
        if (initialScene)
            chapter.setTargetId(sceneId);

        if (element.SelectSingleNode("name") != null)
            scene.setName(element.SelectSingleNode("name").InnerText);
        if (element.SelectSingleNode("documentation") != null)
            scene.setDocumentation(element.SelectSingleNode("documentation").InnerText);

        foreach (XmlElement el in resourcess)
        {
            currentResources = new ResourcesUni();
            tmpArgVal = el.GetAttribute("name");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                currentResources.setName(el.GetAttribute(tmpArgVal));
            }

            assets = el.SelectNodes("asset");
            foreach (XmlElement ell in assets)
            {
                string type = "";
                string path = "";

                tmpArgVal = ell.GetAttribute("type");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    type = tmpArgVal;
                }
                tmpArgVal = ell.GetAttribute("uri");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    path = tmpArgVal;
                }
                currentResources.addAsset(type, path);
            }

            conditions = el.SelectNodes("condition");
            foreach (XmlElement ell in conditions)
            {
                currentConditions = new Conditions();
                new ConditionSubParser_(currentConditions, chapter).ParseElement(ell);
                currentResources.setConditions(currentConditions);
            }

            scene.addResources(currentResources);
        }

        foreach (XmlElement el in defaultsinitialsposition)
        {
            int x = int.MinValue, y = int.MinValue;

            tmpArgVal = el.GetAttribute("x");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                x = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("y");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                y = int.Parse(tmpArgVal);
            }

            scene.setDefaultPosition(x, y);
        }

        foreach (XmlElement el in exits)
        {
            int x = 0, y = 0, width = 0, height = 0;
            bool rectangular = true;
            int influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0;
            bool hasInfluence = false;
            string idTarget = "";
            int destinyX = int.MinValue, destinyY = int.MinValue;
            int transitionType = 0, transitionTime = 0;
            bool notEffects = false;

            tmpArgVal = el.GetAttribute("rectangular");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                rectangular = tmpArgVal.Equals("yes");
            }
            tmpArgVal = el.GetAttribute("x");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                x = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("y");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                y = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("width");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                width = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("height");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                height = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("hasInfluenceArea");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                hasInfluence = tmpArgVal.Equals("yes");
            }
            tmpArgVal = el.GetAttribute("influenceX");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceX = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceY");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceY = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceWidth");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceWidth = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceHeight");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceHeight = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("idTarget");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                idTarget = tmpArgVal;
            }
            tmpArgVal = el.GetAttribute("destinyX");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                destinyX = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("destinyY");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                destinyY = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("transitionType");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                transitionType = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("transitionTime");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                transitionTime = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("not-effects");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                notEffects = tmpArgVal.Equals("yes");
            }

            currentExit = new Exit(rectangular, x, y, width, height);
            currentExit.setNextSceneId(idTarget);
            currentExit.setDestinyX(destinyX);
            currentExit.setDestinyY(destinyY);
            currentExit.setTransitionTime(transitionTime);
            currentExit.setTransitionType(transitionType);
            currentExit.setHasNotEffects(notEffects);
            if (hasInfluence)
            {
                InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight);
                currentExit.setInfluenceArea(influenceArea);
            }

            exitslook = el.SelectNodes("exit-look");
            foreach (XmlElement ell in exitslook)
            {
                currentExitLook = new ExitLook();
                string text = null;
                string cursorPath = null;
                string soundPath = null;

                tmpArgVal = ell.GetAttribute("text");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    text = tmpArgVal;
                }
                tmpArgVal = ell.GetAttribute("cursor-path");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    cursorPath = tmpArgVal;
                }
                tmpArgVal = ell.GetAttribute("sound-path");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    soundPath = tmpArgVal;
                }

                currentExitLook.setCursorPath(cursorPath);
                currentExitLook.setExitText(text);
                if (soundPath != null)
                {
                    currentExitLook.setSoundPath(soundPath);
                }
                currentExit.setDefaultExitLook(currentExitLook);
            }

            if (el.SelectSingleNode("documentation") != null)
                currentExit.setDocumentation(el.SelectSingleNode("documentation").InnerText);

            points = el.SelectNodes("point");
            foreach (XmlElement ell in points)
            {
                int x_ = 0;
                int y_ = 0;

                tmpArgVal = ell.GetAttribute("x");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    x_ = int.Parse(tmpArgVal);
                }
                tmpArgVal = ell.GetAttribute("y");
                if (!string.IsNullOrEmpty(tmpArgVal))
                {
                    y_ = int.Parse(tmpArgVal);
                }
                currentPoint = new Vector2(x_, y_);
                currentExit.addPoint(currentPoint);
            }

            conditions = el.SelectNodes("condition");
            foreach (XmlElement ell in conditions)
            {
                currentConditions = new Conditions();
                new ConditionSubParser_(currentConditions, chapter).ParseElement(ell);
                currentExit.setConditions(currentConditions);
            }

            effects = el.SelectNodes("effect");
            foreach (XmlElement ell in effects)
            {
                currentEffects = new Effects();
                new EffectSubParser_(currentEffects, chapter).ParseElement(ell);
                currentExit.setEffects(currentEffects);
            }

            notseffect = el.SelectNodes("not-effect");
            foreach (XmlElement ell in notseffect)
            {
                currentEffects = new Effects();
                new EffectSubParser_(currentEffects, chapter).ParseElement(ell);
                currentExit.setNotEffects(currentEffects);
            }

            postseffects = el.SelectNodes("post-effect");
            foreach (XmlElement ell in postseffects)
            {
                currentEffects = new Effects();
                new EffectSubParser_(currentEffects, chapter).ParseElement(ell);
                currentExit.setPostEffects(currentEffects);
            }

            if (currentExit.getNextScenes().Count > 0)
            {
                foreach (NextScene nextScene in currentExit.getNextScenes())
                {

                    Exit exit = (Exit) currentExit;
                    exit.setNextScenes(new List<NextScene>());
                    exit.setDestinyX(nextScene.getPositionX());
                    exit.setDestinyY(nextScene.getPositionY());
                    exit.setEffects(nextScene.getEffects());
                    exit.setPostEffects(nextScene.getPostEffects());
                    if (exit.getDefaultExitLook() == null)
                        exit.setDefaultExitLook(nextScene.getExitLook());
                    else
                    {
                        if (nextScene.getExitLook() != null)
                        {
                            if (nextScene.getExitLook().getExitText() != null &&
                                !nextScene.getExitLook().getExitText().Equals(""))
                                exit.getDefaultExitLook().setExitText(nextScene.getExitLook().getExitText());
                            if (nextScene.getExitLook().getCursorPath() != null &&
                                !nextScene.getExitLook().getCursorPath().Equals(""))
                                exit.getDefaultExitLook().setCursorPath(nextScene.getExitLook().getCursorPath());
                        }
                    }
                    exit.setHasNotEffects(false);
                    exit.setConditions(nextScene.getConditions());
                    exit.setNextSceneId(nextScene.getTargetId());
                    scene.addExit(exit);
                }
            }
            else
            {
                scene.addExit(currentExit);
            }
        }

        foreach (XmlElement el in nextsscene)
        {
            string idTarget = "";
            int x = int.MinValue, y = int.MinValue;
            int transitionType = 0, transitionTime = 0;

            tmpArgVal = el.GetAttribute("idTarget");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                idTarget = tmpArgVal;
            }
            tmpArgVal = el.GetAttribute("x");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                x = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("y");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                y = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("transitionType");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                transitionType = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("transitionTime");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                transitionTime = int.Parse(tmpArgVal);
            }

            currentNextScene = new NextScene(idTarget, x, y);
            currentNextScene.setTransitionType((NextSceneEnumTransitionType) transitionType);
            currentNextScene.setTransitionTime(transitionTime);

            currentNextScene.setExitLook(currentExitLook);

            conditions = el.SelectNodes("condition");
            foreach (XmlElement ell in conditions)
            {
                currentConditions = new Conditions();
                new ConditionSubParser_(currentConditions, chapter).ParseElement(ell);
                currentNextScene.setConditions(currentConditions);
            }

            effects = el.SelectNodes("effect");
            foreach (XmlElement ell in effects)
            {
                currentEffects = new Effects();
                new EffectSubParser_(currentEffects, chapter).ParseElement(ell);
                currentNextScene.setEffects(currentEffects);
            }
            postseffects = el.SelectNodes("post-effect");
            foreach (XmlElement ell in effects)
            {
                currentEffects = new Effects();
                new EffectSubParser_(currentEffects, chapter).ParseElement(ell);
                currentNextScene.setPostEffects(currentEffects);
            }

        }

        foreach (XmlElement el in objectsrefs)
        {
            string idTarget = "";
            int x = 0, y = 0;
            float scale = 0;
            int layer = 0;
            int influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0;
            bool hasInfluence = false;

            tmpArgVal = el.GetAttribute("idTarget");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                idTarget = tmpArgVal;
            }
            tmpArgVal = el.GetAttribute("x");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                x = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("y");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                y = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("scale");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                scale = float.Parse(tmpArgVal, CultureInfo.InvariantCulture);
            }
            tmpArgVal = el.GetAttribute("layer");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                layer = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("hasInfluenceArea");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                hasInfluence = tmpArgVal.Equals("yes");
            }
            tmpArgVal = el.GetAttribute("layer");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                layer = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceX");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceX = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceY");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceY = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceWidth");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceWidth = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceHeight");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceHeight = int.Parse(tmpArgVal);
            }

            // This is for maintain the back-compatibility: in previous dtd versions layer has -1 as default value and this is
            // an erroneous value. This reason, if this value is -1, it will be changed to 0. Now in dtd there are not default value
            // for layer
            if (layer == -1)
                layer = 0;

            currentElementReference = new ElementReference(idTarget, x, y, layer);
            if (hasInfluence)
            {
                InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight);
                currentElementReference.setInfluenceArea(influenceArea);
            }
            if (scale > 0.001 || scale < -0.001)
                currentElementReference.setScale(scale);

            if (el.SelectSingleNode("documentation") != null)
                currentElementReference.setDocumentation(el.SelectSingleNode("documentation").InnerText);

            conditions = el.SelectNodes("condition");
            foreach (XmlElement ell in conditions)
            {
                currentConditions = new Conditions();
                new ConditionSubParser_(currentConditions, chapter).ParseElement(ell);
                currentElementReference.setConditions(currentConditions);
            }

            scene.addItemReference(currentElementReference);
        }

        foreach (XmlElement el in charactersrefs)
        {
            string idTarget = "";
            int x = 0, y = 0;
            float scale = 0;
            int layer = 0;
            int influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0;
            bool hasInfluence = false;

            tmpArgVal = el.GetAttribute("idTarget");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                idTarget = tmpArgVal;
            }
            tmpArgVal = el.GetAttribute("x");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                x = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("y");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                y = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("scale");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                scale = float.Parse(tmpArgVal, CultureInfo.InvariantCulture);
            }
            tmpArgVal = el.GetAttribute("layer");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                layer = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("hasInfluenceArea");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                hasInfluence = tmpArgVal.Equals("yes");
            }
            tmpArgVal = el.GetAttribute("layer");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                layer = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceX");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceX = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceY");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceY = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceWidth");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceWidth = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceHeight");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceHeight = int.Parse(tmpArgVal);
            }

            // This is for maintain the back-compatibility: in previous dtd versions layer has -1 as default value and this is
            // an erroneous value. This reason, if this value is -1, it will be changed to 0. Now in dtd there are not default value
            // for layer
            if (layer == -1)
                layer = 0;

            currentElementReference = new ElementReference(idTarget, x, y, layer);
            if (hasInfluence)
            {
                InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight);
                currentElementReference.setInfluenceArea(influenceArea);
            }
            if (scale > 0.001 || scale < -0.001)
                currentElementReference.setScale(scale);

            if (el.SelectSingleNode("documentation") != null)
                currentElementReference.setDocumentation(el.SelectSingleNode("documentation").InnerText);

            conditions = el.SelectNodes("condition");
            foreach (XmlElement ell in conditions)
            {
                currentConditions = new Conditions();
                new ConditionSubParser_(currentConditions, chapter).ParseElement(ell);
                currentElementReference.setConditions(currentConditions);
            }

            scene.addCharacterReference(currentElementReference);
        }

        foreach (XmlElement el in atrezzosrefs)
        {
            string idTarget = "";
            int x = 0, y = 0;
            float scale = 0;
            int layer = 0;
            int influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0;
            bool hasInfluence = false;

            tmpArgVal = el.GetAttribute("idTarget");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                idTarget = tmpArgVal;
            }
            tmpArgVal = el.GetAttribute("x");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                x = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("y");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                y = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("scale");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                scale = float.Parse(tmpArgVal, CultureInfo.InvariantCulture);
            }
            tmpArgVal = el.GetAttribute("layer");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                layer = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("hasInfluenceArea");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                hasInfluence = tmpArgVal.Equals("yes");
            }
            tmpArgVal = el.GetAttribute("layer");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                layer = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceX");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceX = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceY");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceY = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceWidth");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceWidth = int.Parse(tmpArgVal);
            }
            tmpArgVal = el.GetAttribute("influenceHeight");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                influenceHeight = int.Parse(tmpArgVal);
            }

            // This is for maintain the back-compatibility: in previous dtd versions layer has -1 as default value and this is
            // an erroneous value. This reason, if this value is -1, it will be changed to 0. Now in dtd there are not default value
            // for layer
            if (layer == -1)
                layer = 0;

            currentElementReference = new ElementReference(idTarget, x, y, layer);
            if (hasInfluence)
            {
                InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight);
                currentElementReference.setInfluenceArea(influenceArea);
            }
            if (scale > 0.001 || scale < -0.001)
                currentElementReference.setScale(scale);

            if (el.SelectSingleNode("documentation") != null)
                currentElementReference.setDocumentation(el.SelectSingleNode("documentation").InnerText);

            conditions = el.SelectNodes("condition");
            foreach (XmlElement ell in conditions)
            {
                currentConditions = new Conditions();
                new ConditionSubParser_(currentConditions, chapter).ParseElement(ell);
                currentElementReference.setConditions(currentConditions);
            }

            scene.addAtrezzoReference(currentElementReference);
        }

        foreach (XmlElement el in activesareas)
        {
            new ActiveAreaSubParser_(chapter, scene, scene.getActiveAreas().Count).ParseElement(el);
        }

        foreach (XmlElement el in barriers)
        {
            new BarrierSubParser_(chapter, scene, scene.getBarriers().Count).ParseElement(el);
        }

        foreach (XmlElement el in trajectorys)
        {
            new TrajectorySubParser_(chapter, scene).ParseElement(el);
        }

        if (scene != null)
        {
            TrajectoryFixer.fixTrajectory(scene);
        }
        chapter.addScene(scene);
    }
Exemplo n.º 10
0
    /*
     * (non-Javadoc)
     *
     * @see es.eucm.eadventure.engine.cargador.subparsers.SubParser#startElement(java.lang.string, java.lang.string,
     *      java.lang.string, org.xml.sax.Attributes)
     */
    public override void startElement(string namespaceURI, string sName, string qName, Dictionary<string, string> attrs)
    {
        Debug.Log("START: " + sName + " " + qName + " sub:" + subParsing + ", reading: " + reading);
        // If no element is being parsed
        if (subParsing == SUBPARSING_NONE)
        {

            // If it is a scene tag, create a new scene with its id
            if (qName.Equals("scene"))
            {
                string sceneId = "";
                bool initialScene = false;
                int playerLayer = -1;
                float playerScale = 1.0f;

                foreach (KeyValuePair<string, string> entry in attrs)
                {
                    if (entry.Key.Equals("id"))
                        sceneId = entry.Value.ToString();
                    if (entry.Key.Equals("start"))
                        initialScene = entry.Value.ToString().Equals("yes");
                    if (entry.Key.Equals("playerLayer"))
                        playerLayer = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("playerScale"))
                        playerScale = float.Parse(entry.Value.ToString(), CultureInfo.InvariantCulture);
                }

                scene = new Scene(sceneId);
                scene.setPlayerLayer(playerLayer);
                scene.setPlayerScale(playerScale);
                if (initialScene)
                    chapter.setTargetId(sceneId);
            }

            // If it is a resources tag, create the new resources
            else if (qName.Equals("resources"))
            {
                currentResources = new ResourcesUni();

                foreach (KeyValuePair<string, string> entry in attrs)
                {
                    if (entry.Key.Equals("name"))
                        currentResources.setName(entry.Value.ToString());
                }

                reading = READING_RESOURCES;
            }

            // If it is an asset tag, read it and add it to the current resources
            else if (qName.Equals("asset"))
            {
                string type = "";
                string path = "";

                foreach (KeyValuePair<string, string> entry in attrs)
                {
                    if (entry.Key.Equals("type"))
                        type = entry.Value.ToString();
                    if (entry.Key.Equals("uri"))
                        path = entry.Value.ToString();
                }

                currentResources.addAsset(type, path);
            }

            // If it is a default-initial-position tag, store it in the scene
            else if (qName.Equals("default-initial-position"))
            {
                int x = int.MinValue, y = int.MinValue;

                foreach (KeyValuePair<string, string> entry in attrs)
                {
                    if (entry.Key.Equals("x"))
                        x = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("y"))
                        y = int.Parse(entry.Value.ToString());
                }

                scene.setDefaultPosition(x, y);
            }

            // If it is an exit tag, create the new exit
            else if (qName.Equals("exit"))
            {
                int x = 0, y = 0, width = 0, height = 0;
                bool rectangular = true;
                int influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0;
                bool hasInfluence = false;
                string idTarget = "";
                int destinyX = int.MinValue, destinyY = int.MinValue;
                int transitionType = 0, transitionTime = 0;
                bool notEffects = false;

                foreach (KeyValuePair<string, string> entry in attrs)
                {
                    if (entry.Key.Equals("rectangular"))
                        rectangular = entry.Value.ToString().Equals("yes");
                    if (entry.Key.Equals("x"))
                        x = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("y"))
                        y = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("width"))
                        width = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("height"))
                        height = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("hasInfluenceArea"))
                        hasInfluence = entry.Value.ToString().Equals("yes");
                    if (entry.Key.Equals("influenceX"))
                        influenceX = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("influenceY"))
                        influenceY = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("influenceWidth"))
                        influenceWidth = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("influenceHeight"))
                        influenceHeight = int.Parse(entry.Value.ToString());

                    if (entry.Key.Equals("idTarget"))
                        idTarget = entry.Value.ToString();
                    if (entry.Key.Equals("destinyX"))
                        destinyX = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("destinyY"))
                        destinyY = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("transitionType"))
                        transitionType = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("transitionTime"))
                        transitionTime = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("not-effects"))
                        notEffects = entry.Value.ToString().Equals("yes");
                }

                currentExit = new Exit(rectangular, x, y, width, height);
                currentExit.setNextSceneId(idTarget);
                currentExit.setDestinyX(destinyX);
                currentExit.setDestinyY(destinyY);
                currentExit.setTransitionTime(transitionTime);
                currentExit.setTransitionType(transitionType);
                currentExit.setHasNotEffects(notEffects);
                if (hasInfluence)
                {
                    InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight);
                    currentExit.setInfluenceArea(influenceArea);
                }
                reading = READING_EXIT;
            }

            else if (qName.Equals("exit-look"))
            {
                currentExitLook = new ExitLook();
                string text = null;
                string cursorPath = null;
                string soundPath = null;
                foreach (KeyValuePair<string, string> entry in attrs)
                {
                    if (entry.Key.Equals("text"))
                    {
                        text = entry.Value.ToString();
                    }
                    if (entry.Key.Equals("cursor-path"))
                        cursorPath = entry.Value.ToString();
                    if (entry.Key.Equals("sound-path"))
                        soundPath = entry.Value.ToString();
                }
                currentExitLook.setCursorPath(cursorPath);
                currentExitLook.setExitText(text);
                if (soundPath != null)
                {
                    currentExitLook.setSoundPath(soundPath);
                }
                //  Debug.Log("311" + currentExitLook.getExitText());
            }

            // If it is a next-scene tag, create the new next scene
            else if (qName.Equals("next-scene"))
            {
                string idTarget = "";
                int x = int.MinValue, y = int.MinValue;
                int transitionType = 0, transitionTime = 0;

                foreach (KeyValuePair<string, string> entry in attrs)
                {
                    if (entry.Key.Equals("idTarget"))
                        idTarget = entry.Value.ToString();
                    if (entry.Key.Equals("x"))
                        x = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("y"))
                        y = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("transitionType"))
                        transitionType = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("transitionTime"))
                        transitionTime = int.Parse(entry.Value.ToString());
                }

                currentNextScene = new NextScene(idTarget, x, y);
                currentNextScene.setTransitionType((NextSceneEnumTransitionType)transitionType);
                currentNextScene.setTransitionTime(transitionTime);
                reading = READING_NEXT_SCENE;
            }

            else if (qName.Equals("point"))
            {

                int x = 0;
                int y = 0;

                foreach (KeyValuePair<string, string> entry in attrs)
                {
                    if (entry.Key.Equals("x"))
                        x = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("y"))
                        y = int.Parse(entry.Value.ToString());
                }

                currentPoint = new Vector2(x, y);
            }

            // If it is a object-ref or character-ref, create the new element reference
            else if (qName.Equals("object-ref") || qName.Equals("character-ref") || qName.Equals("atrezzo-ref"))
            {
                Debug.Log("SceneReference Start");
                string idTarget = "";
                int x = 0, y = 0;
                float scale = 0;
                int layer = 0;
                int influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0;
                bool hasInfluence = false;

                foreach (KeyValuePair<string, string> entry in attrs)
                {
                    if (entry.Key.Equals("idTarget"))
                        idTarget = entry.Value.ToString();
                    if (entry.Key.Equals("x"))
                        x = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("y"))
                        y = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("scale"))
                        scale = float.Parse(entry.Value.ToString(), CultureInfo.InvariantCulture);
                    if (entry.Key.Equals("layer"))
                        layer = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("hasInfluenceArea"))
                        hasInfluence = entry.Value.ToString().Equals("yes");
                    if (entry.Key.Equals("influenceX"))
                        influenceX = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("influenceY"))
                        influenceY = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("influenceWidth"))
                        influenceWidth = int.Parse(entry.Value.ToString());
                    if (entry.Key.Equals("influenceHeight"))
                        influenceHeight = int.Parse(entry.Value.ToString());
                }

                // This is for maintain the back-compatibility: in previous dtd versions layer has -1 as default value and this is
                // an erroneous value. This reason, if this value is -1, it will be changed to 0. Now in dtd there are not default value
                // for layer
                if (layer == -1)
                    layer = 0;

                currentElementReference = new ElementReference(idTarget, x, y, layer);
                if (hasInfluence)
                {
                    InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight);
                    currentElementReference.setInfluenceArea(influenceArea);
                }
                if (scale > 0.001 || scale < -0.001)
                    currentElementReference.setScale(scale);
                reading = READING_ELEMENT_REFERENCE;
            }

            // If it is a condition tag, create the new condition, the subparser and switch the state
            else if (qName.Equals("condition"))
            {
                currentConditions = new Conditions();
                subParser = new ConditionSubParser(currentConditions, chapter);
                subParsing = SUBPARSING_CONDITION;
            }

            // If it is a effect tag, create the new effect, the subparser and switch the state
            else if (qName.Equals("effect"))
            {
                currentEffects = new Effects();
                subParser = new EffectSubParser(currentEffects, chapter);
                subParsing = SUBPARSING_EFFECT;
            }

            // If it is a post-effect tag, create the new effect, the subparser and switch the state
            else if (qName.Equals("post-effect"))
            {
                currentEffects = new Effects();
                subParser = new EffectSubParser(currentEffects, chapter);
                subParsing = SUBPARSING_EFFECT;
            }

            // If it is a post-effect tag, create the new effect, the subparser and switch the state
            else if (qName.Equals("not-effect"))
            {
                currentEffects = new Effects();
                subParser = new EffectSubParser(currentEffects, chapter);
                subParsing = SUBPARSING_EFFECT;
            }

            // If it is a post-effect tag, create the new effect, the subparser and switch the state
            else if (qName.Equals("active-area"))
            {
                subParsing = SUBPARSING_ACTIVE_AREA;
                subParser = new ActiveAreaSubParser(chapter, scene, scene.getActiveAreas().Count);
            }

            // If it is a post-effect tag, create the new effect, the subparser and switch the state
            else if (qName.Equals("barrier"))
            {
                subParsing = SUBPARSING_BARRIER;
                subParser = new BarrierSubParser(chapter, scene, scene.getBarriers().Count);
            }

            else if (qName.Equals("trajectory"))
            {
                subParsing = SUBPARSING_TRAJECTORY;
                subParser = new TrajectorySubParser(chapter, scene);
            }

        }

        // If it is subparsing an effect or condition, spread the call
        if (subParsing != SUBPARSING_NONE)
        {
            subParser.startElement(namespaceURI, sName, qName, attrs);
        }
    }