Пример #1
0
        public void LoadData(string dataDirectory, bool defaultToCompiled = true)
        {
            _dataDirectory = dataDirectory;

            LuaContext?.Dispose();
            LuaContext = new Lua();
            var dataSource = new JObject();

            var files        = Directory.GetFiles(dataDirectory, "*.*", SearchOption.AllDirectories);
            var jsonFinished = false;

            if (defaultToCompiled)
            {
                var compiledFile = files.FirstOrDefault(x => x.EndsWith("compiled.json"));

                if (compiledFile != null)
                {
                    var source = File.ReadAllText(compiledFile);
                    dataSource.Merge(JObject.Parse(source));
                    jsonFinished = true;
                }
            }

            foreach (string file in files)
            {
                var ext = Path.GetExtension(file);
                if (ext == ".lua")
                {
                    LuaContext.DoFile(file);
                }
                else if (!jsonFinished && ext == ".json")
                {
                    var text = File.ReadAllText(file);
                    dataSource.Merge(JObject.Parse(text));
                }
            }

            GameData = dataSource.ToObject <GameDataObject>();

            foreach (var skillTree in GameData.TalentTrees)
            {
                skillTree.Hellforge = this;
                foreach (var node in skillTree.Nodes)
                {
                    node.Graph = skillTree;
                }
            }

            foreach (var affix in GameData.Affixes)
            {
                if (!string.IsNullOrEmpty(affix.Inherits))
                {
                    var parent = GameData.Affixes.First(x => x.Name == affix.Inherits);
                    if (parent != null)
                    {
                        affix.Inherit(parent);
                    }
                }
            }
        }
Пример #2
0
        private void DocumentActivated(Document doc)
        {
            var            selEnt = EntityTypeList.SelectedItem as GameDataObject;
            var            sel = selEnt == null ? null : selEnt.Name;
            var            def = doc.Game.DefaultPointEntity;
            GameDataObject reselect = null, redef = null;

            EntityTypeList.Items.Clear();
            foreach (var gdo in doc.GameData.Classes.Where(x => x.ClassType == ClassType.Point).OrderBy(x => x.Name.ToLowerInvariant()))
            {
                EntityTypeList.Items.Add(gdo);
                if (String.Equals(sel, gdo.Name, StringComparison.InvariantCultureIgnoreCase))
                {
                    reselect = gdo;
                }
                if (String.Equals(def, gdo.Name, StringComparison.InvariantCultureIgnoreCase))
                {
                    redef = gdo;
                }
            }
            if (reselect == null && redef == null)
            {
                redef = doc.GameData.Classes
                        .Where(x => x.ClassType == ClassType.Point)
                        .OrderBy(x => x.Name.StartsWith("info_player_start") ? 0 : 1)
                        .FirstOrDefault();
            }
            EntityTypeList.SelectedItem = reselect ?? redef;
            SelectedEntityChanged(null, null);
        }
Пример #3
0
        private bool OnGameData(GameDataObject lcds)
        {
            draftData = lcds.Content;

            if (draftData.AfkCheckState?.Inventory != null)
            {
                var src = draftData.AfkCheckState.Inventory;
                this.inventory = new Model.Inventory {
                    AvailableSpells = src.SpellIds,
                    PickableChamps  = src.LastSelectedSkins.Keys.Select(int.Parse).ToList(),
                    BannableChamps  = src.AllChampionIds
                };
            }

            switch (lcds.Content.CurrentPhase)
            {
            case Phase.DRAFT_PREMADE:
                OnAdvancedToLobby();
                break;

            case Phase.MATCHMAKING:
            case Phase.AFK_CHECK:
                OnAdvancedToMatchmaking();
                break;

            case Phase.CHAMPION_SELECT:
                if (state.Chatroom == Guid.Empty)
                {
                    state.Chatroom = rooms.JoinDraft(draftData.ChampSelectState);
                }

                state.IsBlue    = draftData.ChampSelectState.MyCellId < 5;
                state.Inventory = this.inventory;
                state.Remaining = draftData.ChampSelectState.CurrentRemainingMillis;
                state.Turn      = draftData.ChampSelectState.CurrentActionIndex;

                state.AlliedBans = draftData.ChampSelectState.Bans.AlliedBans;
                state.EnemyBans  = draftData.ChampSelectState.Bans.EnemyBans;

                state.Phase = GetPhase(draftData.ChampSelectState);

                var current      = draftData.ChampSelectState.GetCurrentAction();
                var tradesByCell = draftData.ChampSelectState.Trades.ToDictionary(t => t.CellId);
                draftMembers = new Dictionary <object, Cell>();

                state.Allies = (from c in draftData.ChampSelectState.Cells.AlliedTeam
                                orderby c.CellId
                                select GetMember(c, current, tradesByCell)).ToList();

                state.Enemies = (from c in draftData.ChampSelectState.Cells.EnemyTeam
                                 orderby c.CellId
                                 select GetMember(c, current, tradesByCell)).ToList();

                OnStateChanged();
                break;
            }

            return(true);
        }
Пример #4
0
    private void initRefs()
    {
        gameDataObject = GameObject.FindObjectOfType<GameDataObject>();

        ZoneInfoText = GameObject.FindGameObjectWithTag("PauseZoneInfo").GetComponent<Text>();
        GlobalFlagsText = GameObject.FindGameObjectWithTag("PauseGlobalFlagInfo").GetComponent<Text>();
        InventoryText = InventoryTextGameObject.GetComponent<Text>();

        panelRectTransform = gameObject.GetComponent<RectTransform>();
    }
Пример #5
0
    private void initRefs()
    {
        gameDataObject = GameObject.FindObjectOfType <GameDataObject>();

        ZoneInfoText    = GameObject.FindGameObjectWithTag("PauseZoneInfo").GetComponent <Text>();
        GlobalFlagsText = GameObject.FindGameObjectWithTag("PauseGlobalFlagInfo").GetComponent <Text>();
        InventoryText   = InventoryTextGameObject.GetComponent <Text>();

        panelRectTransform = gameObject.GetComponent <RectTransform>();
    }
    public void UpdateInfo(GameDataObject gameObject, InfoTree infoTree)
    {
        if (infoTree != null)
        {
            InfoTreeNode infoNode = (InfoTreeNode)infoTree.getNode(infoTree.currentIndex);
            infoNode.SelectNode(infoTree);
            UIHelper.UpdateTextComponent(TreeInfoPanel, "TreeInfoTitle", infoNode.content.nodeName);
            UIHelper.UpdateTextComponent(TreeInfoPanel, "TreeInfoText", infoNode.content.text);

            gameObject.runActions(infoNode.actionList);
        }
    }
Пример #7
0
        protected override void OnStart(string[] args)
        {
            // TODO: Add code here to start your service.
            FileProcessing.ImportSettting();
            GameDataObject gameDataObject = new GameDataObject();

            Connector.EstablishConnection(gameDataObject);
            DayActiveController.RegisterGameMetaData(gameDataObject);
            DayActiveController.BindGameEvent(gameDataObject);
            DayActiveController.StartGameHeartBeatTimer();
            DayActiveController.StartMonitoringTimer(gameDataObject);
        }
    public void UpdateInfo(GameDataObject gameObject, InfoTree infoTree)
    {
        if (infoTree != null)
        {
            InfoTreeNode infoNode = (InfoTreeNode)infoTree.getNode(infoTree.currentIndex);
            infoNode.SelectNode(infoTree);
            UIHelper.UpdateTextComponent(TreeInfoPanel, "TreeInfoTitle", infoNode.content.nodeName);
            UIHelper.UpdateTextComponent(TreeInfoPanel, "TreeInfoText", infoNode.content.text);

            gameObject.runActions(infoNode.actionList);
        }
    }
Пример #9
0
        private void CreateEntity(Coordinate origin, GameDataObject gd = null)
        {
            if (gd == null)
            {
                gd = _sidebarPanel.GetSelectedEntity();
            }
            if (gd == null)
            {
                return;
            }

            var col    = gd.Behaviours.Where(x => x.Name == "color").ToArray();
            var colour = col.Any() ? col[0].GetColour(0) : Colour.GetDefaultEntityColour();

            var entity = new Entity(Document.Map.IDGenerator.GetNextObjectID())
            {
                EntityData = new EntityData(gd),
                ClassName  = gd.Name,
                Colour     = colour,
                Origin     = origin
            };

            for (int x = 0; x < entity.EntityData.Properties.Count(); x++)
            {
                if (entity.EntityData.Properties[x].Key == "%name%")
                {
                    var v = Document.Map.WorldSpawn.MetaData.Get <Dictionary <string, UInt32> >("EntityCounts");
                    v[gd.Name] += 1;
                    entity.EntityData.Properties[x].Value = gd.Name + v[gd.Name].ToString();
                    //entity.EntityData.Properties[x] = Document.Map.WorldSpawn.MetaData.Get<string>["EntityCounts"];
                }
            }

            if (Select.SelectCreatedEntity)
            {
                entity.IsSelected = true;
            }

            IAction action = new Create(Document.Map.WorldSpawn.ID, entity);

            if (Select.SelectCreatedEntity && Select.DeselectOthersWhenSelectingCreation)
            {
                action = new ActionCollection(new ChangeSelection(new MapObject[0], Document.Selection.GetSelectedObjects()), action);
            }

            Document.PerformAction("Create entity: " + gd.Name, action);
            if (Select.SwitchToSelectAfterEntity)
            {
                Mediator.Publish(HotkeysMediator.SwitchTool, HotkeyTool.Selection);
            }
        }
    public static bool OpenEditor(int instanceId, int line)
    {
        // Check if the double clicked asset is an asset of type GameDataObject
        GameDataObject obj = EditorUtility.InstanceIDToObject(instanceId) as GameDataObject;

        // If it is Open the Editor Window
        if (obj != null)
        {
            GameDataEditorWindow.Open(obj);
            return(true);
        }

        return(false);
    }
Пример #11
0
        /// <summary>
        /// Populate the flags list using the given the source flags data of the context.
        /// </summary>
        /// <param name="cls">The game data object. If null, the list will remain blank.</param>
        /// <param name="flags">A list of flag values for the current context</param>
        private void PopulateFlags(GameDataObject cls, List <int> flags)
        {
            FlagsTable.Items.Clear();

            var flagsProp = cls?.Properties.FirstOrDefault(x => x.Name == "spawnflags");

            if (flagsProp == null)
            {
                return;
            }

            foreach (var option in flagsProp.Options.OrderBy(x => int.TryParse(x.Key, out int v) ? v : 0))
            {
                var key        = int.Parse(option.Key);
                var numChecked = flags.Count(x => (x & key) > 0);
                var cs         = numChecked == flags.Count ? CheckState.Checked : (numChecked == 0 ? CheckState.Unchecked : CheckState.Indeterminate);
                FlagsTable.Items.Add(new FlagHolder(option, cs), cs);
            }
        }
Пример #12
0
        private bool OnGameData(GameDataObject lcds)
        {
            if (lcds != null)
            {
                draftData = lcds.Content;
            }

            switch (lcds.Content.CurrentPhase)
            {
            case Phase.DRAFT_PREMADE:
                if (state != null)
                {
                    state = null;
                    OnStateChanged();
                    OnAdvancedToLobby();
                }
                break;

            case Phase.MATCHMAKING:
                state = new Model.MatchmakingState {
                    Actual   = draftData.MatchmakingState.TimeInMatchmaking,
                    Estimate = draftData.MatchmakingState.EstimatedMatchmakingTime
                };
                OnStateChanged();
                break;

            case Phase.AFK_CHECK:
                state.AfkCheck = new AfkCheck {
                    Accepted  = draftData.AfkCheckState.IsReady ? new bool?(true) : null,
                    Duration  = draftData.AfkCheckState.MaxDuration,
                    Remaining = draftData.AfkCheckState.RemainingDuration
                };
                OnStateChanged();
                break;

            case Phase.CHAMPION_SELECT:
                OnAdvancedToChampSelect();
                break;
            }

            return(true);
        }
Пример #13
0
        public void DebugDraft()
        {
            var file  = @"C:\Users\max\desktop\full draft game.txt";
            var lines = File.ReadAllLines(file);

            new Thread(() => {
                int index = 0;
                while (true)
                {
                    while (!lines[index].StartsWith("  {\"counter\":"))
                    {
                        index++;
                    }
                    var lcds = new GameDataObject("", "OK", (JSONObject)JSONParser.Parse(lines[index]));
                    Thread.Sleep(1000);
                    session.HandleMessage(lcds);
                    index++;
                }
            }).Start();
        }
Пример #14
0
        private void CreateEntity(Coordinate origin, GameDataObject gd = null)
        {
            if (gd == null)
            {
                gd = _sidebarPanel.GetSelectedEntity();
            }
            if (gd == null)
            {
                return;
            }

            var col    = gd.Behaviours.Where(x => x.Name == "color").ToArray();
            var colour = col.Any() ? col[0].GetColour(0) : Colour.GetDefaultEntityColour();

            var entity = new Entity(Document.Map.IDGenerator.GetNextObjectID())
            {
                EntityData = new EntityData(gd),
                ClassName  = gd.Name,
                Colour     = colour,
                Origin     = origin
            };

            if (Select.SelectCreatedEntity)
            {
                entity.IsSelected = true;
            }

            IAction action = new Create(Document.Map.WorldSpawn.ID, entity);

            if (Select.SelectCreatedEntity && Select.DeselectOthersWhenSelectingCreation)
            {
                action = new ActionCollection(new ChangeSelection(new MapObject[0], Document.Selection.GetSelectedObjects()), action);
            }

            Document.PerformAction("Create entity: " + gd.Name, action);
            if (Select.SwitchToSelectAfterEntity)
            {
                Mediator.Publish(HotkeysMediator.SwitchTool, HotkeyTool.Selection);
            }
        }
Пример #15
0
        public void RefreshEntities(Document doc)
        {
            if (doc == null)
            {
                return;
            }

            EntityTypeList.BeginUpdate();

            var selEnt = EntityTypeList.SelectedItem as GameDataObject;

            EntityTypeList.Items.Clear();
            var            sel = selEnt == null ? null : selEnt.Name;
            var            def = doc.Game.DefaultPointEntity;
            GameDataObject reselect = null, redef = null;

            foreach (var gdo in doc.GameData.Classes.Where(x => x.ClassType == ClassType.Point).OrderBy(x => x.Name.ToLowerInvariant()))
            {
                EntityTypeList.Items.Add(gdo);
                if (String.Equals(sel, gdo.Name, StringComparison.OrdinalIgnoreCase))
                {
                    reselect = gdo;
                }
                if (String.Equals(def, gdo.Name, StringComparison.OrdinalIgnoreCase))
                {
                    redef = gdo;
                }
            }
            if (reselect == null && redef == null)
            {
                redef = doc.GameData.Classes
                        .Where(x => x.ClassType == ClassType.Point)
                        .OrderBy(x => x.Name.StartsWith("info_player_start") ? 0 : 1)
                        .FirstOrDefault();
            }
            EntityTypeList.SelectedItem = reselect ?? redef;

            EntityTypeList.EndUpdate();
        }
Пример #16
0
    void Start()
    {
        gameData            = Resources.Load <GameDataObject>("Configs/GameData");
        score               = 0;
        scoreIncrease       = 1;
        clickerLevel        = 0;
        autoclickerLevel    = 0;
        autoclickerIncrease = 1;
        playerName          = "Player1234";
        OnScoreUpdate();
        ChangeAutoClickerCountText();
        ChangeAutoclickerLevelText();
        ShowPlayerName();
        SetSlidersVisibility(true);

        //GameDataObject[] configs = Resources.LoadAll<GameDataObject>("Configs");

        //foreach(GameDataObject config in configs)
        //{
        //Debug.Log(config.name);
        //}
        //SpawnCubes();
    }
Пример #17
0
        private bool OnGameData(GameDataObject lcds)
        {
            if (lcds != null)
            {
                draftData = lcds.Content;
            }

            switch (lcds.Content.CurrentPhase)
            {
            case Phase.DRAFT_PREMADE:

                if (state.Chatroom == Guid.Empty)
                {
                    state.Chatroom = rooms.JoinDraft(draftData.PremadeState);
                }

                state.Members = new List <LobbyMember>();
                foreach (var slot in draftData.PremadeState.Slots)
                {
                    var member = new LobbyMember(slot);
                    if (slot.SlotId == draftData.PremadeState.MySlot)
                    {
                        state.Me = member;
                    }
                    state.Members.Add(member);
                }

                state.CanMatch = draftData.PremadeState.ReadyToMatchmake;
                OnStateChanged();
                break;

            case Phase.MATCHMAKING:
                OnAdvancedToMatchmaking();
                break;
            }
            return(true);
        }
Пример #18
0
 private void loadGameData()
 {
     gameDataObject = GameObject.FindObjectOfType<GameDataObject>();
 }
Пример #19
0
    public static void Open(GameDataObject dataObject)
    {
        GameDataEditorWindow window = GetWindow <GameDataEditorWindow>("Game Data Editor");

        window.serializedObject = new SerializedObject(dataObject);
    }
Пример #20
0
        protected override void SaveToStream(Stream stream, DataStructures.MapObjects.Map map, DataStructures.GameData.GameData gameData, TextureCollection textureCollection)
        {
            BinaryWriter writer = new BinaryWriter(stream);

            writer.WriteFixedLengthString(Encoding.ASCII, 3, "CBR");
            writer.Write(revision);

            // Lightmaps
            bool lightmapped = textureCollection != null && textureCollection.Lightmaps[0] != null;

            if (lightmapped)
            {
                writer.Write((byte)Lightmapped.Fully); // TODO: Determine changes from last render
                for (int i = 0; i < 4; i++)
                {
                    long prevPos = writer.Seek(0, SeekOrigin.Current);
                    writer.Write(0);
                    writer.Flush();
                    textureCollection.Lightmaps[i].Save(stream, ImageFormat.Png);
                    int imageOffset = (int)(writer.Seek(0, SeekOrigin.Current) - prevPos);
                    writer.Seek(-imageOffset, SeekOrigin.Current);
                    writer.Write(imageOffset - sizeof(int));
                    writer.Seek(0, SeekOrigin.End);
                }
            }
            else
            {
                writer.Write((byte)Lightmapped.No);
            }

            // Texture dictionary
            Dictionary <string, int> texDic     = new Dictionary <string, int>();
            StringBuilder            texBuilder = new StringBuilder();
            int texCount = 0;
            IEnumerator <string> textures = map.GetAllTextures().GetEnumerator();

            while (textures.MoveNext())
            {
                texBuilder.Append(textures.Current);
                texBuilder.Append('\0');
                texDic.Add(textures.Current, texCount);
                texCount++;
            }
            writer.Write(texCount);
            writer.WriteFixedLengthString(Encoding.UTF8, texBuilder.Length, texBuilder.ToString());

            // Solids
            List <MapObject> solids = map.WorldSpawn.Find(x => x is Solid);

            writer.Write(solids.Count);
            foreach (Solid s in solids)
            {
                writer.Write(s.Faces.Count);
                foreach (Face f in s.Faces)
                {
                    writer.Write(texDic[f.Texture.Name]);
                    writer.WriteCoordinate(f.Texture.UAxis);
                    writer.WriteCoordinate(f.Texture.VAxis);
                    writer.Write(f.Texture.XShift);
                    writer.Write(f.Texture.YShift);
                    writer.Write(f.Texture.XScale);
                    writer.Write(f.Texture.YScale);
                    writer.Write(f.Texture.Rotation);
                    writer.Write(f.Vertices.Count);
                    foreach (Vertex v in f.Vertices)
                    {
                        writer.WriteCoordinate(v.Location);
                        if (lightmapped)
                        {
                            writer.Write(v.LMU);
                            writer.Write(v.LMV);
                            writer.Write((float)v.TextureU);
                            writer.Write((float)v.TextureV);
                        }
                    }
                }
            }

            // Entities
            ISet <string>         foundEntityTypes = new HashSet <string>();
            List <GameDataObject> entityTypes      = new List <GameDataObject>();
            List <MapObject>      entites          = map.WorldSpawn.Find(x => x is Entity && x.ClassName != "");

            foreach (Entity e in entites)
            {
                Console.WriteLine(e.ClassName);
                Console.WriteLine(e.GameData.Name);
                if (!foundEntityTypes.Contains(e.ClassName))
                {
                    GameDataObject gdo = gameData.Classes.Find(x => x.Name == e.ClassName);
                    entityTypes.Add(gdo);
                    foundEntityTypes.Add(gdo.Name);
                }
            }
            // Move brush entities to front
            entityTypes.Sort((x, y) => (x.ClassType == ClassType.Solid ? -1 : 0));
            // For later use with groups
            Dictionary <Entity, int> entityIndices = new Dictionary <Entity, int>();
            int  entityIndicesCounter = 0;
            bool reachedRegular       = false;

            foreach (GameDataObject gdo in entityTypes)
            {
                if (!reachedRegular && gdo.ClassType != ClassType.Solid)
                {
                    reachedRegular = true;
                    writer.WriteNullTerminatedString("");
                }
                writer.WriteNullTerminatedString(gdo.Name);
                foreach (DataStructures.GameData.Property p in gdo.Properties)
                {
                    writer.Write((byte)p.VariableType);
                    writer.WriteNullTerminatedString(p.Name); // Switch from brush to regular entities
                }
                writer.Write((byte)255);                      // Property end byte

                // Entries
                List <MapObject> entitiesOfType = entites.FindAll(x => x.ClassName == gdo.Name);
                writer.Write(entitiesOfType.Count);
                foreach (Entity e in entitiesOfType)
                {
                    entityIndices.Add(e, entityIndicesCounter++);
                    if (e.GameData.ClassType == ClassType.Solid)
                    {
                        IEnumerable <MapObject> children = e.GetChildren();
                        writer.Write(children.Count());
                        foreach (MapObject mo in children)
                        {
                            int index = solids.FindIndex(x => x == mo);
                            writer.Write(index);
                        }
                    }
                    for (int i = 0; i < gdo.Properties.Count; i++)
                    {
                        DataStructures.MapObjects.Property property;
                        if (i < e.EntityData.Properties.Count && gdo.Properties[i].Name == e.EntityData.Properties[i].Key)
                        {
                            property = e.EntityData.Properties[i];
                        }
                        else
                        {
                            property = e.EntityData.Properties.Find(x => x.Key == gdo.Properties[i].Name);
                            if (property == null)
                            {
                                property       = new DataStructures.MapObjects.Property();
                                property.Key   = gdo.Properties[i].Name;
                                property.Value = gdo.Properties[i].DefaultValue;
                            }
                        }
                        switch (gdo.Properties[i].VariableType)
                        {
                        case VariableType.Bool:
                            writer.Write(property.Value == "Yes");
                            break;

                        case VariableType.Color255:
                            writer.WriteRGBAColour(property.GetColour(Color.Black));
                            break;

                        case VariableType.Float:
                            writer.Write(float.Parse(property.Value));
                            break;

                        case VariableType.Integer:
                            writer.Write(int.Parse(property.Value));
                            break;

                        case VariableType.String:
                            // TODO: Implement dictionary.
                            writer.WriteNullTerminatedString(property.Value);
                            break;

                        case VariableType.Vector:
                            writer.WriteCoordinate(property.GetCoordinate(Coordinate.Zero));
                            break;

                        case VariableType.Choices:
                            bool found = false;
                            for (int j = 0; j < gdo.Properties[i].Options.Count; j++)
                            {
                                if (property.Value == gdo.Properties[i].Options[j].Key)
                                {
                                    writer.Write((byte)j);
                                    found = true;
                                    break;
                                }
                            }
                            if (!found)
                            {
                                writer.Write((byte)255);
                            }
                            break;
                        }
                    }
                }
            }
            writer.WriteNullTerminatedString("");

            // CBRE ONLY

            // Visgroup dictionary
            // TODO: Visgroup IDs to indices
            Stack <IEnumerator <Visgroup> > visStack = new Stack <IEnumerator <Visgroup> >();

            visStack.Push(map.Visgroups.GetEnumerator());
            while (visStack.Count > 0)
            {
                IEnumerator <Visgroup> v = visStack.Pop();
                while (v.MoveNext())
                {
                    if (!v.Current.IsAutomatic)
                    {
                        writer.Write(HIERARCHY_PROCCEED);
                        writer.Write(v.Current.ID);
                        writer.WriteNullTerminatedString(v.Current.Name);
                        if (v.Current.Children.Count != 0)
                        {
                            writer.Write(HIERARCHY_DOWN);
                            visStack.Push(v);
                            v = v.Current.Children.GetEnumerator();
                        }
                    }
                }
                writer.Write(HIERARCHY_UP);
            }

            // Solid visgroups
            foreach (Solid s in map.WorldSpawn.FindAll().OfType <Solid>())
            {
                WriteVisgroups(writer, s);
            }

            // Entity visgroups
            foreach (GameDataObject entityType in entityTypes)
            {
                foreach (Entity e in entites.FindAll(x => x.ClassName == entityType.Name))
                {
                    WriteVisgroups(writer, e);
                }
            }

            // Groups
            IEnumerable <Group> groups = map.WorldSpawn.GetChildren().OfType <Group>();

            writer.Write(groups.Count());
            foreach (Group g in groups)
            {
                Stack <IEnumerator <MapObject> > groupStack = new Stack <IEnumerator <MapObject> >();
                groupStack.Push(g.GetChildren().GetEnumerator());
                while (groupStack.Count > 0)
                {
                    IEnumerator <MapObject> gg = groupStack.Pop();
                    while (gg.MoveNext())
                    {
                        if (gg.Current is Group)
                        {
                            writer.Write(HIERARCHY_DOWN);
                            groupStack.Push(gg);
                            gg = gg.Current.GetChildren().GetEnumerator();
                        }
                        else if (gg.Current is Entity)
                        {
                            writer.Write(IDENTIFIER_ENTITY);
                            writer.Write(entityIndices[(Entity)gg.Current]);
                        }
                        else
                        {
                            writer.Write(IDENTIFIER_SOLID);
                            writer.Write(solids.FindIndex(x => x == gg.Current));
                        }
                    }
                    writer.Write(HIERARCHY_UP);
                }
            }

            stream.Close();
        }
Пример #21
0
        private void ParseAt(DataStructures.GameData.GameData gd, IEnumerator <LexObject> iterator)
        {
            iterator.MoveNext();
            var type = iterator.Current.Value;

            if (type.Equals("include", StringComparison.InvariantCultureIgnoreCase))
            {
                Expect(iterator, LexType.String);
                if (CurrentFile != null)
                {
                    var filename = iterator.Current.GetValue();
                    var path     = Path.GetDirectoryName(CurrentFile) ?? "";
                    var incfile  = Path.Combine(path, filename);

                    var current = CurrentFile;
                    var incgd   = GetGameDataFromFile(incfile);
                    CurrentFile = current;

                    if (!gd.Includes.Any(x => String.Equals(x, filename, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        gd.Includes.Add(filename);
                    }

                    // Merge the included gamedata into the current one
                    gd.MapSizeHigh = Math.Max(incgd.MapSizeHigh, gd.MapSizeHigh);
                    gd.MapSizeLow  = Math.Min(incgd.MapSizeLow, gd.MapSizeLow);
                    gd.Includes.AddRange(incgd.Includes.Where(x => !gd.Includes.Contains(x)));
                    gd.Classes.AddRange(incgd.Classes.Where(x => !gd.Classes.Any(y => String.Equals(x.Name, y.Name, StringComparison.InvariantCultureIgnoreCase))));
                    gd.AutoVisgroups.AddRange(incgd.AutoVisgroups.Where(x => !gd.AutoVisgroups.Any(y => String.Equals(x.Name, y.Name, StringComparison.InvariantCultureIgnoreCase))));
                    gd.MaterialExclusions.AddRange(incgd.MaterialExclusions.Where(x => !gd.MaterialExclusions.Any(y => String.Equals(x, y, StringComparison.InvariantCultureIgnoreCase))));
                }
                else
                {
                    throw new ProviderException("Unable to include a file when not reading from a file.");
                }
            }
            else if (type.Equals("mapsize", StringComparison.InvariantCultureIgnoreCase))
            {
                Expect(iterator, LexType.OpenParen);
                Expect(iterator, LexType.Value);
                gd.MapSizeLow = Int32.Parse(iterator.Current.Value);
                Expect(iterator, LexType.Comma);
                Expect(iterator, LexType.Value);
                gd.MapSizeHigh = Int32.Parse(iterator.Current.Value);
                Expect(iterator, LexType.CloseParen);
            }
            else if (type.Equals("materialexclusion", StringComparison.InvariantCultureIgnoreCase))
            {
                Expect(iterator, LexType.OpenBracket);
                iterator.MoveNext();
                while (iterator.Current.Type != LexType.CloseBracket)
                {
                    Assert(iterator.Current, iterator.Current.IsValueOrString(), "Expected value type, got " + iterator.Current.Type + ".");
                    var exclusion = iterator.Current.GetValue();
                    gd.MaterialExclusions.Add(exclusion);
                    iterator.MoveNext();
                }
            }
            else if (type.Equals("autovisgroup", StringComparison.InvariantCultureIgnoreCase))
            {
                Expect(iterator, LexType.Equals);

                iterator.MoveNext();
                Assert(iterator.Current, iterator.Current.IsValueOrString(), "Expected value type, got " + iterator.Current.Type + ".");
                var sectionName = iterator.Current.GetValue();
                var sect        = new AutoVisgroupSection {
                    Name = sectionName
                };

                Expect(iterator, LexType.OpenBracket);
                iterator.MoveNext();
                while (iterator.Current.Type != LexType.CloseBracket)
                {
                    Assert(iterator.Current, iterator.Current.IsValueOrString(), "Expected value type, got " + iterator.Current.Type + ".");
                    var groupName = iterator.Current.GetValue();
                    var grp       = new AutoVisgroup {
                        Name = groupName
                    };

                    Expect(iterator, LexType.OpenBracket);
                    iterator.MoveNext();
                    while (iterator.Current.Type != LexType.CloseBracket)
                    {
                        Assert(iterator.Current, iterator.Current.IsValueOrString(), "Expected value type, got " + iterator.Current.Type + ".");
                        var entity = iterator.Current.GetValue();
                        grp.EntityNames.Add(entity);
                        iterator.MoveNext();
                    }

                    sect.Groups.Add(grp);
                }

                gd.AutoVisgroups.Add(sect);
            }
            else
            {
                // Parsing:
                // @TypeClass name(param, param) name()
                var ct  = ParseClassType(type, iterator.Current);
                var gdo = new GameDataObject("", "", ct);
                iterator.MoveNext();
                while (iterator.Current.Type == LexType.Value)
                {
                    // Parsing:
                    // @TypeClass {name(param, param) name()}
                    var name = iterator.Current.Value;
                    var bh   = new Behaviour(name);
                    iterator.MoveNext();
                    if (iterator.Current.Type == LexType.Value)
                    {
                        // Allow for the following (first seen in hl2 base):
                        // @PointClass {halfgridsnap} base(Targetname)
                        continue;
                    }
                    Assert(iterator.Current, iterator.Current.Type == LexType.OpenParen, "Unexpected " + iterator.Current.Type);
                    iterator.MoveNext();
                    while (iterator.Current.Type != LexType.CloseParen)
                    {
                        // Parsing:
                        // name({param, param})
                        if (iterator.Current.Type != LexType.Comma)
                        {
                            Assert(iterator.Current, iterator.Current.Type == LexType.Value || iterator.Current.Type == LexType.String,
                                   "Unexpected " + iterator.Current.Type + ".");
                            var value = iterator.Current.Value;
                            if (iterator.Current.Type == LexType.String)
                            {
                                value = value.Trim('"');
                            }
                            bh.Values.Add(value);
                        }
                        iterator.MoveNext();
                    }
                    Assert(iterator.Current, iterator.Current.Type == LexType.CloseParen, "Unexpected " + iterator.Current.Type);
                    // Treat base behaviour as a special case
                    if (bh.Name == "base")
                    {
                        gdo.BaseClasses.AddRange(bh.Values);
                    }
                    else
                    {
                        gdo.Behaviours.Add(bh);
                    }
                    iterator.MoveNext();
                }
                // = class_name : "Descr" + "iption" [
                Assert(iterator.Current, iterator.Current.Type == LexType.Equals, "Expected equals, got " + iterator.Current.Type);
                Expect(iterator, LexType.Value);
                gdo.Name = iterator.Current.Value;
                iterator.MoveNext();
                if (iterator.Current.Type == LexType.Colon)
                {
                    // Parsing:
                    // : {"Descr" + "iption"} [
                    iterator.MoveNext();
                    gdo.Description = ParsePlusString(iterator);
                }
                Assert(iterator.Current, iterator.Current.Type == LexType.OpenBracket, "Unexpected " + iterator.Current.Type);

                // Parsing:
                // name(type) : "Desc" : "Default" : "Long Desc" = [ ... ]
                // input name(type) : "Description"
                // output name(type) : "Description"
                iterator.MoveNext();
                while (iterator.Current.Type != LexType.CloseBracket)
                {
                    Assert(iterator.Current, iterator.Current.Type == LexType.Value, "Unexpected " + iterator.Current.Type);
                    var pt = iterator.Current.Value;
                    if (pt == "input" || pt == "output") // IO
                    {
                        // input name(type) : "Description"
                        var io = new IO();
                        Expect(iterator, LexType.Value);
                        io.IOType = (IOType)Enum.Parse(typeof(IOType), pt, true);
                        io.Name   = iterator.Current.Value;
                        Expect(iterator, LexType.OpenParen);
                        Expect(iterator, LexType.Value);
                        io.VariableType = ParseVariableType(iterator.Current);
                        Expect(iterator, LexType.CloseParen);
                        iterator.MoveNext(); // if not colon, this will be the value of the next io/property, or close
                        if (iterator.Current.Type == LexType.Colon)
                        {
                            iterator.MoveNext();
                            io.Description = ParsePlusString(iterator);
                        }
                        gdo.InOuts.Add(io);
                    }
                    else // Property
                    {
                        Expect(iterator, LexType.OpenParen);
                        Expect(iterator, LexType.Value);
                        var vartype = ParseVariableType(iterator.Current);
                        Expect(iterator, LexType.CloseParen);
                        var prop = new Property(pt, vartype);
                        iterator.MoveNext();
                        // if not colon or equals, this will be the value of the next io/property, or close
                        if (iterator.Current.Type == LexType.Value)
                        {
                            // Check for additional flags on the property
                            // e.g.: name(type) readonly : "This is a read only value"
                            //       name(type) report   : "This value will show in the entity report"
                            switch (iterator.Current.Value)
                            {
                            case "readonly":
                                prop.ReadOnly = true;
                                iterator.MoveNext();
                                break;

                            case "report":
                                prop.ShowInEntityReport = true;
                                iterator.MoveNext();
                                break;
                            }
                        }
                        do // Using do/while(false) so I can break out - reduces nesting.
                        {
                            // Short description
                            if (iterator.Current.Type != LexType.Colon)
                            {
                                break;
                            }
                            iterator.MoveNext();
                            prop.ShortDescription = ParsePlusString(iterator);

                            // Default value
                            if (iterator.Current.Type != LexType.Colon)
                            {
                                break;
                            }
                            iterator.MoveNext();
                            if (iterator.Current.Type != LexType.Colon) // Allow for ': :' structure (no default)
                            {
                                if (iterator.Current.Type == LexType.String)
                                {
                                    prop.DefaultValue = iterator.Current.Value.Trim('"');
                                }
                                else
                                {
                                    Assert(iterator.Current, iterator.Current.Type == LexType.Value, "Unexpected " + iterator.Current.Type);
                                    prop.DefaultValue = iterator.Current.Value;
                                }
                                iterator.MoveNext();
                            }

                            // Long description
                            if (iterator.Current.Type != LexType.Colon)
                            {
                                break;
                            }
                            iterator.MoveNext();
                            prop.Description = ParsePlusString(iterator);
                        } while (false);
                        if (iterator.Current.Type == LexType.Equals)
                        {
                            Expect(iterator, LexType.OpenBracket);
                            // Parsing property options:
                            // value : description
                            // value : description : 0
                            iterator.MoveNext();
                            while (iterator.Current.IsValueOrString())
                            {
                                var opt = new Option
                                {
                                    Key = iterator.Current.GetValue()
                                };
                                Expect(iterator, LexType.Colon);

                                // Some FGDs use values for property descriptions instead of strings
                                iterator.MoveNext();
                                Assert(iterator.Current, iterator.Current.IsValueOrString(), "Choices value must be value or string type.");
                                if (iterator.Current.Type == LexType.String)
                                {
                                    opt.Description = ParsePlusString(iterator);
                                }
                                else
                                {
                                    opt.Description = iterator.Current.GetValue();
                                    iterator.MoveNext();
                                    // ParsePlusString moves next once it's complete, need to do the same here
                                }

                                prop.Options.Add(opt);
                                if (iterator.Current.Type != LexType.Colon)
                                {
                                    continue;
                                }
                                Expect(iterator, LexType.Value);
                                opt.On = iterator.Current.Value == "1";
                                iterator.MoveNext();
                            }
                            Assert(iterator.Current, iterator.Current.Type == LexType.CloseBracket, "Unexpected " + iterator.Current.Type);
                            iterator.MoveNext();
                        }
                        gdo.Properties.Add(prop);
                    }
                }
                Assert(iterator.Current, iterator.Current.Type == LexType.CloseBracket, "Unexpected " + iterator.Current.Type);
                gd.Classes.Add(gdo);
            }
        }
Пример #22
0
 private void loadGameData()
 {
     gameDataObject = GameObject.FindObjectOfType <GameDataObject>();
     gameDataObject.SelectCharacter(gameDataObject.playerGameCharacter);
     selectedGameCharacter = gameDataObject.getSelectedCharacter();
 }
Пример #23
0
 private void loadGameData()
 {
     gameDataObject = GameObject.FindObjectOfType <GameDataObject>();
 }
Пример #24
0
 public void EntitySelected(GameDataObject selection)
 {
     _document.SetMemory("SelectedEntity", selection == null ? null : selection.Name);
 }