#include "game_data.h" #include #include #include namespace { LingoColor GetColorForString(const std::string &str) { if (str == "black") { return LingoColor::kBlack; } else if (str == "red") { return LingoColor::kRed; } else if (str == "blue") { return LingoColor::kBlue; } else if (str == "yellow") { return LingoColor::kYellow; } else if (str == "orange") { return LingoColor::kOrange; } else if (str == "green") { return LingoColor::kGreen; } else if (str == "gray") { return LingoColor::kGray; } else if (str == "brown") { return LingoColor::kBrown; } else if (str == "purple") { return LingoColor::kPurple; } else { std::cout << "Invalid color: " << str << std::endl; return LingoColor::kNone; } } struct GameData { std::vector rooms_; std::vector doors_; std::vector panels_; std::vector map_areas_; std::map room_by_id_; std::map door_by_id_; std::map panel_by_id_; std::map area_by_id_; std::map room_by_painting_; std::vector achievement_panels_; GameData() { YAML::Node lingo_config = YAML::LoadFile("assets/LL1.yaml"); YAML::Node areas_config = YAML::LoadFile("assets/areas.yaml"); YAML::Node pilgrimage_config = YAML::LoadFile("assets/pilgrimage.yaml"); rooms_.reserve(lingo_config.size() * 2); for (const auto &room_it : lingo_config) { int room_id = AddOrGetRoom(room_it.first.as()); Room &room_obj = rooms_[room_id]; for (const auto &entrance_it : room_it.second["entrances"]) { int from_room_id = AddOrGetRoom(entrance_it.first.as()); Room &from_room_obj = rooms_[from_room_id]; switch (entrance_it.second.Type()) { case YAML::NodeType::Scalar: { // This is just "true". from_room_obj.exits.push_back({.destination_room = room_id}); break; } case YAML::NodeType::Map: { Exit exit_obj; exit_obj.destination_room = room_id; if (entrance_it.second["door"]) { std::string door_room = room_obj.name; if (entrance_it.second["room"]) { door_room = entrance_it.second["room"].as(); } exit_obj.door = AddOrGetDoor( door_room, entrance_it.second["door"].as()); } if (entrance_it.second["painting"]) { exit_obj.painting = entrance_it.second["painting"].as(); } from_room_obj.exits.push_back(exit_obj); break; } case YAML::NodeType::Sequence: { for (const auto &option : entrance_it.second) { Exit exit_obj; exit_obj.destination_room = room_id; std::string door_room = room_obj.name; if (option["room"]) { door_room = option["room"].as(); } exit_obj.door = AddOrGetDoor(door_room, option["door"].as()); if (option["painting"]) { exit_obj.painting = option["painting"].as(); } from_room_obj.exits.push_back(exit_obj); } break; } default: { // This shouldn't happen. std::cout << "Error reading game data: " << entrance_it << std::endl; break; } } } if (room_it.second["panels"]) { for (const auto &panel_it : room_it.second["panels"]) { int panel_id = AddOrGetPanel(room_obj.name, panel_it.first.as()); Panel &panel_obj = panels_[panel_id]; if (panel_it.second["colors"]) { if (panel_it.second["colors"].IsScalar()) { panel_obj.colors.push_back(GetColorForString( panel_it.second["colors"].as())); } else { for (const auto &color_node : panel_it.second["colors"]) { panel_obj.colors.push_back( GetColorForString(color_node.as())); } } } if (panel_it.second["required_room"]) { if (panel_it.second["required_room"].IsScalar()) { panel_obj.required_rooms.push_back(AddOrGetRoom( panel_it.second["required_room"].as())); } else { for (const auto &rr_node : panel_it.second["required_room"]) { panel_obj.required_rooms.push_back( AddOrGetRoom(rr_node.as())); } } } if (panel_it.second["required_door"]) { if (panel_it.second["required_door"].IsMap()) { std::string rd_room = room_obj.name; if (panel_it.second["required_door"]["room"]) { rd_room = panel_it.second["required_door"]["room"].as(); } panel_obj.required_doors.push_back(AddOrGetDoor( rd_room, panel_it.second["required_door"]["door"].as())); } else { for (const auto &rr_node : panel_it.second["required_door"]) { std::string rd_room = room_obj.name; if (rr_node["room"]) { rd_room = rr_node["room"].as(); } panel_obj.required_doors.push_back( AddOrGetDoor(rd_room, rr_node["door"].as())); } } } if (panel_it.second["check"]) { panel_obj.check = panel_it.second["check"].as(); } if (panel_it.second["achievement"]) { panel_obj.achievement = true; panel_obj.achievement_name = panel_it.second["achievement"].as(); achievement_panels_.push_back(panel_id); } if (panel_it.second["exclude_reduce"]) { panel_obj.exclude_reduce = panel_it.second["exclude_reduce"].as(); } } } if (room_it.second["doors"]) { for (const auto &door_it : room_it.second["doors"]) { int door_id = AddOrGetDoor(room_obj.name, door_it.first.as()); Door &door_obj = doors_[door_id]; bool has_external_panels = false; std::vector panel_names; for (const auto &panel_node : door_it.second["panels"]) { if (panel_node.IsScalar()) { panel_names.push_back(panel_node.as()); door_obj.panels.push_back( AddOrGetPanel(room_obj.name, panel_node.as())); } else { has_external_panels = true; panel_names.push_back(panel_node["panel"].as()); door_obj.panels.push_back( AddOrGetPanel(panel_node["room"].as(), panel_node["panel"].as())); } } if (door_it.second["skip_location"]) { door_obj.skip_location = door_it.second["skip_location"].as(); } if (door_it.second["skip_item"]) { door_obj.skip_item = door_it.second["skip_item"].as(); } if (door_it.second["event"]) { door_obj.skip_location = door_it.second["event"].as(); door_obj.skip_item = door_it.second["event"].as(); } if (door_it.second["item_name"]) { door_obj.item_name = door_it.second["item_name"].as(); } else if (!door_it.second["skip_item"] && !door_it.second["event"]) {
/*
 * cocos2d for iPhone: http://www.cocos2d-iphone.org
 *
 * Copyright (C) 2009 Matt Oswald
 *
 * Copyright (c) 2009-2010 Ricardo Quesada
 * Copyright (c) 2011 Zynga Inc.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */


#import "CCNode.h"
#import "CCProtocols.h"
#import "CCTextureAtlas.h"
#import "ccMacros.h"

#pragma mark CCSpriteBatchNode

@class CCSprite;

/** CCSpriteBatchNode is like a batch node: if it contains children, it will draw them in 1 single OpenGL call
 * (often known as "batch draw").
 *
 * A CCSpriteBatchNode can reference one and only one texture (one image file, one texture atlas).
 * Only the CCSprites that are contained in that texture can be added to the CCSpriteBatchNode.
 * All CCSprites added to a CCSpriteBatchNode are drawn in one OpenGL ES draw call.
 * If the CCSprites are not added to a CCSpriteBatchNode then an OpenGL ES draw call will be needed for each one, which is less efficient.
 *
 *
 * Limitations:
 *  - The only object that is accepted as child (or grandchild, grand-grandchild, etc...) is CCSprite or any subclass of CCSprite. eg: particles, labels and layer can't be added to a CCSpriteBatchNode.
 *  - Either all its children are Aliased or Antialiased. It can't be a mix. This is because "alias" is a property of the texture, and all the sprites share the same texture.
 * 
 * @since v0.7.1
 */
@interface CCSpriteBatchNode : CCNode <CCTextureProtocol>
{
	CCTextureAtlas	*textureAtlas_;
	ccBlendFunc		blendFunc_;

	// all descendants: chlidren, gran children, etc...
	CCArray	*descendants_;
}

/** returns the TextureAtlas that is used */
@property (nonatomic,readwrite,retain) CCTextureAtlas * textureAtlas;

/** conforms to CCTextureProtocol protocol */
@property (nonatomic,readwrite) ccBlendFunc blendFunc;

/** descendants (children, gran children, etc) */
@property (nonatomic,readonly) CCArray *descendants;

/** creates a CCSpriteBatchNode with a texture2d and a default capacity of 29 children.
 The capacity will be increased in 33% in runtime if it run out of space.
 */
+(id)batchNodeWithTexture:(CCTexture2D *)tex;
+(id)spriteSheetWithTexture:(CCTexture2D *)tex DEPRECATED_ATTRIBUTE;

/** creates a CCSpriteBatchNode with a texture2d and capacity of children.
 The capacity will be increased in 33% in runtime if it run out of space.
 */
+(id)batchNodeWithTexture:(CCTexture2D *)tex capacity:(NSUInteger)capacity;
+(id)spriteSheetWithTexture:(CCTexture2D *)tex capacity:(NSUInteger)capacity DEPRECATED_ATTRIBUTE;

/** creates a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) with a default capacity of 29 children.
 The capacity will be increased in 33% in runtime if it run out of space.
 The file will be loaded using the TextureMgr.
 */
+(id)batchNodeWithFile:(NSString*) fileImage;
+(id)spriteSheetWithFile:(NSString*) fileImage DEPRECATED_ATTRIBUTE;

/** creates a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and capacity of children.
 The capacity will be increased in 33% in runtime if it run out of space.
 The file will be loaded using the TextureMgr.
*/
+(id)batchNodeWithFile:(NSString*)fileImage capacity:(NSUInteger)capacity;
+(id)spriteSheetWithFile:(NSString*)fileImage capacity:(NSUInteger)capacity DEPRECATED_ATTRIBUTE;

/** initializes a CCSpriteBatchNode with a texture2d and capacity of children.
 The capacity will be increased in 33% in runtime if it run out of space.
 */
-(id)initWithTexture:(CCTexture2D *)tex capacity:(NSUInteger)capacity;
/** initializes a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) and a capacity of children.
 The capacity will be increased in 33% in runtime if it run out of space.
 The file will be loaded using the TextureMgr.
 */
-(id)initWithFile:(NSString*)fileImage capacity:(NSUInteger)capacity;

-(void) increaseAtlasCapacity;

/** creates an sprite with a rect in the CCSpriteBatchNode.
 It's the same as:
   - create an standard CCSsprite
   - set the usingSpriteSheet = YES
   - set the textureAtlas to the same texture Atlas as the CCSpriteBatchNode
 @deprecated Use [CCSprite spriteWithBatchNode:rect:] instead;
 */
-(CCSprite*) createSpriteWithRect:(CGRect)rect DEPRECATED_ATTRIBUTE;

/** initializes a previously created sprite with a rect. This sprite will have the same texture as the CCSpriteBatchNode.
 It's the same as:
 - initialize an standard CCSsprite
 - set the usingBatchNode = YES
 - set the textureAtlas to the same texture Atlas as the CCSpriteBatchNode
 @since v0.99.0
 @deprecated Use [CCSprite initWithBatchNode:rect:] instead;
*/ 
-(void) initSprite:(CCSprite*)sprite rect:(CGRect)rect DEPRECATED_ATTRIBUTE;

/** removes a child given a certain index. It will also cleanup the running actions depending on the cleanup parameter.
 @warning Removing a child from a CCSpriteBatchNode is very slow
 */
-(void)removeChildAtIndex:(NSUInteger)index cleanup:(BOOL)doCleanup;

/** removes a child given a reference. It will also cleanup the running actions depending on the cleanup parameter.
 @warning Removing a child from a CCSpriteBatchNode is very slow
 */
-(void)removeChild: (CCSprite *)sprite cleanup:(BOOL)doCleanup;

-(void) insertChild:(CCSprite*)child inAtlasAtIndex:(NSUInteger)index;
-(void) removeSpriteFromAtlas:(CCSprite*)sprite;

-(NSUInteger) rebuildIndexInOrder:(CCSprite*)parent atlasIndex:(NSUInteger)index;
-(NSUInteger) atlasIndexForChild:(CCSprite*)sprite atZ:(NSInteger)z;

@end