ScriptedObject::ScriptedObject(const ReaderMapping& lisp) : MovingSprite(lisp, "images/objects/bonus_block/brick.sprite", LAYER_OBJECTS, COLGROUP_MOVING_STATIC), ExposedObject<ScriptedObject, scripting::ScriptedObject>(this), physic(), solid(), physic_enabled(), visible(), new_vel_set(false), new_vel(), new_size() { if (!lisp.get("name", name)) name = ""; if(name.empty()) { name = "unnamed" + std::to_string(graphicsRandom.rand()); log_warning << "Scripted object must have a name specified, setting to: " << name << std::endl; } if (!lisp.get("solid", solid)) solid = true; if (!lisp.get("physic-enabled", physic_enabled)) physic_enabled = true; if (!lisp.get("visible", visible)) visible = true; layer = reader_get_layer (lisp, /* default = */ LAYER_OBJECTS); if( solid ) { set_group( COLGROUP_MOVING_STATIC ); } else { set_group( COLGROUP_DISABLED ); } }
Thunderstorm::Thunderstorm(const ReaderMapping& reader) : ExposedObject<Thunderstorm, scripting::Thunderstorm>(this), running(true), interval(10.0f), layer(LAYER_BACKGROUNDTILES-1), time_to_thunder(), time_to_lightning(), flash_display_timer() { reader.get("name", name); reader.get("running", running); reader.get("interval", interval); if(interval <= 0) { log_warning << "Running a thunderstorm with non-positive time interval is a bad idea" << std::endl; } layer = reader_get_layer (reader, /* default = */ LAYER_BACKGROUNDTILES-1); SoundManager::current()->preload("sounds/thunder.wav"); SoundManager::current()->preload("sounds/lightning.wav"); if (running) { running = false; // else start() is ignored start(); } }
Gradient::Gradient(const ReaderMapping& reader) : layer(LAYER_BACKGROUND0), gradient_top(), gradient_bottom(), gradient_direction(), gradient_region(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) { layer = reader_get_layer (reader, /* default = */ LAYER_BACKGROUND0); std::vector<float> bkgd_top_color, bkgd_bottom_color; std::string direction; if (!reader.get("name", name)) name = ""; if(reader.get("direction", direction)) { if(direction == "horizontal") { gradient_direction = HORIZONTAL; } else if(direction == "horizontal_sector") { gradient_direction = HORIZONTAL_SECTOR; } else if(direction == "vertical_sector") { gradient_direction = VERTICAL_SECTOR; } else { gradient_direction = VERTICAL; } } else { gradient_direction = VERTICAL; } if(gradient_direction == HORIZONTAL || gradient_direction == HORIZONTAL_SECTOR) { if(!reader.get("left_color", bkgd_top_color) || !reader.get("right_color", bkgd_bottom_color)) { log_warning << "Horizontal gradients should use left_color and right_color, respectively. Trying to parse top and bottom color instead" << std::endl; } else { gradient_top = Color(bkgd_top_color); gradient_bottom = Color(bkgd_bottom_color); return; } } if(!reader.get("top_color", bkgd_top_color) || !reader.get("bottom_color", bkgd_bottom_color)) throw std::runtime_error("Must specify top_color and bottom_color in gradient"); gradient_top = Color(bkgd_top_color); gradient_bottom = Color(bkgd_bottom_color); }
Decal::Decal(const ReaderMapping& reader) : MovingSprite(reader, LAYER_OBJECTS, COLGROUP_DISABLED) { layer = reader_get_layer (reader, /* default = */ LAYER_OBJECTS); bool solid = false; reader.get("solid", solid); if(solid) set_group(COLGROUP_STATIC); std::string action; if(reader.get("action", action)) set_action(action, -1); }
Decal::Decal(const ReaderMapping& reader) : MovingSprite(reader, "images/decal/explanations/billboard-fireflower.png", LAYER_OBJECTS, COLGROUP_DISABLED), default_action(), solid() { layer = reader_get_layer (reader, /* default = */ LAYER_OBJECTS); if (!reader.get("solid", solid)) solid = false; if(solid) set_group(COLGROUP_STATIC); if(reader.get("action", default_action)) set_action(default_action, -1); }
Gradient::Gradient(const Reader& reader) : layer(LAYER_BACKGROUND0), gradient_top(), gradient_bottom() { layer = reader_get_layer (reader, /* default = */ LAYER_BACKGROUND0); std::vector<float> bkgd_top_color, bkgd_bottom_color; if(!reader.get("top_color", bkgd_top_color) || !reader.get("bottom_color", bkgd_bottom_color)) throw std::runtime_error("Must specify top_color and bottom_color in gradient"); gradient_top = Color(bkgd_top_color); gradient_bottom = Color(bkgd_bottom_color); }
Gradient::Gradient(const Reader& reader) : layer(LAYER_BACKGROUND0), gradient_top(), gradient_bottom() { layer = reader_get_layer (reader, /* default = */ LAYER_BACKGROUND0); std::vector<float> bkgd_top_color, bkgd_bottom_color; std::string direction; if(reader.get("direction", direction) && direction == "horizontal") { gradient_direction = HORIZONTAL; } else { gradient_direction = VERTICAL; } if(gradient_direction == HORIZONTAL) { if(!reader.get("left_color", bkgd_top_color) || !reader.get("right_color", bkgd_bottom_color)) { log_warning << "Horizontal gradients should use left_color and right_color, respectively. Trying to parse top and bottom color instead" << std::endl; } else { gradient_top = Color(bkgd_top_color); gradient_bottom = Color(bkgd_bottom_color); return; } } if(!reader.get("top_color", bkgd_top_color) || !reader.get("bottom_color", bkgd_bottom_color)) throw std::runtime_error("Must specify top_color and bottom_color in gradient"); gradient_top = Color(bkgd_top_color); gradient_bottom = Color(bkgd_bottom_color); }
ScriptedObject::ScriptedObject(const Reader& lisp) : MovingSprite(lisp, LAYER_OBJECTS, COLGROUP_MOVING_STATIC), physic(), name(), solid(true), physic_enabled(true), visible(true), new_vel_set(false), new_vel() { lisp.get("name", name); if(name == "") throw std::runtime_error("Scripted object must have a name specified"); lisp.get("solid", solid); lisp.get("physic-enabled", physic_enabled); lisp.get("visible", visible); layer = reader_get_layer (lisp, /* default = */ LAYER_OBJECTS); if( solid ){ set_group( COLGROUP_MOVING_STATIC ); } else { set_group( COLGROUP_DISABLED ); } }
void SnowParticleSystem::parse(const Reader& reader) { z_pos = reader_get_layer (reader, /* default = */ LAYER_BACKGROUND1); }
TileMap::TileMap(const Reader& reader) : editor_active(true), tileset(), tiles(), real_solid(false), effective_solid(false), speed_x(1), speed_y(1), width(-1), height(-1), z_pos(0), offset(Vector(0,0)), movement(Vector(0,0)), drawing_effect(NO_EFFECT), alpha(1.0), current_alpha(1.0), remaining_fade_time(0), path(), walker(), draw_target(DrawingContext::NORMAL) { tileset = current_tileset; assert(tileset != NULL); reader.get("name", name); reader.get("solid", real_solid); reader.get("speed", speed_x); reader.get("speed-y", speed_y); z_pos = reader_get_layer (reader, /* default = */ 0); if(real_solid && ((speed_x != 1) || (speed_y != 1))) { log_warning << "Speed of solid tilemap is not 1. fixing" << std::endl; speed_x = 1; speed_y = 1; } const lisp::Lisp* pathLisp = reader.get_lisp("path"); if (pathLisp) { path.reset(new Path()); path->read(*pathLisp); walker.reset(new PathWalker(path.get(), /*running*/false)); Vector v = path->get_base(); set_offset(v); } std::string draw_target_s = "normal"; reader.get("draw-target", draw_target_s); if (draw_target_s == "normal") draw_target = DrawingContext::NORMAL; if (draw_target_s == "lightmap") draw_target = DrawingContext::LIGHTMAP; if (reader.get("alpha", alpha)) { current_alpha = alpha; } /* Initialize effective_solid based on real_solid and current_alpha. */ effective_solid = real_solid; update_effective_solid (); reader.get("width", width); reader.get("height", height); if(width < 0 || height < 0) throw std::runtime_error("Invalid/No width/height specified in tilemap."); if(!reader.get("tiles", tiles)) throw std::runtime_error("No tiles in tilemap."); if(int(tiles.size()) != width*height) { throw std::runtime_error("wrong number of tiles in tilemap."); } bool empty = true; // make sure all tiles used on the tilemap are loaded and tilemap isn't empty for(Tiles::iterator i = tiles.begin(); i != tiles.end(); ++i) { if(*i != 0) { empty = false; } tileset->get(*i); } if(empty) { log_info << "Tilemap '" << name << "', z-pos '" << z_pos << "' is empty." << std::endl; } }
void CometParticleSystem::parse(const ReaderMapping& reader) { z_pos = reader_get_layer (reader, /* default = */ LAYER_BACKGROUND1); }
Background::Background(const Reader& reader) : alignment(NO_ALIGNMENT), layer(LAYER_BACKGROUND0), imagefile_top(), imagefile(), imagefile_bottom(), pos(), speed(), speed_y(), scroll_speed(), scroll_offset(), image_top(), image(), image_bottom() { // read position, defaults to (0,0) float px = 0; float py = 0; reader.get("x", px); reader.get("y", py); this->pos = Vector(px,py); speed = 1.0; speed_y = 1.0; std::string alignment_str; if (reader.get("alignment", alignment_str)) { if (alignment_str == "left") { alignment = LEFT_ALIGNMENT; } else if (alignment_str == "right") { alignment = RIGHT_ALIGNMENT; } else if (alignment_str == "top") { alignment = TOP_ALIGNMENT; } else if (alignment_str == "bottom") { alignment = BOTTOM_ALIGNMENT; } else if (alignment_str == "none") { alignment = NO_ALIGNMENT; } else { log_warning << "Background: invalid alignment: '" << alignment_str << "'" << std::endl; alignment = NO_ALIGNMENT; } } reader.get("scroll-offset-x", scroll_offset.x); reader.get("scroll-offset-y", scroll_offset.y); reader.get("scroll-speed-x", scroll_speed.x); reader.get("scroll-speed-y", scroll_speed.y); layer = reader_get_layer (reader, /* default = */ LAYER_BACKGROUND0); if(!reader.get("image", imagefile) || !reader.get("speed", speed)) throw std::runtime_error("Must specify image and speed for background"); set_image(imagefile, speed); if (!reader.get("speed-y", speed_y)) { speed_y = speed; } if (reader.get("image-top", imagefile_top)) { image_top = Surface::create(imagefile_top); } if (reader.get("image-bottom", imagefile_bottom)) { image_bottom = Surface::create(imagefile_bottom); } }
Background::Background(const ReaderMapping& reader) : ExposedObject<Background, scripting::Background>(this), alignment(NO_ALIGNMENT), layer(LAYER_BACKGROUND0), imagefile_top(), imagefile(), imagefile_bottom(), pos(), speed(), speed_y(), scroll_speed(), scroll_offset(), image_top(), image(), image_bottom(), has_pos_x(false), has_pos_y(false) { // read position, defaults to (0,0) float px = 0; float py = 0; has_pos_x = reader.get("x", px); has_pos_y = reader.get("y", py); this->pos = Vector(px,py); reader.get("name", name, ""); speed = 1.0; speed_y = 1.0; std::string alignment_str; if (reader.get("alignment", alignment_str)) { if (alignment_str == "left") { alignment = LEFT_ALIGNMENT; } else if (alignment_str == "right") { alignment = RIGHT_ALIGNMENT; } else if (alignment_str == "top") { alignment = TOP_ALIGNMENT; } else if (alignment_str == "bottom") { alignment = BOTTOM_ALIGNMENT; } else if (alignment_str == "none") { alignment = NO_ALIGNMENT; } else { log_warning << "Background: invalid alignment: '" << alignment_str << "'" << std::endl; alignment = NO_ALIGNMENT; } } reader.get("scroll-offset-x", scroll_offset.x, 0); reader.get("scroll-offset-y", scroll_offset.y, 0); reader.get("scroll-speed-x", scroll_speed.x, 0.5); reader.get("scroll-speed-y", scroll_speed.y, 0.5); layer = reader_get_layer (reader, /* default = */ LAYER_BACKGROUND0); reader.get("image", imagefile, "images/background/transparent_up.png"); reader.get("speed", speed, 0.5); set_image(imagefile, speed); reader.get("speed-y", speed_y, speed); if (reader.get("image-top", imagefile_top)) { image_top = Surface::create(imagefile_top); } else { imagefile_top = imagefile; } if (reader.get("image-bottom", imagefile_bottom)) { image_bottom = Surface::create(imagefile_bottom); } else { imagefile_bottom = imagefile; } }
void ParticleSystem::parse(const ReaderMapping& reader) { reader.get("name", m_name, ""); reader.get("enabled", enabled, true); z_pos = reader_get_layer (reader, /* default = */ LAYER_BACKGROUND1); }
TileMap::TileMap(const TileSet *tileset_, const ReaderMapping& reader) : GameObject(reader), ExposedObject<TileMap, scripting::TileMap>(this), PathObject(), m_editor_active(true), m_tileset(tileset_), m_tiles(), m_real_solid(false), m_effective_solid(false), m_speed_x(1), m_speed_y(1), m_width(-1), m_height(-1), m_z_pos(0), m_offset(Vector(0,0)), m_movement(Vector(0,0)), m_flip(NO_FLIP), m_alpha(1.0), m_current_alpha(1.0), m_remaining_fade_time(0), m_tint(1, 1, 1), m_current_tint(1, 1, 1), m_remaining_tint_fade_time(0), m_running(false), m_draw_target(DrawingTarget::COLORMAP), m_new_size_x(0), m_new_size_y(0), m_new_offset_x(0), m_new_offset_y(0), m_add_path(false) { assert(m_tileset); reader.get("solid", m_real_solid); bool backward_compatibility_fudge = false; if (!reader.get("speed-x", m_speed_x)) { if (reader.get("speed", m_speed_x)) { backward_compatibility_fudge = true; } } if (!reader.get("speed-y", m_speed_y)) { if (backward_compatibility_fudge) { m_speed_y = m_speed_x; } } m_z_pos = reader_get_layer(reader, 0); if (!Editor::is_active()) { if (m_real_solid && ((m_speed_x != 1) || (m_speed_y != 1))) { log_warning << "Speed of solid tilemap is not 1. fixing" << std::endl; m_speed_x = 1; m_speed_y = 1; } } init_path(reader, false); std::string draw_target_s = "normal"; reader.get("draw-target", draw_target_s); if (draw_target_s == "normal") m_draw_target = DrawingTarget::COLORMAP; if (draw_target_s == "lightmap") m_draw_target = DrawingTarget::LIGHTMAP; if (reader.get("alpha", m_alpha)) { m_current_alpha = m_alpha; } std::vector<float> vColor; if (reader.get("tint", vColor)) { m_current_tint = Color(vColor); m_tint = m_current_tint; } /* Initialize effective_solid based on real_solid and current_alpha. */ m_effective_solid = m_real_solid; update_effective_solid (); reader.get("width", m_width); reader.get("height", m_height); if (m_width < 0 || m_height < 0) { //throw std::runtime_error("Invalid/No width/height specified in tilemap."); m_width = 0; m_height = 0; m_tiles.clear(); resize(static_cast<int>(Sector::get().get_width() / 32.0f), static_cast<int>(Sector::get().get_height() / 32.0f)); m_editor_active = false; } else { if (!reader.get("tiles", m_tiles)) throw std::runtime_error("No tiles in tilemap."); if (int(m_tiles.size()) != m_width * m_height) { throw std::runtime_error("wrong number of tiles in tilemap."); } } bool empty = true; // make sure all tiles used on the tilemap are loaded and tilemap isn't empty for (const auto& tile : m_tiles) { if (tile != 0) { empty = false; } m_tileset->get(tile); } if (empty) { log_info << "Tilemap '" << get_name() << "', z-pos '" << m_z_pos << "' is empty." << std::endl; } }