forked from julapy/ofxFlashLite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathofxFlashXFL.cpp
More file actions
194 lines (151 loc) · 4.57 KB
/
Copy pathofxFlashXFL.cpp
File metadata and controls
194 lines (151 loc) · 4.57 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* ofxFlashFXL.cpp
* emptyExample
*
* Created by lukasz karluk on 3/11/10.
* Copyright 2010 __MyCompanyName__. All rights reserved.
*
*/
#include "ofxFlashXFL.h"
ofxFlashXFL :: ofxFlashXFL()
{
bLoaded = false;
}
ofxFlashXFL :: ~ofxFlashXFL()
{
//
}
///////////////////////////////////////////
//
///////////////////////////////////////////
vector<DOMBitmapItem> domBitmapItems;
vector<SymbolItem> symbolItems;
///////////////////////////////////////////
// LOAD XFL.
///////////////////////////////////////////
bool ofxFlashXFL :: loadFile ( const string& file )
{
vector<string> xflFileSplit;
xflFileSplit = ofSplitString( file, "/" );
xflFile = xflFileSplit[ xflFileSplit.size() - 1 ];
xflFolder = "";
for( int i=0; i<xflFileSplit.size()-1; i++ ) // drop the file
{
xflFolder += xflFileSplit[ i ] + "/";
}
string xflPath;
xflPath = xflFolder + xflFile;
cout << "Loading, " << xflPath << endl;
bLoaded = xml.loadFile( xflPath );
if( !bLoaded )
{
cout << "DOMDocument.xml did not load." << endl;
return bLoaded;
}
loadXFLMedia();
loadXFLSymbols();
loadAssets();
return bLoaded;
}
void ofxFlashXFL :: loadXFLMedia ()
{
xml.pushTag( "DOMDocument", 0 );
if( !xml.tagExists( "media", 0 ) )
return;
xml.pushTag( "media", 0 );
int numOfMediaTags;
numOfMediaTags = xml.getNumTags( "DOMBitmapItem" );
for( int i=0; i<numOfMediaTags; i++ )
{
DOMBitmapItem item;
item.name = xml.getAttribute( "DOMBitmapItem", "name", "", i );
item.itemID = xml.getAttribute( "DOMBitmapItem", "itemID", "", i );
item.sourceExternalFilepath = xml.getAttribute( "DOMBitmapItem", "sourceExternalFilepath", "", i );
item.sourceLastImported = xml.getAttribute( "DOMBitmapItem", "sourceLastImported", 0, i );
item.sourcePlatform = xml.getAttribute( "DOMBitmapItem", "sourcePlatform", "", i );
item.externalFileSize = xml.getAttribute( "DOMBitmapItem", "externalFileSize", 0, i );
item.originalCompressionType = xml.getAttribute( "DOMBitmapItem", "originalCompressionType", "", i );
item.quality = xml.getAttribute( "DOMBitmapItem", "quality", 0, i );
item.href = xml.getAttribute( "DOMBitmapItem", "href", "", i );
item.bitmapDataHRef = xml.getAttribute( "DOMBitmapItem", "bitmapDataHRef", "", i );
item.frameRight = xml.getAttribute( "DOMBitmapItem", "frameRight", 0, i );
item.frameBottom = xml.getAttribute( "DOMBitmapItem", "frameBottom", 0, i );
domBitmapItems.push_back( item );
}
xml.popTag();
}
void ofxFlashXFL :: loadXFLSymbols ()
{
if( !xml.tagExists( "symbols", 0 ) ){
return;
}
xml.pushTag( "symbols", 0 );
int numOfSymbolTags;
numOfSymbolTags = xml.getNumTags( "Include" );
for( int i=0; i<numOfSymbolTags; i++ )
{
SymbolItem item;
string href = xml.getAttribute( "Include", "href", "", i );
item.href= href;
vector<string> elems;
elems = ofSplitString( href, "/" );
string name = elems[elems.size() - 1];
elems= ofSplitString( name, "." );
name = elems[0];
item.name= name;
symbolItems.push_back( item );
}
xml.popTag();
}
///////////////////////////////////////////
// LOAD ASSETS.
///////////////////////////////////////////
void ofxFlashXFL :: loadAssets ()
{
ofxFlashLibrary* library;
library = ofxFlashLibrary :: getInstance();
for( int i=0; i<domBitmapItems.size(); i++ )
{
const DOMBitmapItem& item = domBitmapItems[ i ];
int mediaType = determineMediaType( item.sourceExternalFilepath );
string path = xflFolder + item.sourceExternalFilepath;
cout << "loading asset :: " << path << endl;
if( mediaType == OFX_FLASH_LIBRARY_TYPE_IMAGE )
{
library->addImage( item.name, path );
}
else if( mediaType == OFX_FLASH_LIBRARY_TYPE_VIDEO )
{
library->addVideo( item.name, path );
}
else if( mediaType == OFX_FLASH_LIBRARY_TYPE_SOUND )
{
library->addSound( item.name, path );
}
}
// load symbols
for( int i=0; i<symbolItems.size(); i++ )
{
const SymbolItem& item = symbolItems[ i ];
string path = xflFolder + "LIBRARY/" + item.href;
library->addSymbol( item.name, path );
}
}
int ofxFlashXFL :: determineMediaType ( string fileName )
{
return OFX_FLASH_LIBRARY_TYPE_IMAGE; // TODO :: work out correct file type.
}
///////////////////////////////////////////
// BUILD.
///////////////////////////////////////////
void ofxFlashXFL :: build ()
{
if( !bLoaded )
return;
ofxFlashStage* stage;
stage = ofxFlashStage :: getInstance();
ofxFlashXFLBuilder* builder;
builder = new ofxFlashXFLBuilder();
builder->build( xflFolder + xflFile, stage->root() );
stage->update();
}