|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
AppearanceData.java | 50% | 93.9% | 100% | 91.3% |
|
1 |
/*
|
|
2 |
|
|
3 |
VRMoo Common - Virtual Reality Object Oriented MUD Common Code
|
|
4 |
Copyright (C) 2003 VRMoo Development Team
|
|
5 |
|
|
6 |
|
|
7 |
This program is free software; you can redistribute it and/or modify
|
|
8 |
it under the terms of the GNU General Public License as published by
|
|
9 |
the Free Software Foundation; either version 2 of the License, or
|
|
10 |
(at your option) any later version.
|
|
11 |
|
|
12 |
This program is distributed in the hope that it will be useful,
|
|
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 |
GNU General Public License for more details.
|
|
16 |
|
|
17 |
You should have received a copy of the GNU General Public License
|
|
18 |
along with this program; if not, write to the Free Software
|
|
19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
20 |
|
|
21 |
|
|
22 |
For information about VRMoo and its authors, please visit the website:
|
|
23 |
http://www.vrmoo.org/
|
|
24 |
|
|
25 |
*/
|
|
26 |
|
|
27 |
package org.vrmoo.common.data;
|
|
28 |
|
|
29 |
import org.vrmoo.common.exception.VRMooParseException;
|
|
30 |
import org.vrmoo.common.util.ParserUtility;
|
|
31 |
|
|
32 |
/**
|
|
33 |
* Stores the appearance data that will be referenced by various 3D elements.
|
|
34 |
* Also contains functionality for writing out the data into a text format, and
|
|
35 |
* parsing that same text format.
|
|
36 |
*
|
|
37 |
*@author Jeff Weston
|
|
38 |
*/
|
|
39 |
public class AppearanceData extends BrokerableObject { |
|
40 |
/**
|
|
41 |
* The name for this appearance.
|
|
42 |
*/
|
|
43 |
private String name;
|
|
44 |
|
|
45 |
/**
|
|
46 |
* The name of the texture for this appearance.
|
|
47 |
*/
|
|
48 |
private String textureName;
|
|
49 |
|
|
50 |
/**
|
|
51 |
* Contains the red component of the material data.
|
|
52 |
*/
|
|
53 |
private float colorRed; |
|
54 |
|
|
55 |
/**
|
|
56 |
* Contains the green component of the material data.
|
|
57 |
*/
|
|
58 |
private float colorGreen; |
|
59 |
|
|
60 |
/**
|
|
61 |
* Contains the blue component of the material data.
|
|
62 |
*/
|
|
63 |
private float colorBlue; |
|
64 |
|
|
65 |
/**
|
|
66 |
* Contains the relative "shininess" value
|
|
67 |
*/
|
|
68 |
private float shininess; |
|
69 |
|
|
70 |
|
|
71 |
/**
|
|
72 |
* Construct an instance of this class with a given texture name and
|
|
73 |
* paramaterized values for the color data.
|
|
74 |
*
|
|
75 |
*@param name the name of this appearance
|
|
76 |
*@param textureName the name of the texture for this appearance
|
|
77 |
*@param colorRed the red component of the color data
|
|
78 |
*@param colorGreen the green component of the color data
|
|
79 |
*@param colorBlue the blue component of the color data
|
|
80 |
*@param shininess Description of the Parameter
|
|
81 |
*/
|
|
82 | 13 |
public AppearanceData( String name,
|
83 |
String textureName, |
|
84 |
float colorRed,
|
|
85 |
float colorGreen,
|
|
86 |
float colorBlue,
|
|
87 |
float shininess ) {
|
|
88 | 13 |
this.name = name;
|
89 | 13 |
this.textureName = textureName;
|
90 | 13 |
this.colorRed = colorRed;
|
91 | 13 |
this.colorGreen = colorGreen;
|
92 | 13 |
this.colorBlue = colorBlue;
|
93 | 13 |
this.shininess = shininess;
|
94 |
} |
|
95 |
|
|
96 |
|
|
97 |
/**
|
|
98 |
* Construct an instance of this class using text representing encoded
|
|
99 |
* appearance data.
|
|
100 |
*
|
|
101 |
*@param data the encoded appearance data
|
|
102 |
*@exception VRMooParseException Description of the Exception
|
|
103 |
*@throws VRMooParseException for any parsing errors that occur
|
|
104 |
*/
|
|
105 | 11 |
public AppearanceData( String data )
|
106 |
throws VRMooParseException {
|
|
107 | 11 |
int nameStart = data.indexOf( "\"" ); |
108 | 11 |
int nameEnd = data.indexOf( "\"", nameStart + 1 ); |
109 |
|
|
110 | 11 |
if ( ( nameStart != -1 ) &&
|
111 |
( nameEnd != -1 ) ) { |
|
112 | 11 |
name = data.substring( nameStart + 1, nameEnd ); |
113 |
} |
|
114 |
else {
|
|
115 | 0 |
throw new VRMooParseException( "Unable to parse appearance name." ); |
116 |
} |
|
117 |
|
|
118 | 11 |
int appearanceStart = data.indexOf( "(" ); |
119 | 11 |
int appearanceEnd = data.indexOf( ")", appearanceStart ); |
120 |
|
|
121 | 11 |
if ( ( appearanceStart != -1 ) &&
|
122 |
( appearanceEnd != -1 ) ) { |
|
123 | 11 |
String appearance = data.substring( appearanceStart + 1, |
124 |
appearanceEnd ); |
|
125 | 11 |
int textureEnd = appearance.indexOf( "," ); |
126 | 11 |
textureName = appearance.substring( 0, textureEnd ).trim(); |
127 |
|
|
128 | 11 |
int shininessEnd = appearance.lastIndexOf( "," ); |
129 | 11 |
String shineValue = appearance.substring( shininessEnd + 1 ).trim(); |
130 | 11 |
shininess = ParserUtility.parseFloat( shineValue ); |
131 |
|
|
132 | 11 |
String color = appearance.substring( textureEnd + 1, shininessEnd |
133 |
).trim(); |
|
134 | 11 |
float f[] = ParserUtility.parseFloatArray( color, 3 );
|
135 | 11 |
colorRed = f[0]; |
136 | 11 |
colorGreen = f[1]; |
137 | 11 |
colorBlue = f[2]; |
138 |
|
|
139 |
} |
|
140 |
else {
|
|
141 | 0 |
throw new VRMooParseException( "Unable to parse appearance data." ); |
142 |
} |
|
143 |
} |
|
144 |
|
|
145 |
|
|
146 |
/**
|
|
147 |
* Get the name for this appearance.
|
|
148 |
*
|
|
149 |
*@return the name for this appearance
|
|
150 |
*/
|
|
151 | 51 |
public String getName() {
|
152 | 51 |
return name;
|
153 |
} |
|
154 |
|
|
155 |
|
|
156 |
/**
|
|
157 |
* Get the texture name for this appearance.
|
|
158 |
*
|
|
159 |
*@return the texture name for this appearance
|
|
160 |
*/
|
|
161 | 5 |
public String getTextureName() {
|
162 | 5 |
return textureName;
|
163 |
} |
|
164 |
|
|
165 |
|
|
166 |
/**
|
|
167 |
* Get the red component of the Color data.
|
|
168 |
*
|
|
169 |
*@return the red component of the Color data
|
|
170 |
*/
|
|
171 | 5 |
public float getColorRed() { |
172 | 5 |
return colorRed;
|
173 |
} |
|
174 |
|
|
175 |
|
|
176 |
/**
|
|
177 |
* Get the green component of the Color data.
|
|
178 |
*
|
|
179 |
*@return the green component of the Color data
|
|
180 |
*/
|
|
181 | 5 |
public float getColorGreen() { |
182 | 5 |
return colorGreen;
|
183 |
} |
|
184 |
|
|
185 |
|
|
186 |
/**
|
|
187 |
* Get the blue component of the Color data.
|
|
188 |
*
|
|
189 |
*@return the blue component of the Color data
|
|
190 |
*/
|
|
191 | 5 |
public float getColorBlue() { |
192 | 5 |
return colorBlue;
|
193 |
} |
|
194 |
|
|
195 |
|
|
196 |
/**
|
|
197 |
* Get the shininess value for the material
|
|
198 |
*
|
|
199 |
*@return The shininess value
|
|
200 |
*/
|
|
201 | 4 |
public float getShininess() { |
202 | 4 |
return shininess;
|
203 |
} |
|
204 |
|
|
205 |
|
|
206 |
/**
|
|
207 |
* Convert this appearance to its encoded <code>String</code>
|
|
208 |
* representation.
|
|
209 |
*
|
|
210 |
*@return the encoded <code>String</code>
|
|
211 |
*/
|
|
212 | 32 |
public String toEncodedString() {
|
213 | 32 |
return "\"" + name + "\", " + "( " + |
214 |
textureName + ", " +
|
|
215 |
colorRed + ", " +
|
|
216 |
colorGreen + ", " +
|
|
217 |
colorBlue + ", " +
|
|
218 |
shininess + " )";
|
|
219 |
} |
|
220 |
} |
|
221 |
|
|
222 |
|
|