public void Init(string configType, int player, NVector pos, Dictionary <string, int> cost) { Debug.Log($"{player}: Create unit {configType} at {pos}"); baseData = dataUnit = L.b.units[configType]; var calc = CalculatedData.Calc(dataUnit, cost); data = new BuildingUnitData(); data.UnitInit(this, configType, -1, player, calc); data.pos = pos.Clone(); //has a town? Town t = S.Towns().NearestTown(S.Player(player), pos, false); if (t != null) { int buildtime = L.b.modifiers[C.BuildRes].CalcModi(calc.buildTime, S.Player(player), pos); data.townId = t.id; gameObject.AddComponent <Construction>().Init(data, cost, this, buildtime); S.Player(player).fog.Clear(pos); } else { Clear(pos); } FinishInit(); }
public override void ShowDetail(PanelBuilder panel) { _build.AddImageLabel(panel); panel.AddResT("constructionCost", _cost); panel.AddHeaderLabelT("general"); var hpap = CalculatedData.Calc(_build, _cost); panel.AddSubLabelT("hp", hpap.hp, "hp"); panel.AddSubLabelT("ap", hpap.ap, "ap"); var b = L.b.modifiers[C.BuildRes].CalcText(hpap.buildTime, S.ActPlayer(), pos); L.b.res[C.BuildRes].AddSubLabel(panel, b.value, "round", b.display); panel.AddButtonT("reset", (() => { _cost = new Dictionary <string, int>(_costOrg); ReCalc(0); })); //what replace? if (!_cost.ContainsKey(replace.id)) { panel.AddLabel(S.T("constructionOwnReplaceNothing", _build.Name())); return; } panel.AddHeaderLabel(S.T("constructionOwnReplace", replace.Text(_cost[replace.id]))); //build dropdown List <string> values = new List <string>(); List <string> titles = new List <string>(); foreach (Resource r in L.b.res.GetAllByCategory(replace.id)) { if (r.special == false && _town.KnowRes(r.id)) { values.Add(r.id); titles.Add(r.Text(_town.GetRes(r.id))); } } panel.AddDropdown(values.ToArray(), values[0], titles.ToArray(), s => { selected = L.b.res[s]; UpdateButton(); }); _one = panel.AddImageTextButton("", "logo", () => { ReCalc(1); }); _ten = panel.AddImageTextButton("", "logo", () => { ReCalc(10); }); max = panel.AddImageTextButton("", "logo", () => { ReCalc(Math.Min(_cost[replace.id], _town.GetRes(selected.id))); }); total = panel.AddImageTextButton("", "logo", () => { ReCalc(_cost[replace.id]); }); selected = L.b.res[values[0]]; UpdateButton(); }
public override void ShowDetail(PanelBuilder panel) { build.AddImageLabel(panel); panel.AddResT("constructionCost", cost); panel.AddHeaderLabelT("general"); var hpap = CalculatedData.Calc(build, cost); panel.AddSubLabelT("hp", hpap.hp, "hp"); panel.AddSubLabelT("ap", hpap.ap, "ap"); var b = L.b.modifiers[C.BuildRes].CalcText(hpap.buildTime, S.ActPlayer(), pos); L.b.res[C.BuildRes].AddSubLabel(panel, b.value, "round", b.display); }
public void Init(int town, string configType, NVector pos, Dictionary <string, int> cost) { Debug.Log($"Create building {configType} at {pos} for town {town}"); baseData = dataBuilding = L.b.buildings[configType]; var calc = CalculatedData.Calc(dataBuilding, cost); data = new BuildingUnitData(); data.BuildingInit(this, configType, town, calc); data.pos = pos.Clone(); int buildtime = L.b.modifiers[C.BuildRes].CalcModi(calc.buildTime, S.Towns().Get(town).Player(), pos); gameObject.AddComponent <Construction>().Init(data, cost, this, buildtime); S.Player(Town().playerId).fog.Clear(pos); FinishInit(); }
public IActionResult Update([FromBody] List <AnalyzeData> analyzeDatas) { return(ActionExecute(() => { var file = SessionExtension.Get <FileData>(session, Key.File); var controlFlowGraphJson = session.GetString(Key.ControlFlowGraph.ToString("g")); var dataFlowGraphJson = session.GetString(Key.DataFlowGraph.ToString("g")); var analyzers = new List <Analyzer>(); if (file == null || controlFlowGraphJson == null || dataFlowGraphJson == null) { return BadRequest("Kérem töltsön fel először fájlt!"); } analyzeDatas.ForEach(x => { analyzers.Add(new Analyzer(controlFlowGraphJson, dataFlowGraphJson, x, file.Content)); }); Parallel.ForEach(analyzers, (analyzer) => { analyzer.Analyze(); analyzer.FinishOperations(); }); analyzers.DistinctGraphs(out List <List <ViewNode> > controlFlowGraphs, out List <List <ViewNode> > dataFlowGraphs); analyzers.CreateCharts(out BarChartData readAndWriteChartData, out PieChartData useVariable, out PieChartData useful, out BarChartData headers); var calculateData = new CalculatedData { ControlFlowGraphs = controlFlowGraphs, DataFlowGraphs = dataFlowGraphs, ReadAndWriteChartData = readAndWriteChartData, UseVariable = useVariable, Useful = useful, Headers = headers, File = file }; return Ok(calculateData); })); }
public void UpdateTest(int no) { var analyzerController = new AnalyzerController(mockHttpContextAccessor.Object); var file = new FileData { Name = "Valami", Content = System.IO.File.ReadAllText($@"..\..\..\..\AngularApp\Files\demo{no}.txt") }; var value = Encoding.ASCII.GetBytes(JsonSerializer.Serialize(file)); mockSession.Setup(_ => _.TryGetValue(Key.File.ToString("g"), out value)).Returns(true); var content = file.Content; var controlFlowGraph = P4ToGraph.ControlFlowGraph(ref content); var controlValue = Encoding.ASCII.GetBytes(controlFlowGraph.ToJson()); mockSession.Setup(_ => _.TryGetValue(Key.ControlFlowGraph.ToString("g"), out controlValue)).Returns(true); var dataFlowGraph = P4ToGraph.DataFlowGraph(content, controlFlowGraph); var dataValue = Encoding.ASCII.GetBytes(dataFlowGraph.ToJson()); mockSession.Setup(_ => _.TryGetValue(Key.DataFlowGraph.ToString("g"), out dataValue)).Returns(true); var analyzeDatas = new List <AnalyzeData>(); for (var i = 0; i < 5; ++i) { var structs = Analyzer.GetStructs(file.Content); var _struct = structs.FirstOrDefault(x => x.Name == "headers_t"); Random random = new Random(); var randomNumber = random.Next(0, 2); var ethernet = _struct.Headers["ethernet"]; if (randomNumber == 1) { ethernet.Valid = true; ethernet.Variables.ForEach(x => x.IsInitialize = true); } randomNumber = random.Next(0, 2); var ipv4 = _struct.Headers["ipv4"]; if (randomNumber == 1) { ipv4.Valid = true; ipv4.Variables.ForEach(x => x.IsInitialize = true); } analyzeDatas.Add(new AnalyzeData { Id = i, StartState = structs, EndState = structs }); } var result = analyzerController.Update(analyzeDatas); var objectResult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsAssignableFrom <CalculatedData>(objectResult.Value); var analyzers = new List <Analyzer>(); analyzeDatas.ForEach(x => { analyzers.Add(new Analyzer(controlFlowGraph.ToJson(), dataFlowGraph.ToJson(), x, file.Content)); }); Parallel.ForEach(analyzers, (analyzer) => { analyzer.Analyze(); analyzer.FinishOperations(); }); analyzers.DistinctGraphs(out List <List <ViewNode> > controlFlowGraphs, out List <List <ViewNode> > dataFlowGraphs); analyzers.CreateCharts(out BarChartData readAndWriteChartData, out PieChartData useVariable, out PieChartData useful, out BarChartData headers); var calculateData = new CalculatedData { ControlFlowGraphs = controlFlowGraphs, DataFlowGraphs = dataFlowGraphs, ReadAndWriteChartData = readAndWriteChartData, UseVariable = useVariable, Useful = useful, Headers = headers, File = file }; Assert.Equal(calculateData.File.Name, model.File.Name); Assert.Equal(calculateData.File.Content, model.File.Content); CompareBarChartData(calculateData.ReadAndWriteChartData, model.ReadAndWriteChartData); CompareBarChartData(calculateData.Headers, model.Headers); ComparePieChartData(calculateData.UseVariable, model.UseVariable); ComparePieChartData(calculateData.Useful, model.Useful); }