|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ObjectData.java | 40% | 76.5% | 66.7% | 67.9% |
|
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 |
|
|
31 |
/**
|
|
32 |
* Stores the 3D data that will go into a full blown 3D object. This class
|
|
33 |
* stores arrays of appearances, quads, and triangles. This class also contains
|
|
34 |
* functionality for writing out the data into a text format, and parsing that
|
|
35 |
* same text format.
|
|
36 |
*
|
|
37 |
* @author Jeff Weston
|
|
38 |
*/
|
|
39 |
public class ObjectData extends BrokerableObject |
|
40 |
{ |
|
41 |
/**
|
|
42 |
* The quad data for this 3D object.
|
|
43 |
*/
|
|
44 |
private QuadArrayData quadArrayData;
|
|
45 |
|
|
46 |
/**
|
|
47 |
* The triangle data for this 3D object.
|
|
48 |
*/
|
|
49 |
private TriangleArrayData triangleArrayData;
|
|
50 |
|
|
51 |
/**
|
|
52 |
* The name of this <code>ObjectData</code>.
|
|
53 |
*/
|
|
54 |
private String name;
|
|
55 |
|
|
56 |
/**
|
|
57 |
* Construct this 3D definition with the given name and the initial
|
|
58 |
* <code>QuadArrayData</code> and <code>TriangleArrayData</code>.
|
|
59 |
*
|
|
60 |
* @param name the name of this <code>ObjectData</code>
|
|
61 |
* @param quadArrayData the initial <code>QuadArrayData</code> to use
|
|
62 |
* @param triangleArrayData the initial <code>TriangleArrayData</code> to
|
|
63 |
* use
|
|
64 |
*/
|
|
65 | 5 |
public ObjectData( String name, QuadArrayData quadArrayData,
|
66 |
TriangleArrayData triangleArrayData ) |
|
67 |
{ |
|
68 | 5 |
this.name = name;
|
69 |
|
|
70 | 5 |
if ( quadArrayData == null ) |
71 |
{ |
|
72 | 5 |
this.quadArrayData = new QuadArrayData( ); |
73 |
} |
|
74 |
else
|
|
75 |
{ |
|
76 | 0 |
this.quadArrayData = quadArrayData;
|
77 |
} |
|
78 |
|
|
79 | 5 |
if ( triangleArrayData == null ) |
80 |
{ |
|
81 | 5 |
this.triangleArrayData = new TriangleArrayData( ); |
82 |
} |
|
83 |
else
|
|
84 |
{ |
|
85 | 0 |
this.triangleArrayData = triangleArrayData;
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
/**
|
|
90 |
* Construct this 3D definition using text representing an encoded form of
|
|
91 |
* this object's data.
|
|
92 |
*
|
|
93 |
* @param data the encoded data
|
|
94 |
*
|
|
95 |
* @throws VRMooParseException for any parsing errors that occur
|
|
96 |
*/
|
|
97 | 1 |
public ObjectData( String data ) throws VRMooParseException |
98 |
{ |
|
99 | 1 |
name = null;
|
100 | 1 |
replaceData( data ); |
101 |
} |
|
102 |
|
|
103 |
/**
|
|
104 |
* Replace the data stored in this class with the data stored in another
|
|
105 |
* <code>ObjectData</code> class.
|
|
106 |
*
|
|
107 |
* @param objectData the <code>ObjectData</code> to copy the data from
|
|
108 |
*/
|
|
109 | 2 |
public synchronized void replaceData( ObjectData objectData ) |
110 |
{ |
|
111 | 2 |
this.quadArrayData = objectData.quadArrayData;
|
112 | 2 |
this.triangleArrayData = objectData.triangleArrayData;
|
113 | 2 |
fireBrokerableObjectChanged( ); |
114 |
} |
|
115 |
|
|
116 |
/**
|
|
117 |
* Replace the data stored in this class with the data encoded in a passed
|
|
118 |
* in <code>String</code>.
|
|
119 |
*
|
|
120 |
* @param data the encoded data to replace this class' data with
|
|
121 |
*
|
|
122 |
* @throws VRMooParseException for any parsing errors that occur
|
|
123 |
*/
|
|
124 | 1 |
public synchronized void replaceData( String data ) |
125 |
throws VRMooParseException
|
|
126 |
{ |
|
127 | 1 |
int nameStart = data.indexOf( "\"" ); |
128 | 1 |
int nameEnd = data.indexOf( "\"", nameStart + 1 ); |
129 |
|
|
130 | 1 |
if ( ( nameStart != -1 ) &&
|
131 |
( nameEnd != -1 ) ) |
|
132 |
{ |
|
133 | 1 |
name = data.substring( nameStart + 1, nameEnd ); |
134 |
} |
|
135 |
else
|
|
136 |
{ |
|
137 | 0 |
throw new VRMooParseException( "Unable to parse object name." ); |
138 |
} |
|
139 |
|
|
140 | 1 |
int quadStart = data.indexOf( "{" ); |
141 | 1 |
int quadEnd = data.indexOf( "}", quadStart ); |
142 | 1 |
int triangleStart = data.indexOf( "{", quadEnd ); |
143 | 1 |
int triangleEnd = data.indexOf( "}", triangleStart ); |
144 |
|
|
145 | 1 |
if ( ( quadStart != -1 ) &&
|
146 |
( quadEnd != -1 ) && |
|
147 |
( triangleStart != -1 ) && |
|
148 |
( triangleEnd != -1 ) ) |
|
149 |
{ |
|
150 | 1 |
String quad = data.substring( quadStart + 1, |
151 |
quadEnd ); |
|
152 |
|
|
153 | 1 |
String triangle = data.substring( triangleStart + 1, |
154 |
triangleEnd ); |
|
155 |
|
|
156 | 1 |
quadArrayData = new QuadArrayData ( quad );
|
157 | 1 |
triangleArrayData = new TriangleArrayData ( triangle );
|
158 |
} |
|
159 |
else
|
|
160 |
{ |
|
161 | 0 |
throw new VRMooParseException( "Unable to parse object data." ); |
162 |
} |
|
163 | 1 |
fireBrokerableObjectChanged( ); |
164 |
} |
|
165 |
|
|
166 |
/**
|
|
167 |
* Get the quad data for this 3D object.
|
|
168 |
*
|
|
169 |
* @return the quad data for this 3D object.
|
|
170 |
*/
|
|
171 | 0 |
public synchronized QuadArrayData getQuadArrayData( ) |
172 |
{ |
|
173 | 0 |
return quadArrayData;
|
174 |
} |
|
175 |
|
|
176 |
/**
|
|
177 |
* Get the triangle data for this 3D object.
|
|
178 |
*
|
|
179 |
* @return the triangle data for this 3D object
|
|
180 |
*/
|
|
181 | 0 |
public synchronized TriangleArrayData getTriangleArrayData( ) |
182 |
{ |
|
183 | 0 |
return triangleArrayData;
|
184 |
} |
|
185 |
|
|
186 |
/**
|
|
187 |
* Convert this 3D object to its encoded <code>String</code> representation.
|
|
188 |
*
|
|
189 |
* @return the encoded <code>String</code>
|
|
190 |
*/
|
|
191 | 6 |
public synchronized String toEncodedString( ) |
192 |
{ |
|
193 | 6 |
return "\"" + name + "\", " + |
194 |
"{ " + quadArrayData.toEncodedString( ) + " }, " + |
|
195 |
"{ " + triangleArrayData.toEncodedString( ) + " }"; |
|
196 |
} |
|
197 |
|
|
198 |
/**
|
|
199 |
* Getter for the name of this <code>ObjectData</code>.
|
|
200 |
*
|
|
201 |
* @return the name of this <code>ObjectData</code>
|
|
202 |
*/
|
|
203 | 10 |
public synchronized String getName( ) |
204 |
{ |
|
205 | 10 |
return name;
|
206 |
} |
|
207 |
|
|
208 |
/**
|
|
209 |
* Setter for the name of this <code>ObjectData</code>. The ID will only be
|
|
210 |
* set if it hasn't been set once already. Once the ID has been set, it
|
|
211 |
* cannot be changed.
|
|
212 |
*
|
|
213 |
* @param name the name of this <code>ObjectData</code>
|
|
214 |
*/
|
|
215 | 0 |
public synchronized void setName( String name ) |
216 |
{ |
|
217 | 0 |
if ( this.name == null ) |
218 |
{ |
|
219 | 0 |
this.name = name;
|
220 |
} |
|
221 |
} |
|
222 |
} |
|
223 |
|
|