From 85a02e771388b133940b45e29768e697a29c1a36 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Mon, 3 Oct 2005 00:09:17 +0000 Subject: [PATCH] moved some sprites to separate files SVN-Revision: 2801 --- data/images/creatures/dummyguy/dummyguy.sprite | 44 +++++++++++++ data/images/creatures/yeti/yeti.sprite | 11 ++++ data/images/powerups/potions/blue-potion.sprite | 6 ++ data/images/powerups/potions/red-potion.sprite | 6 ++ data/images/sprites.strf | 85 ------------------------- data/levels/test/bonusblock.stl | 13 +--- data/levels/test/enemy3.stl | 2 +- data/levels/test/intro.stl | 2 +- data/levels/test/raintest.stl | 2 +- data/levels/test/script.stl | 6 +- data/levels/test/wansti-level4.stl | 2 +- data/levels/test/yeti.stl | 6 +- src/badguy/yeti.cpp | 2 +- src/object/gameobjs.cpp | 1 + src/scripting/script_interpreter.cpp | 5 -- src/sprite/sprite_data.cpp | 10 ++- src/sprite/sprite_data.hpp | 60 ++++++++--------- src/sprite/sprite_manager.cpp | 37 +++++++++-- src/sprite/sprite_manager.hpp | 23 ++++--- src/worldmap.cpp | 2 +- 20 files changed, 161 insertions(+), 164 deletions(-) create mode 100644 data/images/creatures/dummyguy/dummyguy.sprite create mode 100644 data/images/creatures/yeti/yeti.sprite create mode 100644 data/images/powerups/potions/blue-potion.sprite create mode 100644 data/images/powerups/potions/red-potion.sprite diff --git a/data/images/creatures/dummyguy/dummyguy.sprite b/data/images/creatures/dummyguy/dummyguy.sprite new file mode 100644 index 000000000..ec4014735 --- /dev/null +++ b/data/images/creatures/dummyguy/dummyguy.sprite @@ -0,0 +1,44 @@ +(supertux-sprite + (action + (name "left") + (fps 6) + (x-offset 0) + (y-offset 40) + (images "walk-1.png" "walk-2.png") + ) + + (action + (name "right") + (fps 6) + (x-offset 0) + (y-offset 40) + (mirror-action "left") + ) + + (action + (name "stand") + (x-offset 0) + (y-offset 40) + (images "stand.png")) + + (action + (name "throw") + (fps 6) + (x-offset 0) + (y-offset 40) + (images "throw.png")) + + (action + (name "jump") + (x-offset 0) + (y-offset 40) + (images "jump.png")) + + (action + (name "dead") + (x-offset 0) + (y-offset 0) + (images "dead.png") + ) +) + diff --git a/data/images/creatures/yeti/yeti.sprite b/data/images/creatures/yeti/yeti.sprite new file mode 100644 index 000000000..5ed8094e2 --- /dev/null +++ b/data/images/creatures/yeti/yeti.sprite @@ -0,0 +1,11 @@ +(supertux-sprite + (action + (name "right") + (images "yeti_b.png") + ) + (action + (name "left") + (mirror-action "right") + ) +) + diff --git a/data/images/powerups/potions/blue-potion.sprite b/data/images/powerups/potions/blue-potion.sprite new file mode 100644 index 000000000..9c9d94f07 --- /dev/null +++ b/data/images/powerups/potions/blue-potion.sprite @@ -0,0 +1,6 @@ +(supertux-sprite + (action + (name "default") + (images "blue-potion.png") + ) +) diff --git a/data/images/powerups/potions/red-potion.sprite b/data/images/powerups/potions/red-potion.sprite new file mode 100644 index 000000000..2274dad57 --- /dev/null +++ b/data/images/powerups/potions/red-potion.sprite @@ -0,0 +1,6 @@ +(supertux-sprite + (action + (name "default") + (images "red-potion.png") + ) +) diff --git a/data/images/sprites.strf b/data/images/sprites.strf index 1e44e8dc0..d43a74272 100644 --- a/data/images/sprites.strf +++ b/data/images/sprites.strf @@ -1201,49 +1201,6 @@ (y-offset 32) (mirror-action "explosion-left"))) - ; Dummyguy - (sprite (name "dummyguy") - (action - (name "left") - (fps 6) - (x-offset 0) - (y-offset 40) - (images "creatures/dummyguy/walk-1.png" - "creatures/dummyguy/walk-2.png")) - - (action - (name "right") - (fps 6) - (x-offset 0) - (y-offset 40) - (mirror-action "left")) - - (action - (name "stand") - (x-offset 0) - (y-offset 40) - (images "creatures/dummyguy/stand.png")) - - (action - (name "throw") - (fps 6) - (x-offset 0) - (y-offset 40) - (images "creatures/dummyguy/throw.png")) - - (action - (name "jump") - (x-offset 0) - (y-offset 40) - (images "creatures/dummyguy/jump.png")) - - (action - (name "dead") - (x-offset 0) - (y-offset 0) - (images "creatures/dummyguy/dead.png"))) - - ; MrTree (sprite (name "mrtree") (action @@ -1653,33 +1610,6 @@ "objects/hatch/hatch-5.png")) ) - (sprite (name "yeti") - (action - (name "right") - (images "creatures/yeti/yeti_b.png") - ) - (action - (name "left") - (mirror-action "right") - ) - ) - - (sprite - (name "red-potion") - (action - (name "default") - (images "powerups/potions/red-potion.png") - ) - ) - - (sprite - (name "blue-potion") - (action - (name "default") - (images "powerups/potions/blue-potion.png") - ) - ) - (sprite (name "lightmap_light") (action @@ -1771,20 +1701,5 @@ (images "objects/keys/outline_gold.png") ) ) - (sprite - (name "leveldot") - (action - (name "default") - (x-offset 16) - (y-offset 16) - (images "worldmap/common/leveldot_red.png") - ) - (action - (name "solved") - (x-offset 16) - (y-offset 16) - (images "worldmap/common/leveldot_green.png") - ) - ) ) diff --git a/data/levels/test/bonusblock.stl b/data/levels/test/bonusblock.stl index fee19e0eb..33dcff606 100644 --- a/data/levels/test/bonusblock.stl +++ b/data/levels/test/bonusblock.stl @@ -145,13 +145,8 @@ (bonusblock (x 96) (y 800) (contents "custom") (powerup - (sprite "red-potion") + (sprite "images/powerups/potions/red-potion.sprite") (script " -function wait(time) { - set_wakeup_time(time); - suspend(); -} - DisplayEffect.set_black(true); wait(0.1); DisplayEffect.set_black(false); @@ -170,12 +165,8 @@ DisplayEffect.fade_in(1); (bonusblock (x 470) (y 96) (contents "custom") (powerup - (sprite "blue-potion") + (sprite "images/powerups/potions/blue-potion.sprite") (script " -function wait(time) { - set_wakeup_time(time); - suspend(); -} DisplayEffect.fade_out(1); wait(1); Level.flip_vertically(); diff --git a/data/levels/test/enemy3.stl b/data/levels/test/enemy3.stl index eecf9788f..66ea8238b 100644 --- a/data/levels/test/enemy3.stl +++ b/data/levels/test/enemy3.stl @@ -84,7 +84,7 @@ (powerup (x 980) (y 140) (sprite "egg")) (powerup (x 1020) (y 140) (sprite "1up")) (powerup (x 1400) (y 140) - (sprite "red-potion") + (sprite "images/powerups/potions/images/powerups/potions/red-potion.sprite.sprite") (contents "custom") (script "Level.flip_vertically();") ) diff --git a/data/levels/test/intro.stl b/data/levels/test/intro.stl index 5566b52fd..4a4f1f19c 100644 --- a/data/levels/test/intro.stl +++ b/data/levels/test/intro.stl @@ -106,7 +106,7 @@ (name "PENNY") (x 390) (y 510) - (sprite "dummyguy") + (sprite "images/creatures/dummyguy/dummyguy.sprite") ) (init-script "intro();") ) diff --git a/data/levels/test/raintest.stl b/data/levels/test/raintest.stl index 2d6b46cd4..97e7636d9 100644 --- a/data/levels/test/raintest.stl +++ b/data/levels/test/raintest.stl @@ -201,7 +201,7 @@ (bonusblock (x 160) (y 160) (contents "custom") (powerup - (sprite "red-potion") + (sprite "images/powerups/potions/images/powerups/potions/red-potion.sprite.sprite") (script " function wait(time) { set_wakeup_time(time); diff --git a/data/levels/test/script.stl b/data/levels/test/script.stl index 66719237f..0c79c343b 100644 --- a/data/levels/test/script.stl +++ b/data/levels/test/script.stl @@ -120,19 +120,19 @@ (name "TUX") (x 160) (y 448) - (sprite "yeti") + (sprite "images/creatues/yeti/yeti.sprite") ) (scriptedobject (name "PENNY") (x 390) (y 448) - (sprite "dummyguy") + (sprite "images/creatures/dummyguy/dummyguy.sprite") ) (scriptedobject (name "NOLOK") (x 420) (y 94) - (sprite "dummyguy") + (sprite "images/creatures/dummyguy/dummyguy.sprite") (visible #f) (physic-enabled #f) (solid #f) diff --git a/data/levels/test/wansti-level4.stl b/data/levels/test/wansti-level4.stl index 4b43abd39..5f0d95bfe 100644 --- a/data/levels/test/wansti-level4.stl +++ b/data/levels/test/wansti-level4.stl @@ -166,7 +166,7 @@ (bonusblock (x 160) (y 288) (contents "custom") (powerup - (sprite "red-potion") + (sprite "images/powerups/potions/images/powerups/potions/red-potion.sprite.sprite") (script " DisplayEffect.set_black(true); wait(0.1); diff --git a/data/levels/test/yeti.stl b/data/levels/test/yeti.stl index 24c2171b3..7b2121350 100644 --- a/data/levels/test/yeti.stl +++ b/data/levels/test/yeti.stl @@ -111,11 +111,9 @@ Sound.play(\"sounds/invincible.wav\"); Text.set_text(\"You made it!\"); Text.set_font(\"big\"); Text.fade_in(1.5); -set_wakeup_time(4); -suspend(); +wait(4); DisplayEffect.fade_out(1.5); -set_wakeup_time(1.5); -suspend(); +wait(1.5); Level.finish(); ") ) diff --git a/src/badguy/yeti.cpp b/src/badguy/yeti.cpp index 50aa8887e..8fb1a9578 100644 --- a/src/badguy/yeti.cpp +++ b/src/badguy/yeti.cpp @@ -43,7 +43,7 @@ Yeti::Yeti(const lisp::Lisp& reader) reader.get("x", start_position.x); reader.get("y", start_position.y); bbox.set_size(80, 120); - sprite = sprite_manager->create("yeti"); + sprite = sprite_manager->create("images/creatures/yeti/yeti.sprite"); sprite->set_action("right"); state = INIT; side = LEFT; diff --git a/src/object/gameobjs.cpp b/src/object/gameobjs.cpp index 777db2c92..75c109621 100644 --- a/src/object/gameobjs.cpp +++ b/src/object/gameobjs.cpp @@ -29,6 +29,7 @@ #include "game_session.hpp" #include "gameobjs.hpp" #include "sprite/sprite_manager.hpp" +#include "sprite/sprite.hpp" #include "resources.hpp" #include "sector.hpp" #include "tilemap.hpp" diff --git a/src/scripting/script_interpreter.cpp b/src/scripting/script_interpreter.cpp index af17653c8..1047ed7f7 100644 --- a/src/scripting/script_interpreter.cpp +++ b/src/scripting/script_interpreter.cpp @@ -123,8 +123,6 @@ void ScriptInterpreter::run_script(std::istream& in, const std::string& sourcename, bool remove_when_terminated) { - printf("Stackbefore:\n"); - print_squirrel_stack(v); if(sq_compile(v, squirrel_read_char, &in, sourcename.c_str(), true) < 0) throw Scripting::SquirrelError(v, "Couldn't parse script"); @@ -137,12 +135,9 @@ ScriptInterpreter::run_script(std::istream& in, const std::string& sourcename, if(remove_when_terminated) { remove_me(); } - printf("ended.\n"); // remove closure from stack sq_pop(v, 1); } - printf("After:\n"); - print_squirrel_stack(v); } void diff --git a/src/sprite/sprite_data.cpp b/src/sprite/sprite_data.cpp index a4597e5cf..58d22cf1b 100644 --- a/src/sprite/sprite_data.cpp +++ b/src/sprite/sprite_data.cpp @@ -43,20 +43,18 @@ SpriteData::Action::~Action() delete *i; } -SpriteData::SpriteData(const lisp::Lisp* lisp) +SpriteData::SpriteData(const lisp::Lisp* lisp, const std::string& basedir) { lisp::ListIterator iter(lisp); while(iter.next()) { if(iter.item() == "name") { iter.value()->get(name); } else if(iter.item() == "action") { - parse_action(iter.lisp()); + parse_action(iter.lisp(), basedir); } else { std::cerr << "Unknown sprite field: " << iter.item() << "\n"; } } - if(name.empty()) - throw std::runtime_error("Error: Sprite wihtout name."); if(actions.empty()) throw std::runtime_error("Error: Sprite wihtout actions."); } @@ -68,7 +66,7 @@ SpriteData::~SpriteData() } void -SpriteData::parse_action(const lisp::Lisp* lisp) +SpriteData::parse_action(const lisp::Lisp* lisp, const std::string& basedir) { Action* action = new Action; @@ -108,7 +106,7 @@ SpriteData::parse_action(const lisp::Lisp* lisp) } for(std::vector::size_type i = 0; i < images.size(); i++) { - action->surfaces.push_back(new Surface("images/" + images[i], true)); + action->surfaces.push_back(new Surface(basedir + images[i], true)); } } actions[action->name] = action; diff --git a/src/sprite/sprite_data.hpp b/src/sprite/sprite_data.hpp index 3850141dd..9b9033846 100644 --- a/src/sprite/sprite_data.hpp +++ b/src/sprite/sprite_data.hpp @@ -30,46 +30,46 @@ class SpriteData { public: - /** cur has to be a pointer to data in the form of ((x-offset 5) - (y-offset 10) ...) */ - SpriteData(const lisp::Lisp* cur); - ~SpriteData(); + /** cur has to be a pointer to data in the form of ((x-offset 5) + (y-offset 10) ...) */ + SpriteData(const lisp::Lisp* cur, const std::string& basedir); + ~SpriteData(); - const std::string& get_name() const - { - return name; - } + const std::string& get_name() const + { + return name; + } private: - friend class Sprite; + friend class Sprite; - struct Action - { - Action(); - ~Action(); - - std::string name; + struct Action + { + Action(); + ~Action(); - /** Position correction */ - int x_offset; - int y_offset; - /** Drawing priority in queue */ - int z_order; + std::string name; - /** Frames per second */ - float fps; + /** Position correction */ + int x_offset; + int y_offset; + /** Drawing priority in queue */ + int z_order; - std::vector surfaces; - }; + /** Frames per second */ + float fps; - typedef std::map Actions; - Actions actions; + std::vector surfaces; + }; - void parse_action(const lisp::Lisp* lispreader); - /** Get an action */ - Action* get_action(std::string act); + typedef std::map Actions; + Actions actions; - std::string name; + void parse_action(const lisp::Lisp* lispreader, const std::string& basedir); + /** Get an action */ + Action* get_action(std::string act); + + std::string name; }; #endif diff --git a/src/sprite/sprite_manager.cpp b/src/sprite/sprite_manager.cpp index 212c64ce1..aea403c1b 100644 --- a/src/sprite/sprite_manager.cpp +++ b/src/sprite/sprite_manager.cpp @@ -28,6 +28,7 @@ #include "lisp/lisp.hpp" #include "lisp/parser.hpp" #include "lisp/list_iterator.hpp" +#include "file_system.hpp" SpriteManager::SpriteManager(const std::string& filename) { @@ -55,7 +56,7 @@ SpriteManager::load_resfile(const std::string& filename) lisp::ListIterator iter(resources); while(iter.next()) { if(iter.item() == "sprite") { - SpriteData* spritedata = new SpriteData(iter.lisp()); + SpriteData* spritedata = new SpriteData(iter.lisp(), "images/"); Sprites::iterator i = sprites.find(spritedata->get_name()); if (i == sprites.end()) { @@ -82,11 +83,39 @@ Sprite* SpriteManager::create(const std::string& name) { Sprites::iterator i = sprites.find(name); + SpriteData* data; if(i == sprites.end()) { - std::stringstream msg; - msg << "Sprite '" << name << "' not found."; + // try loading the spritefile + data = load(name); + if(data == NULL) { + std::stringstream msg; + msg << "Sprite '" << name << "' not found."; + throw std::runtime_error(msg.str()); + } + } else { + data = i->second; + } + + return new Sprite(*data); +} + +SpriteData* +SpriteManager::load(const std::string& filename) +{ + lisp::Parser parser; + std::auto_ptr root (parser.parse(filename)); + + const lisp::Lisp* sprite = root->get_lisp("supertux-sprite"); + if(!sprite) { + std::ostringstream msg; + msg << "'" << filename << "' is not a supertux-sprite file"; throw std::runtime_error(msg.str()); } - return new Sprite(*i->second); + + std::auto_ptr data ( + new SpriteData(sprite, FileSystem::dirname(filename)) ); + sprites[filename] = data.release(); + + return sprites[filename]; } diff --git a/src/sprite/sprite_manager.hpp b/src/sprite/sprite_manager.hpp index dcdcbf936..01ec93099 100644 --- a/src/sprite/sprite_manager.hpp +++ b/src/sprite/sprite_manager.hpp @@ -22,22 +22,25 @@ #include -#include "sprite.hpp" +class SpriteData; +class Sprite; class SpriteManager { private: - typedef std::map Sprites; - Sprites sprites; + typedef std::map Sprites; + Sprites sprites; + public: - SpriteManager(const std::string& filename); - ~SpriteManager(); + SpriteManager(const std::string& filename); + ~SpriteManager(); - void load_resfile(const std::string& filename); - /** loads a sprite. - * (contrary to the old api you have to delete the sprite!) - */ - Sprite* create(const std::string& name); + void load_resfile(const std::string& filename); + /** loads a sprite. */ + Sprite* create(const std::string& filename); + +private: + SpriteData* load(const std::string& filename); }; #endif diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 37ef7598d..45cc1bdb0 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -516,7 +516,7 @@ WorldMap::parse_level_tile(const lisp::Lisp* level_lisp) level.south = true; level.west = true; - std::string sprite = "leveldot"; + std::string sprite = "images/worldmap/common/leveldot.sprite"; level_lisp->get("sprite", sprite); level.sprite = sprite_manager->create(sprite); -- 2.11.0