Exemplo n.º 1
0
        public void Array_validate_succeeds()
        {
            var table = new Table(new Schema(new DataField <IEnumerable <int> >("ids")));

            table.Add(new Row(new[] { 1, 2, 3 }));
            table.Add(new Row(new[] { 4, 5, 6 }));
        }
Exemplo n.º 2
0
        public void Array_write_read()
        {
            var table = new Table(
                new Schema(
                    new DataField <int>("id"),
                    new DataField <string[]>("categories") //array field
                    )
                );
            var ms = new MemoryStream();

            table.Add(1, new[] { "1", "2", "3" });
            table.Add(3, new[] { "3", "3", "3" });

            //write to stream
            using (var writer = new ParquetWriter(table.Schema, ms))
            {
                writer.Write(table);
            }

            //System.IO.File.WriteAllBytes("c:\\tmp\\1.parquet", ms.ToArray());

            //read back into table
            ms.Position = 0;
            Table table2;

            using (var reader = new ParquetReader(ms))
            {
                table2 = reader.ReadAsTable();
            }

            //validate data
            Assert.Equal(table.ToString(), table2.ToString(), ignoreLineEndingDifferences: true);
        }
Exemplo n.º 3
0
        public void Special_read_file_with_multiple_row_groups()
        {
            var ms = new MemoryStream();

            //create multirowgroup file

            //first row group
            var t = new Table(new DataField <int>("id"));

            t.Add(1);
            t.Add(2);
            using (var writer = new ParquetWriter(t.Schema, ms))
            {
                writer.Write(t);
            }

            //second row group
            t.Clear();
            t.Add(3);
            t.Add(4);
            using (var writer = new ParquetWriter(t.Schema, ms, null, true))
            {
                writer.Write(t);
            }

            //read back as table
            t = ParquetReader.ReadTableFromStream(ms);
            Assert.Equal(4, t.Count);
        }
Exemplo n.º 4
0
        public void List_simple_element_write_read()
        {
            var table = new Table(
                new Schema(
                    new DataField <int>("id"),
                    new ListField("cities",
                                  new DataField <string>("name"))));

            var ms = new MemoryStream();

            table.Add(1, new[] { "London", "Derby" });
            table.Add(2, new[] { "Paris", "New York" });

            //write as table
            using (var writer = new ParquetWriter(table.Schema, ms))
            {
                writer.Write(table);
            }

            //read back into table
            ms.Position = 0;
            Table table2;

            using (var reader = new ParquetReader(ms))
            {
                table2 = reader.ReadAsTable();
            }

            //validate data
            Assert.Equal(table.ToString(), table2.ToString(), ignoreLineEndingDifferences: true);
        }
Exemplo n.º 5
0
 void AddNew(long id)
 {
     testTable.Add(
         new TestEntity(id)
     {
         Name = String.Format("target-{0}", id)
     });
 }
Exemplo n.º 6
0
        public void ToStr()
        {
            var t = new Table();

            t.Add(new Record(1, 2, 3));
            t.Add(new Record("abc", 100, "xyz"));
            Assert.AreEqual("1\t2\t3\nabc\t100\txyz", t.ToString());
        }
Exemplo n.º 7
0
        public static DataTable GetBankBinTable()
        {
            Table t = new Table("BankBin");

            t.Add("bbid", "autolong", 1);
            t.Add("bankbin", "long", 0);    //银行bin号
            t.Add("bankname", "string", 0); //银行名称
            return(DataTables.GetDataTable(t));
        }
Exemplo n.º 8
0
    static void Main(string[] args)
    {
        Table <int, string> table = new Table <int, string>();

        table.Add(10001, "Joe", "Curly", "Mo");
        table.Add(10002, "Alpha", "Beta");
        table.Add(10101, "UX-300", "UX-201", "HX-100b", "UT-910");
        string[] parts = table[10101];
        // returns "UX-300", "UX-201", "HX-100b" and "UT-910".
    }
Exemplo n.º 9
0
        /// <summary>
        /// update names in metadata
        /// </summary>
        public void UpdateMetadata()
        {
            tblHashNames.Clear();

            for (int i = 0; i < Properties.Count; ++i)
            {
                tblHashNames.Add(DataMap.CalculateHash(Properties[i].Name), Properties[i]);
                tblHashNames.Add(DataMap.CalculateHash(Properties[i].Name.ToLower()), Properties[i]);
            }
        }
Exemplo n.º 10
0
        void addEntry(Table table, int line, string label, EntryType type)
        {
            table.Add(new Label(label), 0, line, hpos: WidgetPlacement.End, hexpand: true);

            Widget entry;

            switch (type)
            {
            case EntryType.Text:
                entry = new TextEntry()
                {
                    Text = "Name"
                };
                break;

            case EntryType.Readonly:
                entry = new TextEntry()
                {
                    Text      = "Obj",
                    Sensitive = false
                };
                break;

            case EntryType.LongText:
                entry = new LongTextEntry("this is a long text");
                break;

            case EntryType.Color:
                entry = new ColorEntry();
                break;

            case EntryType.Combo:
                var cbe = new ComboBoxEntry();
                cbe.Items.Add("One");
                cbe.Items.Add("Two");
                cbe.Items.Add("Three");
                //cbe.SelectedIndex = 0;
                entry = cbe;
                break;

            case EntryType.Check:
                entry = new CheckBox()
                {
                    Active = true
                };
                break;

            default:
                // Shouldn't get here
                entry = null;
                break;
            }

            table.Add(entry, 1, line, hpos: WidgetPlacement.Fill, hexpand: true);
        }
        void HandleClicked(object sender, EventArgs e)
        {
            if (popover == null)
            {
                popover         = new Popover();
                popover.Padding = 20;

                var table = new Table()
                {
                    DefaultColumnSpacing = 20, DefaultRowSpacing = 10
                };
//					table.Margin.SetAll (60);
                table.Add(new Label("Font")
                {
                    TextAlignment = Alignment.End
                }, 0, 0);
                table.Add(new ComboBox(), 1, 0, vexpand: true);

                table.Add(new Label("Family")
                {
                    TextAlignment = Alignment.End
                }, 0, 1);
                table.Add(new ComboBox(), 1, 1, vexpand: true);

                var cmbStyle = new ComboBox();
                cmbStyle.Items.Add("Normal");
                cmbStyle.Items.Add("Bold");
                cmbStyle.Items.Add("Italic");

                table.Add(new Label("Style")
                {
                    TextAlignment = Alignment.End
                }, 0, 2);
                table.Add(cmbStyle, 1, 2, vexpand: true);

                table.Add(new Label("Size")
                {
                    TextAlignment = Alignment.End
                }, 0, 3);
                table.Add(new SpinButton(), 1, 3, vexpand: true);

                var b = new Button("Add more");
                table.Add(b, 0, 4);
                int next = 5;
                b.Clicked += delegate {
                    table.Add(new Label("Row " + next), 0, next++);
                };

                table.Margin    = 20;
                popover.Content = table;
            }
//			popover.Padding.SetAll (20);
            popover.BackgroundColor = Xwt.Drawing.Colors.Yellow.WithAlpha(0.9);
            popover.Show(Popover.Position.Top, (Button)sender, new Rectangle(50, 10, 5, 5));
        }
Exemplo n.º 12
0
        public void Composite_Keys()
        {
            var table       = new Table <TestResult>();
            var resultIndex = table.CreateIndex(result => (result.TestId, result.Version));

            table.Add(new TestResult("AUTO_1", "1.0", 1));
            table.Add(new TestResult("AUTO_2", "1.0", 2));
            table.Add(new TestResult("AUTO_1", "2.0", 3));
            table.Add(new TestResult("AUTO_2", "2.0", 4));

            Assert.AreEqual(1, resultIndex[("AUTO_1", "1.0")][0].Value);
Exemplo n.º 13
0
        public ProcessRunConfigurationEditorWidget()
        {
            VBox mainBox = this;

            mainBox.Margin = 12;
            var table = new Table();

            var argumentsLabel = new Label(GettextCatalog.GetString("Arguments:"));

            table.Add(argumentsLabel, 0, 0);
            table.Add(argumentsEntry = new TextEntry(), 1, 0, hexpand: true);
            argumentsEntry.Accessible.LabelWidget = argumentsLabel;
            argumentsEntry.Accessible.Description = GettextCatalog.GetString("Set any additional arguments to pass to the project.");

            var workingDirLabel = new Label(GettextCatalog.GetString("Run in directory:"));

            table.Add(workingDirLabel, 0, 1);
            table.Add(workingDir = new FolderSelector(), 1, 1, hexpand: true);
            workingDir.Accessible.LabelWidget = workingDirLabel;
            workingDir.Accessible.Description = GettextCatalog.GetString("Choose the directory to run the project in.");

            mainBox.PackStart(table);

            mainBox.PackStart(new HSeparator()
            {
                MarginTop = 8, MarginBottom = 8
            });

            var envVarsLabel = new Label(GettextCatalog.GetString("Environment Variables"));

            mainBox.PackStart(envVarsLabel);
            envVars = new EnvironmentVariableCollectionEditor();
            envVars.Accessible.LabelWidget = envVarsLabel;
            envVars.Accessible.Description = GettextCatalog.GetString("Set additional environment variables for the project.");

            mainBox.PackStart(envVars, true);

            mainBox.PackStart(new HSeparator()
            {
                MarginTop = 8, MarginBottom = 8
            });

            HBox cbox = new HBox();

            cbox.PackStart(externalConsole = new CheckBox(GettextCatalog.GetString("Run on external console")));
            cbox.PackStart(pauseConsole    = new CheckBox(GettextCatalog.GetString("Pause console output")));
            mainBox.PackStart(cbox);

            argumentsEntry.Changed   += (s, a) => NotifyChanged();
            workingDir.FolderChanged += (s, a) => NotifyChanged();
            envVars.Changed          += (s, a) => NotifyChanged();
            externalConsole.Toggled  += (s, a) => NotifyChanged();
            pauseConsole.Toggled     += (s, a) => NotifyChanged();
        }
Exemplo n.º 14
0
        public override void Initialize(Table table, Skin skin, float leftCellWidth)
        {
            var label = CreateNameLabel(table, skin, leftCellWidth);

            _textField = new TextField(GetValue <string>(), skin);
            _textField.SetTextFieldFilter(new FloatFilter());
            _textField.OnTextChanged += (field, str) => { SetValue(str); };

            table.Add(label);
            table.Add(_textField).SetMaxWidth(70);
        }
Exemplo n.º 15
0
        void SetupSlider(Table table, Skin skin, float leftCellWidth, float minValue, float maxValue, float stepSize)
        {
            var label = CreateNameLabel(table, skin, leftCellWidth);

            _slider = new Slider(skin, null, minValue, maxValue);
            _slider.SetStepSize(stepSize);
            _slider.SetValue(GetValue <float>());
            _slider.OnChanged += newValue => { _setter.Invoke(newValue); };

            table.Add(label);
            table.Add(_slider);
        }
        public void Array_simple_integers()
        {
            var table = new Table(
                new DataField <int>("id"),
                new DataField <string[]>("categories") //array field
                );

            table.Add(1, new[] { "1", "2", "3" });
            table.Add(3, new[] { "3", "3", "3" });

            CompareWithMr(table);
        }
Exemplo n.º 17
0
        public override void Initialize(Table table, Skin skin, float leftCellWidth)
        {
            var label = CreateNameLabel(table, skin, leftCellWidth);

            _checkbox = new CheckBox(string.Empty, skin);
            _checkbox.ProgrammaticChangeEvents = false;
            _checkbox.IsChecked  = GetValue <bool>();
            _checkbox.OnChanged += newValue => { SetValue(newValue); };

            table.Add().Width(135);
            table.Add(_checkbox);
        }
Exemplo n.º 18
0
        public override void Initialize()
        {
            // scene
            AddSceneComponent(new SceneSprites(this));
            Shared.PrintBackground(this);

            // setup a pixel perfect screen
            ClearColor = Color.Black;
            SetDesignResolution(SD.SCREEN_WIDTH, SD.SCREEN_HEIGHT, SceneResolutionPolicy.ShowAllPixelPerfect);
            Screen.SetSize(SD.SCREEN_WIDTH * SD.SCALE, SD.SCREEN_HEIGHT * SD.SCALE);

            // add a renderer
            renderer = AddRenderer(new DefaultRenderer());

            // canvas
            canvas = CreateEntity("ui").AddComponent(new UICanvas());
            canvas.IsFullScreen = true;
            canvas.RenderLayer  = SCREEN_RENDER_LAYER;

            // table
            table = canvas.Stage.AddElement(new Table());
            table.SetFillParent(false).SetBounds(0, 0, SD.SCREEN_WIDTH, SD.SCREEN_HEIGHT);
            table.Left().Top();
            table.SetScale(SD.SCALE);
            Cell c;

            // title
            var labelStyle = new LabelStyle(Color.Black);

            c = table.Add(new Label("You Won!", labelStyle).SetFontScale(4));
            table.Row().SetPadTop(10);
            c = table.Add(new Label("A Game by Sainer").SetFontScale(1));
            table.Row().SetPadTop(30);

            // button style
            var buttonStyle = new TextButtonStyle(
                new PrimitiveDrawable(Color.Black, 10f),
                new PrimitiveDrawable(Color.Yellow),
                new PrimitiveDrawable(Color.DarkSlateBlue))
            {
                DownFontColor = Color.Black
            };

            // buttons
            c = table.Add(new TextButton("To Main Menu", buttonStyle)).SetMinHeight(30);
            c.GetElement <Button>().OnClicked += Shared.TransitionToMainMenu;
            table.Row().SetPadTop(10);

            // put table in the middle
            table.PadTop(10);
            table.PadLeft((SD.SCREEN_WIDTH - table.GetWidth()) / 2);
        }
Exemplo n.º 19
0
        public void Adding_Index_After_Adding_Data_Fills_Index()
        {
            var table = new Table <TestResult>();

            table.Add(new TestResult("AUTO_1", "1.0", 1));
            table.Add(new TestResult("AUTO_2", "1.0", 2));

            var testIdsIndex = table.CreateIndex(result => result.TestId);

            Assert.AreEqual(2, testIdsIndex.Count);
            Assert.AreEqual(1, testIdsIndex["AUTO_1"][0].Value);
            Assert.AreEqual(2, testIdsIndex["AUTO_2"][0].Value);
        }
Exemplo n.º 20
0
        public HeavyScroller()
        {
            Locator.AddChild(Child);
            Layout.Add(Locator, 0, 0, 1, 1, true, true);
            Layout.Add(VScroll, 1, 0);
            Layout.Add(HScroll, 0, 1);
            base.Content = Layout;

            BoundsChanged        += new EventHandler(HeavyScroller_BoundsChanged);
            VScroll.ValueChanged += new EventHandler(VScroll_ValueChanged);
            HScroll.ValueChanged += new EventHandler(HScroll_ValueChanged);
            this.MouseScrolled   += new EventHandler <MouseScrolledEventArgs>(HeavyScroller_MouseScrolled);
        }
        void HandleClicked2(object sender, EventArgs e)
        {
            if (popover2 == null)
            {
                popover2 = new Popover();

                var table = new Table()
                {
                    DefaultColumnSpacing = 20, DefaultRowSpacing = 10
                };
                table.Add(new Label("Font")
                {
                    TextAlignment = Alignment.End
                }, 0, 0);
                table.Add(new ComboBox(), 1, 0, vexpand: true);

                table.Add(new Label("Family")
                {
                    TextAlignment = Alignment.End
                }, 0, 1);
                table.Add(new ComboBox(), 1, 1, vexpand: true);

                table.Add(new Label("Style")
                {
                    TextAlignment = Alignment.End
                }, 0, 2);
                table.Add(new ComboBox(), 1, 2, vexpand: true);

                table.Add(new Label("Size")
                {
                    TextAlignment = Alignment.End
                }, 0, 3);
                table.Add(new SpinButton(), 1, 3, vexpand: true);

                var b = new Button("Add more");
                table.Add(b, 0, 4);
                int next = 5;
                b.Clicked += delegate {
                    table.Add(new Label("Row " + next), 0, next++);
                };

                table.Margin     = 6;
                popover2.Content = table;
            }

            var newRect = new Rectangle(((Button)sender).Size.Width * 0.66d, 0, 0, 0);

            popover2.Show(Popover.Position.Bottom, (Button)sender, newRect);
        }
Exemplo n.º 22
0
        /// <summary>
        /// 执行查询,返回数据集
        /// </summary>
        /// <returns></returns>
        public Table ExecuteQuery()
        {
            Table tbl    = new Table();
            var   reader = ExecuteReader();

            if (reader != null && reader.FieldCount > 0)
            {
                // 列定义
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    // Microsoft.Data.Sqlite 升级5.0.3后使用 GetFieldType 方法,因通过GetDataTypeName无bigint类型!
                    // 返回结果在表的首行数据出现dbnull的时候不正确!
                    // 原方法参见ComposeDt
                    tbl.Add(reader.GetName(i), reader.GetFieldType(i));
                }

                while (reader.Read())
                {
                    var row = new Row();
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        var col = tbl.Columns[i];
                        if (reader.IsDBNull(i))
                        {
                            // 列为可空类型时重置,因sqlie无可空类型
                            if (col.Type == typeof(byte[]))
                            {
                                // 返回结果的首行数据出现dbnull时列类型不正确!
                                if (tbl.Count == 0)
                                {
                                    col.Type = typeof(string);
                                }
                            }
                            else if (col.Type.IsValueType && Nullable.GetUnderlyingType(col.Type) == null)
                            {
                                col.Type = typeof(Nullable <>).MakeGenericType(col.Type);
                            }
                            new Cell(row, col.ID, col.Type);
                        }
                        else
                        {
                            new Cell(row, col.ID, col.Type, reader.GetValue(i));
                        }
                    }
                    tbl.Add(row);
                }
            }
            return(tbl);
        }
Exemplo n.º 23
0
        public void Updating_Table_Causes_Index_Updates()
        {
            var table        = new Table <TestResult>();
            var testIdsIndex = table.CreateIndex(result => result.TestId);

            table.Add(new TestResult("AUTO_1", "1.0", 1));
            table.Add(new TestResult("AUTO_1", "2.0", 2));
            Assert.AreEqual(1, testIdsIndex.Count);
            Assert.AreEqual(2, testIdsIndex["AUTO_1"].Count);

            table.Add(new TestResult("AUTO_2", "1.0", 3));
            table.Add(new TestResult("AUTO_2", "2.0", 4));
            Assert.AreEqual(2, testIdsIndex.Count);
            Assert.AreEqual(2, testIdsIndex["AUTO_2"].Count);
        }
Exemplo n.º 24
0
        void HandleClicked(object sender, EventArgs e)
        {
            if (popover == null)
            {
                popover = new Popover();

                var table = new Table()
                {
                    DefaultColumnSpacing = 20, DefaultRowSpacing = 10
                };
//					table.Margin.SetAll (60);
                table.Add(new Label("Font")
                {
                    TextAlignment = Alignment.End
                }, 0, 0);
                table.Add(new ComboBox(), 1, 0, vexpand: true);

                table.Add(new Label("Family")
                {
                    TextAlignment = Alignment.End
                }, 0, 1);
                table.Add(new ComboBox(), 1, 1, vexpand: true);

                table.Add(new Label("Style")
                {
                    TextAlignment = Alignment.End
                }, 0, 2);
                table.Add(new ComboBox(), 1, 2, vexpand: true);

                table.Add(new Label("Size")
                {
                    TextAlignment = Alignment.End
                }, 0, 3);
                table.Add(new SpinButton(), 1, 3, vexpand: true);

                var b = new Button("Add more");
                table.Add(b, 0, 4);
                int next = 5;
                b.Clicked += delegate {
                    table.Add(new Label("Row " + next), 0, next++);
                };

                table.Margin    = 20;
                popover.Content = table;
            }
//			popover.Padding.SetAll (20);
            popover.Show(Popover.Position.Top, (Button)sender);
        }
Exemplo n.º 25
0
        public async Task <Table> Read()
        {
            var filePaths = await this.GetParquetFilePaths();

            var    tableSegments = new List <Table>();
            var    filteredRows  = new List <Row>();
            Schema schema        = null;

            foreach (var parquetfilePath in filePaths)
            {
                var table = this.ReadParquetFile(parquetfilePath);
                if (schema == null)
                {
                    schema = table.Schema;
                }
                var dataFields      = table.Schema.GetDataFields();
                var nameColumnIndex = Array.FindIndex(dataFields, x => x.Name == "name");
                var rows            = table.AsEnumerable();
                filteredRows.AddRange(rows);
            }

            var resultTable = new Table(schema);

            foreach (var row in filteredRows)
            {
                resultTable.Add(row);
            }

            return(resultTable);
        }
Exemplo n.º 26
0
        public void List_read_write_structures()
        {
            Table t = new Table(
                new DataField <int>("id"),
                new ListField("structs",
                              new StructField("mystruct",
                                              new DataField <int>("id"),
                                              new DataField <string>("name"))));

            t.Add(1, new[] { new Row(1, "Joe"), new Row(2, "Bloggs") });
            t.Add(2, new[] { new Row(3, "Star"), new Row(4, "Wars") });

            Table t2 = WriteRead(t);

            Assert.Equal(t.ToString(), t2.ToString(), ignoreLineEndingDifferences: true);
        }
Exemplo n.º 27
0
        public override void Initialize()
        {
            BruhUi();

            Chat = new Label("inget mottaget").SetFontScale(3);

            Table.Add(Chat);

            Table.Row().SetPadTop(20);

            textFields = TextFieldStyle.Create(Color.White, Color.White, Color.Black, Color.DarkGray);

            textField = new TextField("", textFields);

            Table.Add(textField);

            Table.Row().SetPadTop(20);

            KörPå            = Table.Add(new TextButton("skicka", Skin.CreateDefaultSkin())).SetFillX().SetMinHeight(30).GetElement <TextButton>();
            KörPå.OnClicked += SickaMeddelade;

            Table.Row().SetPadRight(50);

            /*TextButton Kör = Table.Add(new TextButton("byebye borski" , Skin.CreateDefaultSkin())).SetFillX().SetMinHeight(30).GetElement<TextButton>();
             * Kör.OnClicked += Koppplafrån;*/
            Skin     skin     = Skin.CreateDefaultSkin();
            CheckBox checkbox = Table.Add(new CheckBox("Ready", skin)).GetElement <CheckBox>();

            checkbox.IsChecked  = false;
            checkbox.OnChanged += isChecked => { ReadyStart = isChecked; };
        }
Exemplo n.º 28
0
        public async Task <T> Add(T entity)
        {
            var result = Table.Add(entity);
            await Db.SaveChangesAsync();

            return(result.Entity);
        }
Exemplo n.º 29
0
        public void Flat_write_read()
        {
            var table = new Table(new Schema(new DataField <int>("id"), new DataField <string>("city")));
            var ms    = new MemoryStream();

            //generate fake data
            for (int i = 0; i < 1000; i++)
            {
                table.Add(new Row(i, "record#" + i));
            }

            //write to stream
            using (var writer = new ParquetWriter(table.Schema, ms))
            {
                writer.Write(table);
            }

            //read back into table
            ms.Position = 0;
            Table table2;

            using (var reader = new ParquetReader(ms))
            {
                table2 = reader.ReadAsTable();
            }

            //validate data
            Assert.True(table.Equals(table2, true));
        }
Exemplo n.º 30
0
 public void Save(Car car)
 {
     if (car.Car_ID == 0)
     {
         Table.Add(car);
     }
     else
     {
         Car dbEntry = Table.Find(car.Car_ID);
         if (dbEntry != null)
         {
             dbEntry.Body           = car.Body;
             dbEntry.Description    = car.Description;
             dbEntry.EngineCapacity = car.EngineCapacity;
             dbEntry.Fuel           = car.Fuel;
             dbEntry.GearboxType    = car.GearboxType;
             dbEntry.GradeID        = car.GradeID;
             dbEntry.Mark           = car.Mark;
             dbEntry.Model          = car.Model;
             dbEntry.NumberOfSeats  = car.NumberOfSeats;
             dbEntry.Year           = car.Year;
             dbEntry.Img            = car.Img;
         }
     }
     _dbContext.SaveChanges();
 }
Exemplo n.º 31
0
        static void PickAdvancement(Character result, Dice dice)
        {
            result.UnusedAdvances -= 1;

            if (result.UnusedEdges < 0)
                result.UnusedEdges += 1;
            else if (result.UnusedSkills < 0)
                result.UnusedSkills += 2; //pay back the skill point loan
            else if (result.UnusedSmartSkills < 0)
                result.UnusedSmartSkills += 2; //pay back the skill point loan
            else

            {
                switch (dice.Next(5))
                {
                    case 0:
                        result.UnusedEdges += 1;
                        break;
                    case 1: //increase a high skill

                        {
                            var table = new Table<Skill>();
                            foreach (var skill in result.Skills)
                            {
                                if (skill.Trait >= result.GetAttribute(skill.Attribute) && skill.Trait < 12)
                                    table.Add(skill, skill.Trait.Score);
                            }
                            if (table.Count == 0)
                                goto case 2;
                            table.RandomChoose(dice).Trait += 1;
                            break;
                        }
                    case 2: //increase a low skill

                        {
                            var table = new Table<Skill>();
                            foreach (var skill in result.Skills)
                            {
                                if (skill.Trait < result.GetAttribute(skill.Attribute) && skill.Trait < 12)
                                    table.Add(skill, skill.Trait.Score);
                            }
                            if (table.Count >= 2)
                                goto case 3;
                            table.RandomPick(dice).Trait += 1;
                            table.RandomPick(dice).Trait += 1; //use Pick so we get 2 different skills
                            break;
                        }
                    case 3: //add a new skill

                        {
                            var table = new Table<Skill>();
                            foreach (var skill in result.Skills)
                            {
                                if (skill.Trait == 0)
                                    table.Add(skill, result.GetAttribute(skill.Attribute).Score);
                            }
                            if (table.Count == 0)
                                break; //really?
                            table.RandomChoose(dice).Trait = 4;
                            break;
                        }
                    case 4:
                        result.UnusedAttributes += 1;
                        break;
                }
            }
        }
Exemplo n.º 32
0
        static void PickSkill(Character result, Dice dice, string attributeFilter = null)
        {
            bool allowHigh = result.UnusedSkills >= 2 && result.UnusedAttributes == 0; //don't buy expensive skills until all of the attributes are picked

            var table = new Table<Skill>();
            foreach (var item in result.Skills.Where(s => attributeFilter == null || s.Attribute == attributeFilter))
            {

                if (item.Trait == 0)
                    table.Add(item, result.GetAttribute(item.Attribute).Score - 3); //favor skills that match your attributes
                else if (item.Trait < result.GetAttribute(item.Attribute)) //favor improving what you know
                    table.Add(item, result.GetAttribute(item.Attribute).Score - 3 + item.Trait.Score);
                else if (allowHigh && item.Trait < 12)
                    table.Add(item, item.Trait.Score); //Raising skills above the controlling attribute is relatively rare
            }
            var skill = table.RandomChoose(dice);
            if (skill.Trait == 0)
            {
                result.UnusedSkills -= 1;
                skill.Trait = 4;
            }
            else if (skill.Trait < result.GetAttribute(skill.Attribute))
            {
                result.UnusedSkills -= 1;
                skill.Trait += 1;
            }
            else
            {
                result.UnusedSkills -= 2;
                skill.Trait += 1;
            }
        }
Exemplo n.º 33
0
        private static void TryFillFromExpandable(Table t, decimal index, object o)
        {
            var rl = o as IExpandable;

            if (rl == null)
                t.Add(index, o);
            else
            {
                var list = rl.ToList();

                foreach (var i in list)
                {
                    t.Add(index, i);
                    index++;
                }
            }
        }
Exemplo n.º 34
0
		Table Parse()
		{
			Table table = new Table();
			string name = null;
			Dictionary<object, string> comments = new Dictionary<object,string>();

			while (true) {
				Token token = ReadToken();

				if (token.type == TokenType.Comment) {
					comments[new object()] = (string)token.value;
					continue;
				}

				if (token.type == TokenType.CloseParen || 
				    token.type == TokenType.Ident || 
				    token.type == TokenType.Comma)
				{
					if (name != null)
						throw new InternalParseException(String.Format("Expecting value after '{0} ='", name));
				}
				
				if (token.type == TokenType.CloseParen || token.type == TokenType.EOF)
					break;
				
				if (token.type == TokenType.Ident) {
					name = (string)token.value;
					if (ReadToken().type != TokenType.Equals)
						throw new InternalParseException("Expecting '=' after '" + name + "'");
					continue;
				} 
				if (token.type == TokenType.Equals)
					throw new InternalParseException("Unexpected = token");
				
				object value = null;
				switch (token.type) {
					case TokenType.OpenParen:
						value = Parse();
						break;
					case TokenType.Int:
					case TokenType.Float:
					case TokenType.String:
						value = token.value;
						break;
				}
				if (value != null) {
					name = table.Add(value, name);
					if (comments.Count>0) {
						string comment = "";
						foreach (var kv in comments)
							 comment += kv.Value + "\n";
						table.Comments[table[name]] = comment;
						comments.Clear();
					}
					name = null;
				}
			}
			return table;
		}
Exemplo n.º 35
0
        static void PickAttribute(Character result, Dice dice)
        {
            //Attributes are likely to stack rather than spread evenly
            var table = new Table<string>();
            if (result.Vigor < 12)
                table.Add("Vigor", result.Vigor.Score);
            if (result.Smarts < 12)
                table.Add("Smarts", result.Smarts.Score);
            if (result.Agility < 12)
                table.Add("Agility", result.Agility.Score);
            if (result.Strength < 12)
                table.Add("Strength", result.Strength.Score);
            if (result.Spirit < 12)
                table.Add("Spirit", result.Spirit.Score);

            result.Increment(table.RandomChoose(dice));

            result.UnusedAttributes -= 1;
        }
Exemplo n.º 36
0
        public void AddNumKey()
        {
            var ta = new Table( 6, 0 );

            ta.Add( 1, Math.PI );
            Assert.AreEqual( Math.PI, ta[1] );
        }