BlueGit

timfa raytracer

Files

raytracer / src / tiles.js

tiles.js

tiles.js 961 B Download Raw
1/** Tile table; Image fields filled after preload. */
2var Tiles =
3{
4 Nothing:
5 {
6 ID: 0,
7 Color: { R: 255, G: 255, B: 255 },
8 Solid: false,
9 ImageName: null
10 },
11 Stone:
12 {
13 ID: 1,
14 Color: { R: 155, G: 155, B: 155 },
15 Solid: true,
16 ImageName: "stone"
17 },
18 Finish:
19 {
20 ID: 2,
21 Color: { R: 255, G: 255, B: 0 },
22 Solid: false,
23 ImageName: null
24 },
25 Wood:
26 {
27 ID: 3,
28 Color: { R: 168, G: 102, B: 50 },
29 Solid: true,
30 ImageName: "wood"
31 },
32 findByID: function (id)
33 {
34 for (var key in Tiles)
35 {
36 if (!Object.prototype.hasOwnProperty.call(Tiles, key))
37 { continue; }
38 var value = Tiles[key];
39 if (value && value.ID === id)
40 { return value; }
41 }
42 return null;
43 },
44 bindImages: function (images)
45 {
46 for (var key in Tiles)
47 {
48 if (!Object.prototype.hasOwnProperty.call(Tiles, key))
49 { continue; }
50 var tile = Tiles[key];
51 if (tile && tile.ImageName && images[tile.ImageName])
52 { tile.Image = images[tile.ImageName]; }
53 }
54 }
55};