Skip to content

Commit fc2775f

Browse files
first attempt at sprites
1 parent 5ddc0b1 commit fc2775f

File tree

6 files changed

+57
-26
lines changed

6 files changed

+57
-26
lines changed

bin/data/code/1.cy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//rotate
22
move
33
rotate
4-
color red
4+
color cyan
55
box
66
move
77
rotate
8+
box

bin/data/code/2.cy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
scale 2
2+
rotate 1,1,0,TIME
3+
shape
4+
vert 0,0
5+
for i: 0 to TWO_PI step 0.1
6+
vert sin(i),cos(i)
7+
end
8+
vert 0,1
9+
end

src/Cyril/Ops/CyrilImgOp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void CyrilImgOp::eval(CyrilState &_s) {
3939
i = _s.stk->top(); _s.stk->pop();
4040
ofScale(0.01, 0.01, 0.01);
4141
if (_s.img->count(i)) {
42+
//cout << "Draw image " << _s.img->at(i) << endl;
4243
_s.img->at(i)->draw(0, 0, 0);
4344
}
4445
// TODO: recurse up the parent tree

src/cyrilApp.cpp

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ void cyrilApp::setup(){
99

1010
// Switch back to external data folder
1111
ofSetDataPathRoot("../../../data/");
12-
// Directory watcher for data folder
13-
codeWatcher.registerAllEvents(this);
14-
std::string folderToWatch = ofToDataPath("code", true);
15-
codeWatcher.addPath(folderToWatch, true, &fileFilter);
1612

1713
ofBackground(0);
1814
pauseProg = false;
@@ -75,7 +71,15 @@ void cyrilApp::setup(){
7571
_state.parent = NULL;
7672
_state.light = new ofLight();
7773
//_state.light = NULL;
78-
74+
75+
76+
// Directory watcher for data folder
77+
codeWatcher.registerAllEvents(this);
78+
spriteWatcher.registerAllEvents(this);
79+
codeWatcher.addPath(ofToDataPath("code", true), true, &fileFilter);
80+
spriteWatcher.addPath(ofToDataPath("sprites", true), true, &fileFilter);
81+
82+
7983
(*_state.sym)[REG_X_MAX] = 640;
8084
(*_state.sym)[REG_Y_MAX] = 480;
8185
(*_state.sym)[REG_X_MID] = (*_state.sym)[REG_X_MAX] / 2.0;
@@ -274,13 +278,13 @@ void cyrilApp::toggleLights(void * _o) {
274278
((cyrilApp *)_o)->_state.light->setAttenuation(1.f,0.f,0.f);
275279
}
276280
void cyrilApp::loadFile(void * _o) {
277-
//int whichEditor = ((cyrilApp *)_o)->editor.currentBuffer;
278-
//((cyrilApp *)_o)->editor.loadFile(ofToString(whichEditor)+".txt", whichEditor);
279-
//((cyrilApp *)_o)->editor.update();
281+
int whichEditor = ((cyrilApp *)_o)->editor.currentBuffer;
282+
((cyrilApp *)_o)->editor.loadFile("code/" + ofToString(whichEditor)+".cy", whichEditor);
283+
((cyrilApp *)_o)->editor.update();
280284
}
281285
void cyrilApp::saveFile(void * _o) {
282-
//int whichEditor = ((cyrilApp *)_o)->editor.currentBuffer;
283-
//((cyrilApp *)_o)->editor.saveFile(ofToString(whichEditor)+".txt", whichEditor);
286+
int whichEditor = ((cyrilApp *)_o)->editor.currentBuffer;
287+
((cyrilApp *)_o)->editor.saveFile("code/" + ofToString(whichEditor)+".cy", whichEditor);
284288
}
285289
void cyrilApp::resetTimers(void * _o) {
286290
((cyrilApp *)_o)->doResetTimers = true;
@@ -312,28 +316,41 @@ void cyrilApp::runScript(void * _o) {
312316
((cyrilApp *)_o)->reportError = true;
313317
}
314318

319+
std::string removeExtension(const std::string filename) {
320+
size_t lastdot = filename.find_last_of(".");
321+
if (lastdot == std::string::npos) return filename;
322+
return filename.substr(0, lastdot);
323+
}
315324

316-
void cyrilApp::onDirectoryWatcherItemAdded(const DirectoryWatcherManager::DirectoryEvent& evt) {
317-
ofFile file = ofFile(evt.item.path());
325+
void cyrilApp::reloadFileBuffer(std::string filePath) {
326+
//cout << "File = " << filePath << endl;
327+
ofFile file = ofFile(filePath);
318328
if (file.getExtension() == "cy") {
319-
cout << "Load: " << file.getFileName() << endl;
320-
int whichEditor = editor.currentBuffer;
321-
editor.loadFile(evt.item.path(), whichEditor);
322-
editor.update();
329+
int whichEditor = ofToInt(removeExtension(file.getFileName()));
330+
if (whichEditor >= 0 && whichEditor <= 9) {
331+
editor.loadFile(filePath, whichEditor);
332+
//editor.update();
333+
if (running[whichEditor]) {
334+
editor.currentBuffer = whichEditor;
335+
runScript(this);
336+
}
337+
}
338+
}
339+
if (file.getExtension() == "png") {
340+
//cout << "Loading image " << file.getFileName() << endl;
341+
int whichImg = ofToInt(removeExtension(file.getFileName()));
342+
(*_state.img)[whichImg] = new ofImage(filePath);
323343
}
324344
}
345+
346+
void cyrilApp::onDirectoryWatcherItemAdded(const DirectoryWatcherManager::DirectoryEvent& evt) {
347+
reloadFileBuffer(evt.item.path());
348+
}
325349
void cyrilApp::onDirectoryWatcherItemRemoved(const DirectoryWatcherManager::DirectoryEvent& evt) {
326-
cout << "Unload: " << evt.item.path() << endl;
350+
//cout << "Unload: " << evt.item.path() << endl;
327351
}
328352
void cyrilApp::onDirectoryWatcherItemModified(const DirectoryWatcherManager::DirectoryEvent& evt) {
329-
ofFile file = ofFile(evt.item.path());
330-
if (file.getExtension() == "cy") {
331-
cout << "Reload: " << evt.item.path() << endl;
332-
int whichEditor = editor.currentBuffer;
333-
editor.loadFile(evt.item.path(), whichEditor);
334-
//editor.update();
335-
runScript(this);
336-
}
353+
reloadFileBuffer(evt.item.path());
337354
}
338355
void cyrilApp::onDirectoryWatcherItemMovedFrom(const DirectoryWatcherManager::DirectoryEvent& evt) {
339356

src/cyrilApp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class cyrilApp : public ofBaseApp{
4545
int lastSignalReport;
4646

4747
DirectoryWatcherManager codeWatcher;
48+
DirectoryWatcherManager spriteWatcher;
4849
HiddenFileFilter fileFilter;
4950

5051
public:
@@ -70,6 +71,8 @@ class cyrilApp : public ofBaseApp{
7071

7172
void audioReceived(float*, int, int);
7273

74+
void reloadFileBuffer(std::string);
75+
7376
// Editor command callbacks
7477
static void toggleFullscreen(void *);
7578
static void toggleEditor(void *);

0 commit comments

Comments
 (0)