コード例 #1
0
        protected override AdventureData ParseXml(XmlDocument doc)
        {
            XmlElement element     = doc.DocumentElement,
                       descriptor  = (XmlElement)element.SelectSingleNode("/game-descriptor"),
                       title       = (XmlElement)descriptor.SelectSingleNode("title"),
                       description = (XmlElement)descriptor.SelectSingleNode("description");

            // Basic attributes
            content.setVersionNumber(ExString.Default(descriptor.GetAttribute("versionNumber"), "0"));
            content.setTitle(title.InnerText ?? "");
            content.setDescription(description.InnerText ?? "");

            // Sub nodes
            XmlElement configuration    = (XmlElement)descriptor.SelectSingleNode("configuration"),
                       contents         = (XmlElement)descriptor.SelectSingleNode("contents"),
                       extensionObjects = (XmlElement)descriptor.SelectSingleNode("extension-objects");

            ParseConfiguration(content, configuration, incidences);
            ParseContents(content, contents, resourceManager, incidences);

            if (extensionObjects != null)
            {
                foreach (var el in extensionObjects.ChildNodes)
                {
                    object parsed = DOMParserUtility.DOMParse(el as XmlElement);
                    if (parsed != null)
                    {
                        var t = GroupableTypeAttribute.GetGroupType(parsed.GetType());
                        content.getObjects(t).Add(parsed);
                    }
                }
            }

            return(base.content);
        }
コード例 #2
0
        public object DOMParse(XmlElement element, params object[] parameters)
        {
            string time        = element.GetAttribute("time");
            string displayName = ExString.Default(element.GetAttribute("displayName"), "timer");

            bool usesEndCondition = ExString.EqualsDefault(element.GetAttribute("usesEndCondition"), "yes", true);
            bool runsInLoop       = ExString.EqualsDefault(element.GetAttribute("runsInLoop"), "yes", true);
            bool multipleStarts   = ExString.EqualsDefault(element.GetAttribute("multipleStarts"), "yes", true);
            bool showTime         = ExString.EqualsDefault(element.GetAttribute("showTime"), "yes", false);
            bool countDown        = ExString.EqualsDefault(element.GetAttribute("countDown"), "yes", false);
            bool showWhenStopped  = ExString.EqualsDefault(element.GetAttribute("showWhenStopped"), "yes", false);

            Timer timer = new Timer(long.Parse(time));

            timer.setRunsInLoop(runsInLoop);
            timer.setUsesEndCondition(usesEndCondition);
            timer.setMultipleStarts(multipleStarts);
            timer.setShowTime(showTime);
            timer.setDisplayName(displayName);
            timer.setCountDown(countDown);
            timer.setShowWhenStopped(showWhenStopped);

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

            timer.setInitCond(DOMParserUtility.DOMParse <Conditions>(element.SelectSingleNode("init-condition"), parameters) ?? new Conditions());
            timer.setEndCond(DOMParserUtility.DOMParse <Conditions>(element.SelectSingleNode("end-condition"), parameters) ?? new Conditions());
            timer.setEffects(DOMParserUtility.DOMParse <Effects>(element.SelectSingleNode("effect"), parameters) ?? new Effects());
            timer.setPostEffects(DOMParserUtility.DOMParse <Effects>(element.SelectSingleNode("post-effect"), parameters) ?? new Effects());

            return(timer);
        }
コード例 #3
0
        private static void ParseConfiguration(AdventureData adventureData, XmlElement configuration, List<Incidence> incidences)
        {
            if (configuration == null)
            {
                return;
            }

            // Keep showing text until user clicks
            var isKeepShowing = ExString.EqualsDefault(configuration.GetAttribute("keepShowing"), "yes", false);
            adventureData.setKeepShowing(isKeepShowing);

            // Use keys to navigate in the scene
            var isKeyboardNavigation = ExString.EqualsDefault(configuration.GetAttribute("keyboard-navigation"), "enabled", false);
            adventureData.setKeyboardNavigation(isKeyboardNavigation);

            // Default click action for scene elements
            var defaultClickAction = ExString.Default(configuration.GetAttribute("defaultClickAction"), "showDetails");
            switch (defaultClickAction)
            {
                case "showDetails": adventureData.setDeafultClickAction(DescriptorData.DefaultClickAction.SHOW_DETAILS); break;
                case "showActions": adventureData.setDeafultClickAction(DescriptorData.DefaultClickAction.SHOW_ACTIONS); break;
                default: incidences.Add(Incidence.createDescriptorIncidence("Unknown defaultClickAction type: " + defaultClickAction, null)); break;
            }

            // Perspective for rendering
            var perspective = ExString.Default(configuration.GetAttribute("perspective"), "regular");
            switch (perspective)
            {
                case "regular": adventureData.setPerspective(DescriptorData.Perspective.REGULAR); break;
                case "isometric": adventureData.setPerspective(DescriptorData.Perspective.ISOMETRIC); break;
                default: incidences.Add(Incidence.createDescriptorIncidence("Unknown perspective type: " + perspective, null)); break;
            }

            // Drag behaviour configuration
            var dragBehaviour = ExString.Default(configuration.GetAttribute("dragBehaviour"), "considerNonTargets");
            switch (dragBehaviour)
            {
                case "considerNonTargets": adventureData.setDragBehaviour(DescriptorData.DragBehaviour.CONSIDER_NON_TARGETS); break;
                case "ignoreNonTargets": adventureData.setDragBehaviour(DescriptorData.DragBehaviour.IGNORE_NON_TARGETS); break;
                default: incidences.Add(Incidence.createDescriptorIncidence("Unknown dragBehaviour type: " + dragBehaviour, null)); break;
            }

            // Auto Save
            var isAutoSave = ExString.EqualsDefault(configuration.GetAttribute("autosave"), "yes", true);
            adventureData.setAutoSave(isAutoSave);

            // Save on suspend
            var isSaveOnSuspend = ExString.EqualsDefault(configuration.GetAttribute("save-on-suspend"), "yes", true);
            adventureData.setSaveOnSuspend(isSaveOnSuspend);

            // Sub nodes
            XmlElement gui          = (XmlElement)configuration.SelectSingleNode("gui"),
                mode                = (XmlElement)configuration.SelectSingleNode("mode"),
                graphics            = (XmlElement)configuration.SelectSingleNode("graphics");

            ParseGui(adventureData, gui, incidences);
            ParseMode(adventureData, mode);
            ParseGraphics(adventureData, graphics, incidences);
        }
コード例 #4
0
        private static void ParseGui(AdventureData adventureData, XmlElement gui, List<Incidence> incidences)
        {
            if (gui == null)
            {
                return;
            }

            var guiType = ExString.Default(gui.GetAttribute("type"), "contextual");
            switch (guiType)
            {
                case "traditional": adventureData.setGUIType(DescriptorData.GUI_TRADITIONAL); break;
                case "contextual":  adventureData.setGUIType(DescriptorData.GUI_CONTEXTUAL);  break;
                default: incidences.Add(Incidence.createDescriptorIncidence("Unknown GUIType type: " + guiType, null)); break;
            }
            
            var isCustomized = ExString.EqualsDefault(gui.GetAttribute("customized"), "yes", false);
            adventureData.setGUI(adventureData.getGUIType(), isCustomized);

            var inventoryPosition = ExString.Default(gui.GetAttribute("inventoryPosition"), "top_bottom");
            switch (inventoryPosition)
            {
                case "none": adventureData.setInventoryPosition(DescriptorData.INVENTORY_NONE); break;
                case "top_bottom": adventureData.setInventoryPosition(DescriptorData.INVENTORY_TOP_BOTTOM); break;
                case "top": adventureData.setInventoryPosition(DescriptorData.INVENTORY_TOP); break;
                case "bottom": adventureData.setInventoryPosition(DescriptorData.INVENTORY_BOTTOM); break;
                case "fixed_top": adventureData.setInventoryPosition(DescriptorData.INVENTORY_FIXED_TOP); break;
                case "fixed_bottom": adventureData.setInventoryPosition(DescriptorData.INVENTORY_FIXED_BOTTOM); break;
                default: incidences.Add(Incidence.createDescriptorIncidence("Unknown inventoryPosition type: " + inventoryPosition, null)); break;
            }

            XmlNodeList cursors = gui.SelectNodes("cursors/cursor");
            foreach (XmlElement cursor in cursors)
            {
                string type = ExString.Default(cursor.GetAttribute("type"), ""),
                    uri     = ExString.Default(cursor.GetAttribute("uri"), "");

                adventureData.addCursor(type, uri);
            }

            XmlNodeList buttons = gui.SelectNodes("buttons/button");
            foreach (XmlElement button in buttons)
            {
                string type = ExString.Default(button.GetAttribute("type"), ""),
                    uri     = ExString.Default(button.GetAttribute("uri"), ""),
                    action  = ExString.Default(button.GetAttribute("action"), "");

                adventureData.addButton(action, type, uri);
            }

            XmlNodeList arrows = gui.SelectNodes("cursors/cursor");
            foreach (XmlElement arrow in arrows)
            {
                string type = ExString.Default(arrow.GetAttribute("type"), ""),
                    uri     = ExString.Default(arrow.GetAttribute("uri"), "");

                adventureData.addArrow(type, uri);
            }
        }
コード例 #5
0
        public object DOMParse(XmlElement element, params object[] parameters)
        {
            Action currentAction = new Action(0);

            //First we parse the elements every action haves:
            bool   currentNeedsGoTo     = ExString.EqualsDefault(element.GetAttribute("needsGoTo"), "yes", false);
            int    currentKeepDistance  = ExParsers.ParseDefault(element.GetAttribute("keepDistance"), 0);
            bool   activateNotEffects   = ExString.EqualsDefault(element.GetAttribute("not-effects"), "yes", false);
            bool   activateClickEffects = ExString.EqualsDefault(element.GetAttribute("click-effects"), "yes", false);
            string currentIdTarget      = element.GetAttribute("idTarget");

            Conditions conditions   = DOMParserUtility.DOMParse <Conditions> ((XmlElement)element.SelectSingleNode("condition"), parameters) ?? new Conditions();
            Effects    effects      = DOMParserUtility.DOMParse <Effects> ((XmlElement)element.SelectSingleNode("effect"), parameters) ?? new Effects();
            Effects    clickeffects = DOMParserUtility.DOMParse <Effects> ((XmlElement)element.SelectSingleNode("click-effect"), parameters) ?? new Effects();
            Effects    noteffects   = DOMParserUtility.DOMParse <Effects> ((XmlElement)element.SelectSingleNode("not-effect"), parameters) ?? new Effects();

            // Then we instantiate the correct action by name.
            // We also parse the elements that are unique of that action.
            switch (element.Name)
            {
            case "examine":         currentAction = new Action(Action.EXAMINE, conditions, effects, noteffects); break;

            case "grab":            currentAction = new Action(Action.GRAB, conditions, effects, noteffects); break;

            case "use":             currentAction = new Action(Action.USE, conditions, effects, noteffects); break;

            case "talk-to":         currentAction = new Action(Action.TALK_TO, conditions, effects, noteffects); break;

            case "use-with":        currentAction = new Action(Action.USE_WITH, currentIdTarget, conditions, effects, noteffects, clickeffects); break;

            case "give-to":         currentAction = new Action(Action.GIVE_TO, currentIdTarget, conditions, effects, noteffects, clickeffects); break;

            case "drag-to":         currentAction = new Action(Action.DRAG_TO, currentIdTarget, conditions, effects, noteffects, clickeffects); break;

            case "custom":
            case "custom-interact":
                CustomAction customAction = new CustomAction((element.Name == "custom") ? Action.CUSTOM : Action.CUSTOM_INTERACT);
                customAction.setName(element.GetAttribute("name"));
                customAction.addResources(
                    DOMParserUtility.DOMParse <ResourcesUni>((XmlElement)element.SelectSingleNode("resources"), parameters) ?? new ResourcesUni());

                currentAction = customAction;
                break;
            }

            // Lastly we set al the attributes to the action
            currentAction.setConditions(conditions);
            currentAction.setEffects(effects);
            currentAction.setNotEffects(noteffects);
            currentAction.setKeepDistance(currentKeepDistance);
            currentAction.setNeedsGoTo(currentNeedsGoTo);
            currentAction.setActivatedNotEffects(activateNotEffects);
            currentAction.setClickEffects(clickeffects);
            currentAction.setActivatedClickEffects(activateClickEffects);

            return(currentAction);
        }
        private Condition parseGlobal(XmlElement element, params object[] parameters)
        {
            // Id
            string id = element.GetAttribute("id");
            // VALUE WAS ADDED IN EAD1.4 - It allows negating a global state
            bool value = ExString.EqualsDefault(element.GetAttribute("value"), "true", false);

            return(new GlobalStateCondition(id, value ? GlobalStateCondition.GS_SATISFIED : GlobalStateCondition.GS_NOT_SATISFIED));
        }
コード例 #7
0
 private static void ParseMode(AdventureData adventureData, XmlElement mode)
 {
     if (mode == null)
     {
         return;
     }
     
     var isPlayerTransparent = ExString.EqualsDefault(mode.GetAttribute("playerTransparent"), "yes", true);
     adventureData.setPlayerMode(isPlayerTransparent ? DescriptorData.MODE_PLAYER_1STPERSON : DescriptorData.MODE_PLAYER_3RDPERSON);
 }
コード例 #8
0
        public static void ParseVoice(NPC npc, XmlElement element)
        {
            var voice = element.SelectSingleNode("voice") as XmlElement;

            if (voice != null)
            {
                npc.setAlwaysSynthesizer(ExString.EqualsDefault(voice.GetAttribute("synthesizeAlways"), "yes", npc.isAlwaysSynthesizer()));
                npc.setVoice(voice.GetAttribute("name"));
            }
        }
コード例 #9
0
        private static void ParseGraphics(AdventureData adventureData, XmlElement graphics, List<Incidence> incidences)
        {
            if (graphics == null)
            {
                return;
            }

            var graphicsMode = ExString.Default(graphics.GetAttribute("mode"), "fullscreen");
            switch (graphicsMode)
            {
                case "windowed": adventureData.setGraphicConfig(DescriptorData.GRAPHICS_WINDOWED); break;
                case "fullscreen": adventureData.setGraphicConfig(DescriptorData.GRAPHICS_FULLSCREEN); break;
                case "blackbkg": adventureData.setGraphicConfig(DescriptorData.GRAPHICS_BLACKBKG); break;
                default: incidences.Add(Incidence.createDescriptorIncidence("Unknown graphicsMode type: " + graphicsMode, null)); break;
            }
        }
コード例 #10
0
        public object DOMParse(XmlElement element, params object[] parameters)
        {
            Frame frame = new Frame();

            /*XmlNodeList
             *  assets = element.SelectNodes("next-scene");*/

            switch (element.GetAttribute("type"))
            {
            case "image":
                frame.setType(Frame.TYPE_IMAGE);
                break;

            case "video":
                frame.setType(Frame.TYPE_VIDEO);
                break;
            }

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

            frame.setUri(element.GetAttribute("uri"));
            frame.setWaitforclick(ExString.EqualsDefault(element.GetAttribute("waitforclick"), "yes", false));
            frame.setSoundUri(element.GetAttribute("soundUri"));

            var time = element.GetAttribute("time");

            if (!string.IsNullOrEmpty(time))
            {
                frame.setTime(long.Parse(time));
            }
            var maxsoundtime = element.GetAttribute("maxSoundTime");

            if (!string.IsNullOrEmpty(maxsoundtime))
            {
                frame.setMaxSoundTime(int.Parse(maxsoundtime));
            }

            foreach (var resources in DOMParserUtility.DOMParse <ResourcesUni>(element.SelectNodes("resources"), parameters))
            {
                frame.addResources(resources);
            }

            return(frame);
        }
コード例 #11
0
        protected override Animation ParseXml(XmlDocument doc)
        {
            XmlElement element       = doc.DocumentElement;
            XmlElement animationNode = element.SelectSingleNode("/animation") as XmlElement;

            if (animationNode == null)
            {
                return(null);
            }

            var animation = new Animation(animationNode.GetAttribute("id") ?? "newAnimationId");

            animation.getFrames().Clear();
            animation.getTransitions().Clear();

            animation.setSlides(ExString.EqualsDefault(animationNode.GetAttribute("slides"), "yes", false));
            animation.setUseTransitions(ExString.EqualsDefault(animationNode.GetAttribute("usetransitions"), "yes", false));

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

            // FRAMES
            foreach (var frame in DOMParserUtility.DOMParse <Frame>(element.SelectNodes("/animation/frame")))
            {
                animation.addFrame(frame);
            }

            // TRANSITIONS
            foreach (var transition in DOMParserUtility.DOMParse <Transition>(element.SelectNodes("/animation/transition")))
            {
                animation.getTransitions().Add(transition);
            }


            // RESOURCES
            foreach (var res in DOMParserUtility.DOMParse <ResourcesUni>(element.SelectNodes("/animation/resources")))
            {
                animation.addResources(res);
            }

            return(animation);
        }
コード例 #12
0
ファイル: ItemSubParser.cs プロジェクト: dotlive/uAdventure
        public object DOMParse(XmlElement element, params object[] parameters)
        {
            Item parsedObject = new Item(element.GetAttribute("id"));

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

            switch (element.GetAttribute("behaviour"))
            {
            case "atrezzo": parsedObject.setBehaviour(Item.BehaviourType.ATREZZO); break;

            case "first-action": parsedObject.setBehaviour(Item.BehaviourType.FIRST_ACTION); break;

            default: parsedObject.setBehaviour(Item.BehaviourType.NORMAL); break;
            }

            parsedObject.setReturnsWhenDragged(ExString.EqualsDefault(element.GetAttribute("returnsWhenDragged"), "yes", true));
            parsedObject.setResourcesTransitionTime(ExParsers.ParseDefault(element.GetAttribute("resources-transition-time"), 0L));

            // RESOURCES
            foreach (var res in DOMParserUtility.DOMParse <ResourcesUni> (element.SelectNodes("resources"), parameters))
            {
                parsedObject.addResources(res);
            }

            // DESCRIPTIONS
            parsedObject.setDescriptions(DOMParserUtility.DOMParse <Description>(element.SelectNodes("description"), parameters).ToList());

            // ACTIONS
            var actionsNode = element.SelectSingleNode("actions");

            if (actionsNode != null)
            {
                foreach (var res in DOMParserUtility.DOMParse <Action> (actionsNode.ChildNodes, parameters))
                {
                    parsedObject.addAction(res);
                }
            }

            return(parsedObject);
        }
        private ElementReference parseElementReference(XmlElement element, params object[] parameters)
        {
            string idTarget = element.GetAttribute("idTarget");

            int x = ExParsers.ParseDefault(element.GetAttribute("x"), 0),
                y = ExParsers.ParseDefault(element.GetAttribute("y"), 0);

            Orientation orientation = (Orientation)ExParsers.ParseDefault(element.GetAttribute("orientation"), 2);

            float scale = ExParsers.ParseDefault(element.GetAttribute("scale"), CultureInfo.InvariantCulture, 0f);
            int   layer = ExParsers.ParseDefault(element.GetAttribute("layer"), -1);

            int influenceX      = ExParsers.ParseDefault(element.GetAttribute("influenceX"), 0),
                influenceY      = ExParsers.ParseDefault(element.GetAttribute("influenceY"), 0),
                influenceWidth  = ExParsers.ParseDefault(element.GetAttribute("influenceWidth"), 0),
                influenceHeight = ExParsers.ParseDefault(element.GetAttribute("influenceHeight"), 0);

            bool hasInfluence = ExString.EqualsDefault(element.GetAttribute("hasInfluenceArea"), "yes", false);

            var currentElementReference = new ElementReference(idTarget, x, y, layer);

            currentElementReference.Orientation = orientation;
            if (hasInfluence)
            {
                InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight);
                currentElementReference.setInfluenceArea(influenceArea);
            }
            if (scale > 0.001 || scale < -0.001)
            {
                currentElementReference.Scale = scale;
            }

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

            currentElementReference.Conditions = DOMParserUtility.DOMParse(element.SelectSingleNode("condition"), parameters) as Conditions ?? new Conditions();

            return(currentElementReference);
        }
コード例 #14
0
        protected override AdventureData ParseXml(XmlDocument doc)
        {
            XmlElement element     = doc.DocumentElement,
                       descriptor  = (XmlElement)element.SelectSingleNode("/game-descriptor"),
                       title       = (XmlElement)descriptor.SelectSingleNode("title"),
                       description = (XmlElement)descriptor.SelectSingleNode("description");

            // Basic attributes
            content.setVersionNumber(ExString.Default(descriptor.GetAttribute("versionNumber"), "0"));
            content.setTitle(title.InnerText ?? "");
            content.setDescription(description.InnerText ?? "");

            // Sub nodes
            XmlElement configuration = (XmlElement)descriptor.SelectSingleNode("configuration"),
                       contents      = (XmlElement)descriptor.SelectSingleNode("contents");

            ParseConfiguration(content, configuration, incidences);
            ParseContents(content, contents, resourceManager, incidences);

            return(base.content);
        }
        /// <summary>
        /// Fills the assesment rule.
        /// </summary>
        /// <param name="element">Element.</param>
        /// <param name="rule">Rule.</param>
        /// <param name="parameters">Parameters.</param>
        private void fillAssesmentRule(XmlElement element, AssessmentRule rule, params object[] parameters)
        {
            string id         = element.GetAttribute("id");
            int    importance = 0;
            bool   repeatRule = ExString.EqualsDefault(element.GetAttribute("repeatRule"), "yes", false);

            var tmpArgVal = element.GetAttribute("importance");

            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                for (int j = 0; j < AssessmentRule.N_IMPORTANCE_VALUES; j++)
                {
                    if (tmpArgVal.Equals(AssessmentRule.IMPORTANCE_VALUES[j]))
                    {
                        importance = j;
                    }
                }
            }

            rule.setId(id);
            rule.setImportance(importance);
            rule.setRepeatRule(repeatRule);

            rule.setConditions(DOMParserUtility.DOMParse(element.SelectSingleNode("condition"), parameters)        as Conditions ?? new Conditions());

            var concept = element.SelectSingleNode("concept");

            if (concept != null)
            {
                rule.setConcept(concept.ToString().Trim());
            }

            var setText = element.SelectSingleNode("set-text");

            if (setText != null)
            {
                rule.setText(setText.InnerText.ToString().Trim());
            }
        }
コード例 #16
0
        public static void ParseConversationColors(NPC npc, XmlElement element)
        {
            var textcolor = element.SelectSingleNode("textcolor") as XmlElement;

            if (textcolor != null)
            {
                npc.setShowsSpeechBubbles(ExString.EqualsDefault(textcolor.GetAttribute("showsSpeechBubble"), "yes", npc.getShowsSpeechBubbles()));
                npc.setBubbleBkgColor(ExParsers.ParseDefault(textcolor.GetAttribute("bubbleBkgColor"), npc.getBubbleBkgColor()));
                npc.setBubbleBorderColor(ExParsers.ParseDefault(textcolor.GetAttribute("bubbleBorderColor"), npc.getBubbleBorderColor()));

                var frontcolor = textcolor.SelectSingleNode("frontcolor") as XmlElement;
                if (frontcolor != null)
                {
                    npc.setTextFrontColor(ExParsers.ParseDefault(frontcolor.GetAttribute("color"), npc.getTextFrontColor()));
                }

                var bordercolor = textcolor.SelectSingleNode("bordercolor") as XmlElement;
                if (bordercolor != null)
                {
                    npc.setTextBorderColor(ExParsers.ParseDefault(bordercolor.GetAttribute("color"), npc.getTextBorderColor()));
                }
            }
        }
コード例 #17
0
        public object DOMParse(XmlElement element, params object[] parameters)
        {
            var chapter = parameters [0] as Chapter;
            var effects = element.Name == "macro" ? new Macro(element.GetAttribute("id")) : new Effects();

            var macro = effects as Macro;

            if (macro != null)
            {
                macro.setDocumentation(element.InnerText);
            }

            string tmpArgVal;
            int    x = 0;
            int    y = 0;
            string path = "";
            string id = "";
            string guid = "";
            bool   animated = false, addeffect = true;

            IEffect currentEffect = null;

            foreach (XmlElement effect in element.ChildNodes)
            {
                addeffect = true;
                guid      = effect.GetAttribute("guid");

                switch (effect.Name)
                {
                case "cancel-action": currentEffect = new CancelActionEffect(); break;

                case "activate":
                case "deactivate":
                    tmpArgVal = effect.GetAttribute("flag");
                    if (!string.IsNullOrEmpty(tmpArgVal))
                    {
                        chapter.addFlag(tmpArgVal);
                    }

                    if (effect.Name == "activate")
                    {
                        currentEffect = new ActivateEffect(tmpArgVal);
                    }
                    else
                    {
                        currentEffect = new DeactivateEffect(tmpArgVal);
                    }
                    break;

                case "set-value":
                case "increment":
                case "decrement":
                    string var   = effect.GetAttribute("var");
                    int    value = ExParsers.ParseDefault(effect.GetAttribute("value"), 0);

                    if (effect.Name == "set-value")
                    {
                        currentEffect = new SetValueEffect(var, value);
                    }
                    else if (effect.Name == "increment")
                    {
                        currentEffect = new IncrementVarEffect(var, value);
                    }
                    else
                    {
                        currentEffect = new DecrementVarEffect(var, value);
                    }

                    chapter.addVar(var);
                    break;

                case "macro-ref":
                    currentEffect = new MacroReferenceEffect(effect.GetAttribute("id"));
                    break;

                case "speak-char":
                    // Add the effect and clear the current string
                    currentEffect = new SpeakCharEffect(effect.GetAttribute("idTarget"), effect.InnerText.ToString().Trim());
                    ((SpeakCharEffect)currentEffect).setAudioPath(effect.GetAttribute("uri"));
                    break;

                case "trigger-last-scene":
                    currentEffect = new TriggerLastSceneEffect();
                    break;

                case "play-sound":
                    // Store the path and background
                    bool background = ExString.EqualsDefault(effect.GetAttribute("background"), "yes", true);
                    path = effect.GetAttribute("uri");

                    // Add the new play sound effect
                    currentEffect = new PlaySoundEffect(background, path);
                    break;

                case "consume-object":          currentEffect = new ConsumeObjectEffect(effect.GetAttribute("idTarget")); break;

                case "generate-object":         currentEffect = new GenerateObjectEffect(effect.GetAttribute("idTarget")); break;

                case "trigger-book":            currentEffect = new TriggerBookEffect(effect.GetAttribute("idTarget")); break;

                case "trigger-conversation": currentEffect = new TriggerConversationEffect(effect.GetAttribute("idTarget")); break;

                case "trigger-cutscene":        currentEffect = new TriggerCutsceneEffect(effect.GetAttribute("idTarget")); break;

                case "trigger-scene":

                    x = ExParsers.ParseDefault(effect.GetAttribute("x"), 0);
                    y = ExParsers.ParseDefault(effect.GetAttribute("y"), 0);

                    string scene = effect.GetAttribute("idTarget");
                    var    triggerSceneEffect = new TriggerSceneEffect(scene, x, y)
                    {
                        DestinyScale = ExParsers.ParseDefault(effect.GetAttribute("scale"), CultureInfo.InvariantCulture, float.MinValue)
                    };

                    triggerSceneEffect.setTransitionTime(ExParsers.ParseDefault(effect.GetAttribute("transitionTime"), 0));
                    triggerSceneEffect.setTransitionType((TransitionType)ExParsers.ParseDefault(effect.GetAttribute("transitionType"), 0));

                    currentEffect = triggerSceneEffect;
                    break;

                case "play-animation":
                    x    = ExParsers.ParseDefault(effect.GetAttribute("x"), 0);
                    y    = ExParsers.ParseDefault(effect.GetAttribute("y"), 0);
                    path = effect.GetAttribute("uri");
                    // Add the new play sound effect
                    currentEffect = new PlayAnimationEffect(path, x, y);
                    break;

                case "move-player":
                    x = ExParsers.ParseDefault(effect.GetAttribute("x"), 0);
                    y = ExParsers.ParseDefault(effect.GetAttribute("y"), 0);
                    // Add the new move player effect
                    currentEffect = new MovePlayerEffect(x, y);
                    break;

                case "move-npc":
                    x = ExParsers.ParseDefault(effect.GetAttribute("x"), 0);
                    y = ExParsers.ParseDefault(effect.GetAttribute("y"), 0);
                    string npcTarget = effect.GetAttribute("idTarget");
                    // Add the new move NPC effect
                    currentEffect = new MoveNPCEffect(npcTarget, x, y);
                    break;

                case "random-effect":
                    // Add the new random effect
                    var randomEffect = new RandomEffect(ExParsers.ParseDefault(effect.GetAttribute("probability"), 0));

                    Effects randomEffectList = DOMParserUtility.DOMParse <Effects> (effect, parameters);

                    if (randomEffectList.Count > 0)
                    {
                        randomEffect.setPositiveEffect(randomEffectList.getEffects()[0]);
                        if (randomEffectList.Count > 1)
                        {
                            randomEffect.setNegativeEffect(randomEffectList.getEffects()[1]);
                        }
                    }

                    currentEffect = randomEffect;
                    break;

                case "wait-time":
                    // Add the new move NPC effect
                    currentEffect = new WaitTimeEffect(ExParsers.ParseDefault(effect.GetAttribute("time"), 0));
                    break;

                case "show-text":
                    x = ExParsers.ParseDefault(effect.GetAttribute("x"), 0);
                    y = ExParsers.ParseDefault(effect.GetAttribute("y"), 0);
                    Color frontColor;
                    ColorUtility.TryParseHtmlString(effect.GetAttribute("frontColor"), out frontColor);
                    Color borderColor;
                    ColorUtility.TryParseHtmlString(effect.GetAttribute("borderColor"), out borderColor);

                    // Add the new ShowTextEffect
                    currentEffect = new ShowTextEffect(effect.InnerText.ToString().Trim(), x, y, frontColor, borderColor);
                    ((ShowTextEffect)currentEffect).setAudioPath(effect.GetAttribute("uri"));
                    break;

                case "highlight-item":
                    id       = effect.GetAttribute("idTarget");
                    animated = ExString.EqualsDefault(effect.GetAttribute("animated"), "yes", false);

                    int type = 0;
                    tmpArgVal = effect.GetAttribute("type");
                    if (!string.IsNullOrEmpty(tmpArgVal))
                    {
                        if (tmpArgVal.Equals("none"))
                        {
                            type = HighlightItemEffect.NO_HIGHLIGHT;
                        }
                        if (tmpArgVal.Equals("green"))
                        {
                            type = HighlightItemEffect.HIGHLIGHT_GREEN;
                        }
                        if (tmpArgVal.Equals("red"))
                        {
                            type = HighlightItemEffect.HIGHLIGHT_RED;
                        }
                        if (tmpArgVal.Equals("blue"))
                        {
                            type = HighlightItemEffect.HIGHLIGHT_BLUE;
                        }
                        if (tmpArgVal.Equals("border"))
                        {
                            type = HighlightItemEffect.HIGHLIGHT_BORDER;
                        }
                    }
                    currentEffect = new HighlightItemEffect(id, type, animated);
                    break;

                case "move-object":

                    x = ExParsers.ParseDefault(effect.GetAttribute("x"), 0);
                    y = ExParsers.ParseDefault(effect.GetAttribute("y"), 0);

                    id       = effect.GetAttribute("idTarget");
                    animated = ExString.EqualsDefault(effect.GetAttribute("animated"), "yes", false);
                    float scale          = ExParsers.ParseDefault(effect.GetAttribute("scale"), CultureInfo.InvariantCulture, 1.0f);
                    int   translateSpeed = ExParsers.ParseDefault(effect.GetAttribute("translateSpeed"), 20);
                    int   scaleSpeed     = ExParsers.ParseDefault(effect.GetAttribute("scaleSpeed"), 20);

                    currentEffect = new MoveObjectEffect(id, x, y, scale, animated, translateSpeed, scaleSpeed);
                    break;

                case "speak-player":
                    // Add the effect and clear the current string
                    currentEffect = new SpeakPlayerEffect(effect.InnerText.ToString().Trim());
                    ((SpeakPlayerEffect)currentEffect).setAudioPath(effect.GetAttribute("uri"));
                    break;

                case "condition":
                    addeffect = false;
                    var currentConditions = DOMParserUtility.DOMParse(effect, parameters) as Conditions ?? new Conditions();
                    var lastEffect        = effects[effects.Count - 1] as AbstractEffect;
                    if (lastEffect != null)
                    {
                        lastEffect.setConditions(currentConditions);
                    }
                    break;

                case "documentation":
                    addeffect = false;
                    break;

                default:
                    currentEffect = DOMParserUtility.DOMParse(effect, parameters) as IEffect;
                    addeffect     = currentEffect != null;
                    if (!addeffect)
                    {
                        Debug.LogWarning("EFFECT NOT SUPPORTED: " + effect.Name);
                    }

                    break;
                }

                if (addeffect)
                {
                    if (!string.IsNullOrEmpty(guid))
                    {
                        currentEffect.GUID = guid;
                    }
                    effects.Add(currentEffect);
                }
            }

            return(effects);
        }
        public object DOMParse(XmlElement element, params object[] parameters)
        {
            var chapter = parameters [0] as Chapter;

            string sceneId       = element.GetAttribute("id");
            bool   initialScene  = ExString.EqualsDefault(element.GetAttribute("start"), "yes", false);
            bool   hideInventory = ExString.EqualsDefault(element.GetAttribute("hideInventory"), "yes", false);
            int    playerLayer   = ExParsers.ParseDefault(element.GetAttribute("playerLayer"), -1);
            float  playerScale   = ExParsers.ParseDefault(element.GetAttribute("playerScale"), CultureInfo.InvariantCulture, 1.0f);

            scene = new Scene(sceneId)
            {
                HideInventory = hideInventory
            };
            scene.setPlayerLayer(playerLayer);
            scene.setPlayerScale(playerScale);

            if (initialScene)
            {
                chapter.setTargetId(sceneId);
            }

            var name = element.SelectSingleNode("name");

            if (name != null)
            {
                scene.setName(name.InnerText);
            }

            var documentation = element.SelectSingleNode("documentation");

            if (documentation != null)
            {
                scene.setDocumentation(documentation.InnerText);
            }

            //XAPI ELEMENTS
            scene.setXApiClass(element.GetAttribute("class"));
            scene.setXApiType(element.GetAttribute("type"));
            //END OF XAPI

            foreach (var res in DOMParserUtility.DOMParse <ResourcesUni> (element.SelectNodes("resources"), parameters))
            {
                scene.addResources(res);
            }

            var defaultsinitialsposition = element.SelectSingleNode("default-initial-position") as XmlElement;

            if (defaultsinitialsposition != null)
            {
                int x = ExParsers.ParseDefault(defaultsinitialsposition.GetAttribute("x"), int.MinValue),
                    y = ExParsers.ParseDefault(defaultsinitialsposition.GetAttribute("y"), int.MinValue);

                scene.setDefaultPosition(x, y);
            }

            foreach (XmlElement el in  element.SelectNodes("exits/exit"))
            {
                int x                  = ExParsers.ParseDefault(el.GetAttribute("x"), 0),
                                y      = ExParsers.ParseDefault(el.GetAttribute("y"), 0),
                                width  = ExParsers.ParseDefault(el.GetAttribute("width"), 0),
                                height = ExParsers.ParseDefault(el.GetAttribute("height"), 0);

                bool rectangular  = ExString.EqualsDefault(el.GetAttribute("rectangular"), "yes", true);
                bool hasInfluence = ExString.EqualsDefault(el.GetAttribute("hasInfluenceArea"), "yes", false);

                int influenceX      = ExParsers.ParseDefault(el.GetAttribute("influenceX"), 0),
                    influenceY      = ExParsers.ParseDefault(el.GetAttribute("influenceY"), 0),
                    influenceWidth  = ExParsers.ParseDefault(el.GetAttribute("influenceWidth"), 0),
                    influenceHeight = ExParsers.ParseDefault(el.GetAttribute("influenceHeight"), 0);

                string idTarget = el.GetAttribute("idTarget");
                int    destinyX = ExParsers.ParseDefault(el.GetAttribute("destinyX"), int.MinValue),
                       destinyY = ExParsers.ParseDefault(el.GetAttribute("destinyY"), int.MinValue);

                float destinyScale = ExParsers.ParseDefault(el.GetAttribute("destinyScale"), CultureInfo.InvariantCulture, float.MinValue);

                int transitionType = ExParsers.ParseDefault(el.GetAttribute("transitionType"), 0),
                    transitionTime = ExParsers.ParseDefault(el.GetAttribute("transitionTime"), 0);
                bool notEffects    = ExString.EqualsDefault(el.GetAttribute("not-effects"), "yes", false);


                currentExit = new Exit(rectangular, x, y, width, height);
                currentExit.setNextSceneId(idTarget);
                currentExit.setDestinyX(destinyX);
                currentExit.setDestinyY(destinyY);
                currentExit.setDestinyScale(destinyScale);
                currentExit.setTransitionTime(transitionTime);
                currentExit.setTransitionType(transitionType);
                currentExit.setHasNotEffects(notEffects);

                if (hasInfluence)
                {
                    InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight);
                    currentExit.setInfluenceArea(influenceArea);
                }

                foreach (XmlElement ell in el.SelectNodes("exit-look"))
                {
                    currentExitLook = new ExitLook();
                    string text       = ell.GetAttribute("text");
                    string cursorPath = ell.GetAttribute("cursor-path");
                    string soundPath  = ell.GetAttribute("sound-path");

                    currentExitLook.setCursorPath(cursorPath);
                    currentExitLook.setExitText(text);
                    currentExitLook.setSoundPath(soundPath);
                    currentExit.setDefaultExitLook(currentExitLook);
                }

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

                foreach (XmlElement ell in el.SelectNodes("point"))
                {
                    currentPoint = new Vector2(
                        ExParsers.ParseDefault(ell.GetAttribute("x"), 0),
                        ExParsers.ParseDefault(ell.GetAttribute("y"), 0));
                    currentExit.addPoint(currentPoint);
                }

                currentExit.setConditions(DOMParserUtility.DOMParse(el.SelectSingleNode("condition"), parameters)      as Conditions ?? new Conditions());
                currentExit.setEffects(DOMParserUtility.DOMParse(el.SelectSingleNode("effect"), parameters)            as Effects ?? new Effects());
                currentExit.setNotEffects(DOMParserUtility.DOMParse(el.SelectSingleNode("not-effect"), parameters) as Effects ?? new Effects());
                currentExit.setPostEffects(DOMParserUtility.DOMParse(el.SelectSingleNode("post-effect"), parameters) as Effects ?? new Effects());

                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 element.SelectNodes("next-scene"))
            {
                string idTarget       = el.GetAttribute("idTarget");
                int    x              = ExParsers.ParseDefault(el.GetAttribute("x"), int.MinValue),
                       y              = ExParsers.ParseDefault(el.GetAttribute("y"), int.MinValue),
                       transitionType = ExParsers.ParseDefault(el.GetAttribute("transitionType"), 0),
                       transitionTime = ExParsers.ParseDefault(el.GetAttribute("transitionTime"), 0);

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

                currentNextScene.setExitLook(currentExitLook);

                currentNextScene.setConditions(DOMParserUtility.DOMParse(el.SelectSingleNode("condition"), parameters) as Conditions ?? new Conditions());
                currentNextScene.setEffects(DOMParserUtility.DOMParse(el.SelectSingleNode("effect"), parameters)               as Effects ?? new Effects());
                currentNextScene.setPostEffects(DOMParserUtility.DOMParse(el.SelectSingleNode("post-effect"), parameters) as Effects ?? new Effects());
            }

            foreach (XmlElement el in element.SelectNodes("objects/object-ref"))
            {
                currentElementReference = parseElementReference(el, parameters);
                scene.addItemReference(currentElementReference);
            }

            foreach (XmlElement el in element.SelectNodes("characters/character-ref"))
            {
                currentElementReference = parseElementReference(el, parameters);
                scene.addCharacterReference(currentElementReference);
            }

            foreach (XmlElement el in element.SelectNodes("atrezzo/atrezzo-ref"))
            {
                currentElementReference = parseElementReference(el, parameters);
                scene.addAtrezzoReference(currentElementReference);
            }

            foreach (var activeArea in DOMParserUtility.DOMParse <ActiveArea>(element.SelectNodes("active-areas/active-area"), parameters).ToList())
            {
                scene.addActiveArea(activeArea);
            }

            foreach (var barrier in DOMParserUtility.DOMParse <Barrier>(element.SelectNodes("barriers/barrier"), parameters).ToList())
            {
                scene.addBarrier(barrier);
            }

            foreach (var trajectory in DOMParserUtility.DOMParse <Trajectory>(element.SelectNodes("trajectory"), parameters).ToList())
            {
                scene.setTrajectory(trajectory);
            }


            if (scene != null)
            {
                TrajectoryFixer.fixTrajectory(scene);
            }

            return(scene);
        }
コード例 #19
0
        public object DOMParse(XmlElement element, params object[] parameters)
        {
            var chapter = parameters [0] as Chapter;

            Cutscene cutscene;

            XmlNodeList
                endsgame   = element.SelectNodes("end-game"),
                nextsscene = element.SelectNodes("next-scene");

            string slidesceneId = element.GetAttribute("id");
            bool   initialScene = ExString.EqualsDefault(element.GetAttribute("start"), "yes", false);

            if (element.Name.Equals("slidescene"))
            {
                cutscene = new Slidescene(slidesceneId);
            }
            else
            {
                cutscene = new Videoscene(slidesceneId);
            }
            if (initialScene)
            {
                chapter.setTargetId(slidesceneId);
            }

            //XAPI ELEMENTS
            cutscene.setXApiClass(element.GetAttribute("class"));
            cutscene.setXApiType(element.GetAttribute("type"));
            //END OF XAPI

            cutscene.setTargetId(element.GetAttribute("idTarget"));
            cutscene.setPositionX(ExParsers.ParseDefault(element.GetAttribute("destinyX"), int.MinValue));
            cutscene.setPositionY(ExParsers.ParseDefault(element.GetAttribute("destinyY"), int.MinValue));
            cutscene.setTransitionType((TransitionType)ExParsers.ParseDefault(element.GetAttribute("transitionType"), 0));
            cutscene.setTransitionTime(ExParsers.ParseDefault(element.GetAttribute("transitionTime"), 0));

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

            cutscene.setEffects(DOMParserUtility.DOMParse(element.SelectSingleNode("effect"), parameters) as Effects ?? new Effects());

            if (cutscene is Videoscene)
            {
                ((Videoscene)cutscene).setCanSkip(ExString.EqualsDefault(element.GetAttribute("canSkip"), "yes", true));
            }

            string next = ExString.Default(element.GetAttribute("next"), "go-back");

            if (next.Equals("go-back"))
            {
                cutscene.setNext(Cutscene.GOBACK);
            }
            else if (next.Equals("new-scene"))
            {
                cutscene.setNext(Cutscene.NEWSCENE);
            }
            else if (next.Equals("end-chapter"))
            {
                cutscene.setNext(Cutscene.ENDCHAPTER);
            }

            // RESOURCES
            foreach (var res in DOMParserUtility.DOMParse <ResourcesUni> (element.SelectNodes("resources"), parameters))
            {
                cutscene.addResources(res);
            }

            for (int i = 0; i < endsgame.Count; i++)
            {
                cutscene.setNext(Cutscene.ENDCHAPTER);
            }

            foreach (XmlElement el in nextsscene)
            {
                var currentNextScene = new NextScene(el.GetAttribute("idTarget"),
                                                     ExParsers.ParseDefault(element.GetAttribute("destinyX"), int.MinValue),
                                                     ExParsers.ParseDefault(element.GetAttribute("destinyY"), int.MinValue));

                currentNextScene.setTransitionType((TransitionType)ExParsers.ParseDefault(element.GetAttribute("transitionType"), 0));
                currentNextScene.setTransitionTime(ExParsers.ParseDefault(element.GetAttribute("transitionTime"), 0));
                currentNextScene.setConditions(DOMParserUtility.DOMParse(el.SelectSingleNode("condition"), parameters) as Conditions ?? new Conditions());
                currentNextScene.setEffects(DOMParserUtility.DOMParse(el.SelectSingleNode("effect"), parameters) as Effects ?? new Effects());
                currentNextScene.setPostEffects(DOMParserUtility.DOMParse(el.SelectSingleNode("post-effect"), parameters) as Effects ?? new Effects());

                cutscene.addNextScene(currentNextScene);
            }

            return(cutscene);
        }
コード例 #20
0
        public object DOMParse(XmlElement element, params object[] parameters)
        {
            XmlNodeList points       = element.SelectNodes("point"),
                        descriptions = element.SelectNodes("description");
            XmlElement conditions    = element.SelectSingleNode("condition") as XmlElement,
                       actions       = element.SelectSingleNode("actions") as XmlElement,
                       documentation = element.SelectSingleNode("documentation") as XmlElement;

            string id          = ExString.Default(element.GetAttribute("id"), null);
            bool   rectangular = ExString.EqualsDefault(element.GetAttribute("rectangular"), "yes", true);

            int x      = ExParsers.ParseDefault(element.GetAttribute("x"), 0),
                y      = ExParsers.ParseDefault(element.GetAttribute("y"), 0),
                width  = ExParsers.ParseDefault(element.GetAttribute("width"), 0),
                height = ExParsers.ParseDefault(element.GetAttribute("height"), 0);

            bool hasInfluence    = ExString.EqualsDefault(element.GetAttribute("hasInfluenceArea"), "yes", false);
            int  influenceX      = ExParsers.ParseDefault(element.GetAttribute("influenceX"), 0),
                 influenceY      = ExParsers.ParseDefault(element.GetAttribute("influenceY"), 0),
                 influenceWidth  = ExParsers.ParseDefault(element.GetAttribute("influenceWidth"), 0),
                 influenceHeight = ExParsers.ParseDefault(element.GetAttribute("influenceHeight"), 0);


            var activeArea = new ActiveArea((id ?? generateId()), rectangular, x, y, width, height);

            switch (element.GetAttribute("behaviour"))
            {
            case "atrezzo":      activeArea.setBehaviour(Item.BehaviourType.ATREZZO);      break;

            case "first-action": activeArea.setBehaviour(Item.BehaviourType.FIRST_ACTION); break;

            default:             activeArea.setBehaviour(Item.BehaviourType.NORMAL);       break;
            }

            if (hasInfluence)
            {
                var influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight);
                activeArea.setInfluenceArea(influenceArea);
            }

            if (documentation != null)
            {
                activeArea.setDocumentation(documentation.InnerText);
            }

            activeArea.setDescriptions(DOMParserUtility.DOMParse <Description> (descriptions, parameters).ToList());

            foreach (XmlElement el in points)
            {
                activeArea.addVector2(
                    new Vector2(ExParsers.ParseDefault(el.GetAttribute("x"), 0),
                                ExParsers.ParseDefault(el.GetAttribute("y"), 0)));
            }

            if (actions != null)
            {
                activeArea.setActions(DOMParserUtility.DOMParse <Action>(actions.ChildNodes, parameters).ToList());
            }
            if (conditions != null)
            {
                activeArea.setConditions(DOMParserUtility.DOMParse(conditions, parameters) as Conditions ?? new Conditions());
            }

            return(activeArea);
        }
        public object DOMParse(XmlElement element, params object[] parameters)
        {
            AssessmentProfile profile = new AssessmentProfile();

            profile.setShowReportAtEnd(ExString.EqualsDefault(element.GetAttribute("show-report-at-end"), "yes", false));

            profile.setName(element.GetAttribute("name"));
            profile.setEmail(element.GetAttribute("send-to-email"));
            profile.setSendByEmail(!string.IsNullOrEmpty(profile.getEmail()));
            profile.setScorm12(ExString.EqualsDefault(element.GetAttribute("scorm12"), "yes", false));
            profile.setScorm2004(ExString.EqualsDefault(element.GetAttribute("scorm2004"), "yes", false));

            var smtpConfig = element.SelectSingleNode("smtp-config") as XmlElement;

            if (smtpConfig != null)
            {
                profile.setSmtpSSL(ExString.EqualsDefault(element.GetAttribute("smtp-ssl"), "yes", false));
                profile.setSmtpServer(smtpConfig.GetAttribute("smtp-server"));
                profile.setSmtpPort(smtpConfig.GetAttribute("smtp-port"));
                profile.setSmtpUser(smtpConfig.GetAttribute("smtp-user"));
                profile.setSmtpPwd(smtpConfig.GetAttribute("smtp-pwd"));
            }

            // NORMAL ASSESMENT RULES
            foreach (XmlElement ell in element.SelectNodes("assessment-rule"))
            {
                var currentAssessmentRule = new AssessmentRule("", 0, false);
                fillAssesmentRule(ell, currentAssessmentRule, parameters);
                profile.addRule(currentAssessmentRule);
            }

            // TIMED ASSESMENT RULES
            foreach (XmlElement ell in element.SelectNodes("timed-assessment-rule"))
            {
                bool usesEndConditions = ExString.EqualsDefault(element.GetAttribute("usesEndConditions"), "yes", false);

                var tRule = new TimedAssessmentRule("", 0, false);
                fillAssesmentRule(ell, tRule, parameters);

                if (usesEndConditions || tRule.isRepeatRule())
                {
                    tRule.setUsesEndConditions(usesEndConditions);
                }

                tRule.setInitConditions(DOMParserUtility.DOMParse(element.SelectSingleNode("init-condition"), parameters)                      as Conditions ?? new Conditions());
                tRule.setEndConditions(DOMParserUtility.DOMParse(element.SelectSingleNode("end-condition"), parameters)                        as Conditions ?? new Conditions());

                foreach (XmlElement ell_ in element.SelectNodes("assessEffect"))
                {
                    int timeMin = ExParsers.ParseDefault(ell_.GetAttribute("time-min"), int.MinValue);
                    int timeMax = ExParsers.ParseDefault(ell_.GetAttribute("time-max"), int.MinValue);

                    if (timeMin != int.MinValue && timeMax != int.MaxValue)
                    {
                        tRule.addEffect(timeMin, timeMax);
                    }
                    else
                    {
                        tRule.addEffect();
                    }
                }

                profile.addRule(tRule);
            }

            return(profile);
        }
コード例 #22
0
        public object DOMParse(XmlElement element, params object[] parameters)
        {
            XmlNodeList
                resourcess     = element.SelectNodes("resources"),
                documentations = element.SelectNodes("documentations"),
                texts          = element.SelectNodes("text"),
                pagess         = element.SelectNodes("pages"),
                pages;

            string bookId = "";
            string xPrevious = "", xNext = "", yPrevious = "", yNext = "";

            bookId    = element.GetAttribute("id");
            xPrevious = element.GetAttribute("xPreviousPage");
            xNext     = element.GetAttribute("xNextPage");
            yPrevious = element.GetAttribute("yPreviousPage");
            yNext     = element.GetAttribute("yNextPage");

            Book book = new Book(bookId);

            if (xPrevious != "" && yPrevious != "")
            {
                try
                {
                    float x = float.Parse(xPrevious);
                    float y = float.Parse(yPrevious);
                    book.setPreviousPageVector2(new Vector2(x, y));
                }
                catch
                {
                    // Number in XML is wrong -> Do nothing
                }
            }
            if (xNext != "" && yNext != "")
            {
                try
                {
                    float x = float.Parse(xNext);
                    float y = float.Parse(yNext);
                    book.setNextPageVector2(new Vector2(x, y));
                }
                catch
                {
                    // Number in XML is wrong -> Do nothing
                }
            }


            // RESOURCES
            foreach (var res in DOMParserUtility.DOMParse <ResourcesUni>(resourcess, parameters))
            {
                book.addResources(res);
            }


            foreach (XmlElement el in documentations)
            {
                string currentstring = el.InnerText;
                book.setDocumentation(currentstring.ToString().Trim());
            }

            foreach (XmlElement text in texts)
            {
                book.setType(Book.TYPE_PARAGRAPHS);
                foreach (XmlNode child in text.ChildNodes)
                {
                    if (child is XmlText)
                    {
                        var childText = child.InnerText;
                        if (!string.IsNullOrEmpty(childText.Replace("\t\n", "")))
                        {
                            book.addParagraph(new BookParagraph(BookParagraph.TEXT, childText.Trim().Replace("\t", "")));
                        }
                    }
                    else if (child is XmlElement)
                    {
                        var paragraph = DOMParserUtility.DOMParse(child, parameters) as BookParagraph;
                        if (paragraph != null)
                        {
                            book.addParagraph(paragraph);
                        }
                    }
                }
            }

            foreach (XmlElement el in pagess)
            {
                book.setType(Book.TYPE_PAGES);

                pages = el.SelectNodes("page");

                foreach (XmlElement ell in pages)
                {
                    string uri          = "";
                    int    type         = BookPage.TYPE_URL;
                    int    margin       = 0;
                    int    marginEnd    = 0;
                    int    marginTop    = 0;
                    int    marginBottom = 0;
                    bool   scrollable   = false;

                    uri = ell.GetAttribute("uri");

                    switch (ell.GetAttribute("type"))
                    {
                    case "resource": type = BookPage.TYPE_RESOURCE; break;

                    case "image": type = BookPage.TYPE_IMAGE; break;
                    }

                    scrollable   = ExString.EqualsDefault(ell.GetAttribute("scrollable"), "yes", false);
                    margin       = ExParsers.ParseDefault(ell.GetAttribute("margin"), 0);
                    marginEnd    = ExParsers.ParseDefault(ell.GetAttribute("marginEnd"), 0);
                    marginTop    = ExParsers.ParseDefault(ell.GetAttribute("marginTop"), 0);
                    marginBottom = ExParsers.ParseDefault(ell.GetAttribute("marginBottom"), 0);

                    book.addPage(uri, type, margin, marginEnd, marginTop, marginBottom, scrollable);
                }
            }

            return(book);
        }
        private static void ParseGui(AdventureData adventureData, XmlElement gui, List <Incidence> incidences)
        {
            if (gui == null)
            {
                return;
            }

            var guiType = ExString.Default(gui.GetAttribute("type"), "contextual");

            switch (guiType)
            {
            case "traditional": adventureData.setGUIType(DescriptorData.GUI_TRADITIONAL); break;

            case "contextual":  adventureData.setGUIType(DescriptorData.GUI_CONTEXTUAL);  break;

            default: incidences.Add(Incidence.createDescriptorIncidence("Unknown GUIType type: " + guiType, null)); break;
            }

            var isCustomized = ExString.EqualsDefault(gui.GetAttribute("customized"), "yes", false);

            adventureData.setGUI(adventureData.getGUIType(), isCustomized);

            var inventoryPosition = ExString.Default(gui.GetAttribute("inventoryPosition"), "top_bottom");

            switch (inventoryPosition)
            {
            case "none": adventureData.setInventoryPosition(DescriptorData.INVENTORY_NONE); break;

            case "top_bottom": adventureData.setInventoryPosition(DescriptorData.INVENTORY_TOP_BOTTOM); break;

            case "top": adventureData.setInventoryPosition(DescriptorData.INVENTORY_TOP); break;

            case "bottom": adventureData.setInventoryPosition(DescriptorData.INVENTORY_BOTTOM); break;

            case "fixed_top": adventureData.setInventoryPosition(DescriptorData.INVENTORY_FIXED_TOP); break;

            case "fixed_bottom": adventureData.setInventoryPosition(DescriptorData.INVENTORY_FIXED_BOTTOM); break;

            case "icon":
                adventureData.setInventoryPosition(DescriptorData.INVENTORY_ICON_FREEPOS);
                var scale = gui.GetAttribute("inventoryScale");
                adventureData.setInventoryScale(ExParsers.ParseDefault(gui.GetAttribute("inventoryScale"), CultureInfo.InvariantCulture, 0.2f));
                var xCoord = ExParsers.ParseDefault(gui.GetAttribute("inventoryX"), CultureInfo.InvariantCulture, 675f);
                var yCoord = ExParsers.ParseDefault(gui.GetAttribute("inventoryY"), CultureInfo.InvariantCulture, 550f);
                adventureData.setInventoryCoords(new UnityEngine.Vector2(xCoord, yCoord));
                adventureData.setInventoryImage(ExString.Default(gui.GetAttribute("inventoryImage"), SpecialAssetPaths.ASSET_DEFAULT_INVENTORY));
                break;

            default: incidences.Add(Incidence.createDescriptorIncidence("Unknown inventoryPosition type: " + inventoryPosition, null)); break;
            }

            XmlNodeList cursors = gui.SelectNodes("cursors/cursor");

            foreach (XmlElement cursor in cursors)
            {
                string type         = ExString.Default(cursor.GetAttribute("type"), ""),
                                uri = ExString.Default(cursor.GetAttribute("uri"), "");

                adventureData.addCursor(type, uri);
            }

            XmlNodeList buttons = gui.SelectNodes("buttons/button");

            foreach (XmlElement button in buttons)
            {
                string type            = ExString.Default(button.GetAttribute("type"), ""),
                                uri    = ExString.Default(button.GetAttribute("uri"), ""),
                                action = ExString.Default(button.GetAttribute("action"), "");

                adventureData.addButton(action, type, uri);
            }

            XmlNodeList arrows = gui.SelectNodes("cursors/cursor");

            foreach (XmlElement arrow in arrows)
            {
                string type         = ExString.Default(arrow.GetAttribute("type"), ""),
                                uri = ExString.Default(arrow.GetAttribute("uri"), "");

                adventureData.addArrow(type, uri);
            }
        }
コード例 #24
0
        private void parseLines(ConversationNode node, XmlElement lines, params object[] parameters)
        {
            string tmpArgVal = "";

            currentLinks = new List <int>();
            bool addline           = true;
            bool timeoutConditions = false;

            foreach (XmlElement ell in lines.ChildNodes)
            {
                addline = true;
                // If there is a "keepShowing" attribute, store its value
                keepShowingLine = ExString.EqualsDefault(ell.GetAttribute("keepShowing"), "yes", false);

                if (ell.Name == "speak-player")
                {
                    // Store the read string into the current node, and then delete the string. The trim is performed so we
                    // don't have to worry with indentations or leading/trailing spaces


                    conversationLine = new ConversationLine(ConversationLine.PLAYER, GetText(ell));
                    conversationLine.setKeepShowing(keepShowingLine);
                    //XAPI ELEMENTS
                    conversationLine.setXApiCorrect("true".Equals(ell.GetAttribute("correct")));
                    //END OF XAPI
                    // RESOURCES
                    foreach (var res in DOMParserUtility.DOMParse <ResourcesUni>(ell.SelectNodes("resources"), parameters))
                    {
                        conversationLine.addResources(res);
                    }
                }
                else if (ell.Name == "speak-char")
                {
                    // If it is a non-player character line, store the character name and audio path (if present)
                    // Set default name to "NPC"
                    characterName = "NPC";
                    // If there is a "idTarget" attribute, store it
                    characterName = ell.GetAttribute("idTarget");

                    // Store the read string into the current node, and then delete the string. The trim is performed so we
                    // don't have to worry with indentations or leading/trailing spaces
                    conversationLine = new ConversationLine(characterName, GetText(ell));
                    conversationLine.setKeepShowing(keepShowingLine);
                    // RESOURCES
                    foreach (var res in DOMParserUtility.DOMParse <ResourcesUni>(ell.SelectNodes("resources"), parameters))
                    {
                        conversationLine.addResources(res);
                    }
                }
                else if (ell.Name == "condition")
                {
                    addline = false;
                    var currentConditions = DOMParserUtility.DOMParse(ell, parameters) as Conditions ?? new Conditions();

                    if (timeoutConditions)
                    {
                        ((OptionConversationNode)currentNode).TimeoutConditions = currentConditions;
                    }
                    else
                    {
                        currentNode.getLine(currentNode.getLineCount() - 1).setConditions(currentConditions);
                    }
                }
                else if (ell.Name == "child")
                {
                    addline   = false;
                    tmpArgVal = ell.GetAttribute("nodeindex");
                    if (!string.IsNullOrEmpty(tmpArgVal))
                    {
                        // Get the child node index, and store it
                        int childIndex = int.Parse(tmpArgVal);
                        currentLinks.Add(childIndex);
                    }
                }
                else if (ell.Name == "timeout")
                {
                    ((OptionConversationNode)currentNode).Timeout = ExParsers.ParseDefault(GetText(ell), CultureInfo.InvariantCulture, 10f);
                    timeoutConditions = true;
                    addline           = false;
                }
                else
                {
                    addline = false;
                }

                if (addline)
                {
                    node.addLine(conversationLine);
                }
            }
        }
コード例 #25
0
        public object DOMParse(XmlElement element, params object[] parameters)
        {
            XmlNode effects;
            XmlNode end_conversation;

            string tmpArgVal;

            // Store the name
            conversationName = "";
            tmpArgVal        = element.GetAttribute("id");
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                conversationName = tmpArgVal;
            }

            graphNodes = new List <ConversationNode>();
            nodeLinks  = new List <List <int> >();

            foreach (XmlElement el in element)
            {
                //If there is a "editor-x" and "editor-y" attributes
                editorX         = Mathf.Max(-1, ExParsers.ParseDefault(el.GetAttribute("editor-x"), -1));
                editorY         = Mathf.Max(-1, ExParsers.ParseDefault(el.GetAttribute("editor-y"), -1));
                editorCollapsed = ExString.EqualsDefault(el.GetAttribute("editor-collapsed"), "yes", false);

                //If there is a "waitUserInteraction" attribute, store if the lines will wait until user interacts
                keepShowingDialogue = ExString.EqualsDefault(el.GetAttribute("waitUserInteraction"), "yes", false);

                // Node effects
                end_conversation = el.SelectSingleNode("end-conversation");
                if (end_conversation != null)
                {
                    effects = end_conversation.SelectSingleNode("effect");
                }
                else
                {
                    effects = el.SelectSingleNode("effect");
                }

                var parsedEffects = DOMParserUtility.DOMParse(effects, parameters) as Effects ?? new Effects();

                if (el.Name == "dialogue-node")
                {
                    currentNode = new DialogueConversationNode(keepShowingDialogue);
                }
                else if (el.Name == "option-node")
                {
                    random         = ExString.EqualsDefault(el.GetAttribute("random"), "yes", false);
                    showUserOption = ExString.EqualsDefault(el.GetAttribute("showUserOption"), "yes", false);
                    keepShowing    = ExString.EqualsDefault(el.GetAttribute("keepShowing"), "yes", false);
                    preListening   = ExString.EqualsDefault(el.GetAttribute("preListening"), "yes", false) || editorX >= 0 || editorY >= 0;

                    var optionConversationNode = new OptionConversationNode(random, keepShowing, showUserOption, preListening)
                    {
                        Horizontal     = ExString.EqualsDefault(el.GetAttribute("horizontal"), "yes", false),
                        MaxElemsPerRow = ExParsers.ParseDefault(el.GetAttribute("max-elements-per-row"), -1),
                        Alignment      = el.HasAttribute("alignment") ? ExParsers.ParseEnum <TextAnchor>(el.GetAttribute("alignment")) : TextAnchor.UpperCenter
                    };
                    currentNode = optionConversationNode;

                    //XAPI ELEMENTS
                    optionConversationNode.setXApiQuestion(el.GetAttribute("question"));
                    //END OF XAPI
                }

                if (currentNode != null)
                {
                    // Node editor properties
                    currentNode.setEditorX(editorX);
                    currentNode.setEditorY(editorY);
                    currentNode.setEditorCollapsed(editorCollapsed);

                    // Create a new vector for the links of the current node
                    currentLinks = new List <int>();
                    parseLines(currentNode, el, parameters);
                    currentNode.setEffects(parsedEffects);

                    // Add the current node to the node list, and the set of children references into the node links
                    graphNodes.Add(currentNode);
                    nodeLinks.Add(currentLinks);
                }
            }

            setNodeLinks();
            return(new GraphConversation(conversationName, graphNodes[0]));
        }