コード例 #1
0
ファイル: CarSpawnerFile.cs プロジェクト: robwor/openrails
        public CarSpawnerBlock(STFReader stf, string shapePath, List <CarSpawnerList> carSpawnerLists, string listName)
        {
            var spawnerDataItems = new List <CarSpawnerItemData>();
            {
                var count = stf.ReadInt(null);
                stf.ParseBlock(new STFReader.TokenProcessor[] {
                    new STFReader.TokenProcessor("carspawneritem", () => {
                        if (--count < 0)
                        {
                            STFException.TraceWarning(stf, "Skipped extra CarSpawnerItem");
                        }
                        else
                        {
                            var dataItem = new CarSpawnerItemData(stf, shapePath);
                            if (File.Exists(dataItem.name))
                            {
                                spawnerDataItems.Add(dataItem);
                            }
                            else
                            {
                                STFException.TraceWarning(stf, String.Format("Non-existent shape file {0} referenced", dataItem.name));
                            }
                        }
                    }),
                });
                if (count > 0)
                {
                    STFException.TraceWarning(stf, count + " missing CarSpawnerItem(s)");
                }
            }

            CarSpawnerList carSpawnerList = new CarSpawnerList(spawnerDataItems, listName);

            carSpawnerLists.Add(carSpawnerList);
        }
コード例 #2
0
        public float[] distanceFrom;        // the second parameter of the CarSpwanerItem

        public CarSpawnerFile(string filePath, string shapePath)
        {
            List <CarSpawnerItemData> spawnerDataItems = new List <CarSpawnerItemData>();

            using (STFReader stf = new STFReader(filePath, false))
            {
                var count = stf.ReadInt(null);
                stf.ParseBlock(new STFReader.TokenProcessor[] {
                    new STFReader.TokenProcessor("carspawneritem", () => {
                        if (--count < 0)
                        {
                            STFException.TraceWarning(stf, "Skipped extra CarSpawnerItem");
                        }
                        else
                        {
                            var dataItem = new CarSpawnerItemData(stf, shapePath);
                            if (File.Exists(dataItem.name))
                            {
                                spawnerDataItems.Add(dataItem);
                            }
                            else
                            {
                                STFException.TraceWarning(stf, String.Format("Non-existent shape file {0} referenced", dataItem.name));
                            }
                        }
                    }),
                });
                if (count > 0)
                {
                    STFException.TraceWarning(stf, count + " missing CarSpawnerItem(s)");
                }
            }

            shapeNames   = new string[spawnerDataItems.Count];
            distanceFrom = new float[spawnerDataItems.Count];
            int i = 0;

            foreach (CarSpawnerItemData data in spawnerDataItems)
            {
                shapeNames[i]   = data.name;
                distanceFrom[i] = data.dist;
                i++;
            }
        }