-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBindDataCommand.cs
More file actions
75 lines (55 loc) · 1.67 KB
/
BindDataCommand.cs
File metadata and controls
75 lines (55 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using UnityEngine;
using strange.extensions.command.impl;
namespace Snake
{
public class BindDataCommand : Command
{
[Inject]
public IDataConfigService DataConfigService { get; set; }
[Inject]
public IHighScoreService HighScoreService { get; set; }
public override void Execute ()
{
DataConfigService.GetDataConfig ().Then (BindData);
}
private void BindData (DataConfig data)
{
Camera.main.backgroundColor = data.BackgroundColor;
BindGrid (data.Grid);
BindPellet (data.Pellet, data.Grid);
BindSnake (data.Snake);
BindGame (data);
}
private void BindGrid (GridConfig g)
{
var grid = new Grid (g.Rows, g.Columns);
injectionBinder.Bind<IGrid> ().ToValue (grid).ToSingleton ();
}
private void BindPellet (PelletConfig p, GridConfig g)
{
while ((p.RowInset << 1) >= g.Rows)
{
p.RowInset >>= 1;
}
while ((p.ColumnInset << 1) >= g.Columns)
{
p.ColumnInset >>= 1;
}
var pellet = new Pellet (p.Color, p.RowInset, p.ColumnInset);
injectionBinder.Bind<IPellet> ().ToValue (pellet).ToSingleton ();
}
private void BindSnake (SnakeConfig s)
{
var snake = new Snake (s.HeadColor, s.BodyColor, s.InitialSize);
injectionBinder.Bind<ISnake> ().ToValue (snake).ToSingleton ();
}
private void BindGame (DataConfig d)
{
var g = d.Grid;
var p = d.Pellet;
var maxScore = (g.Rows - (p.RowInset << 1)) * (g.Columns - (p.ColumnInset << 1));
var game = new Game (maxScore, d.TimeSkipPerFrame);
injectionBinder.Bind<IGame> ().ToValue (game).ToSingleton ();
}
}
}