Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- Colorizer class |
2 | -- |
3 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
4 | |
5 | Colorizer = {} |
6 | |
7 | local Colorizer_mt = Class(Colorizer); |
8 | |
9 | function Colorizer:onCreate(id) |
10 | g_currentMission:addNonUpdateable(Colorizer:new(id)); |
11 | end; |
12 | |
13 | function Colorizer:new(name) |
14 | local self = {}; |
15 | setmetatable(self, Colorizer_mt); |
16 | self.me = name; |
17 | |
18 | local colors = {}; |
19 | local xmlFileName = Utils.getNoNil(getUserAttribute(name, "xmlFile"), ""); |
20 | xmlFileName = Utils.getFilename(xmlFileName, g_currentMission.loadingMapBaseDirectory); |
21 | if xmlFileName ~= "" then |
22 | local xmlFile = loadXMLFile("colors.xml", xmlFileName); |
23 | |
24 | local i = 0; |
25 | while true do |
26 | local key = string.format("colors.color(%d)", i); |
27 | local colorName = getXMLString(xmlFile, key .. "#colorName"); |
28 | local rgb = getXMLString(xmlFile, key .. "#color"); |
29 | if rgb == nil then |
30 | break; |
31 | end; |
32 | local r, g, b = Utils.getVectorFromString(rgb); |
33 | if r ~= nil and g ~= nil and b ~= nil then |
34 | table.insert(colors, {r = r, g = g, b = b, colorName = colorName}); |
35 | end; |
36 | i = i + 1; |
37 | end; |
38 | |
39 | delete(xmlFile); |
40 | |
41 | local numberOfColorObjects = getNumOfChildren(name); |
42 | |
43 | for i = 1, numberOfColorObjects do |
44 | local currentColorObject = getChildAt(name, i - 1); |
45 | local colorIndex = math.random(1, table.getn(colors)); |
46 | setShaderParameter(currentColorObject, "colorTint", colors[colorIndex].r, colors[colorIndex].g, colors[colorIndex].b, 1, false); |
47 | end; |
48 | end; |
49 | |
50 | return self; |
51 | end; |
52 | |
53 | function Colorizer:delete() |
54 | |
55 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de