Exemple #1
0
void LibraryPanel::LoadFromFile(const Json::Value& value, const CU_STR& dir)
{
	for (int i = 0, n = value.size(); i < n; ++i)
	{
		Json::Value layer_val = value[i];
		if (layer_val.isNull()) {
			continue;
		}

		ee::LibraryList* list = m_pages[i]->GetList();
		int item_idx = 0;
		Json::Value item_val = layer_val[item_idx++];
		while (!item_val.isNull()) {
			std::string item_path = item_val.asString();
			std::string filepath = ee::FileHelper::GetAbsolutePath(dir, item_path);
			try {
				auto sym = ee::SymbolMgr::Instance()->FetchSymbol(filepath);
				if (!sym) {
					item_val = layer_val[item_idx++];
					continue;
				}
				sym->RefreshThumbnail(sym->GetFilepath());
				list->Insert(sym);
			} catch (ee::Exception& e) {
				item_val = layer_val[item_idx++];
				continue;
			}
			item_val = layer_val[item_idx++];
		}
	}
}
Exemple #2
0
Json::Value FileSaver::StoreActor(const ee::SprConstPtr& spr, const std::string& dir,
								  bool single)
{
	Json::Value value;
	auto sym = std::dynamic_pointer_cast<ee::Symbol>(spr->GetSymbol());
	// filepath
	std::string filepath = ee::SymbolPath::GetRelativePath(*sym, dir);
	if (single) {
		value["filepath"] = filepath;
	} else {
		if (DataMgr::Instance()->GetTemplate().ContainPath(filepath)) {
			value["filepath"] = ee::FileHelper::GetFilenameWithExtension(
				sym->GetFilepath());
		} else {
			value["filepath"] = filepath;
		}
	}
	// filepaths
	const std::set<std::string>& filepaths = sym->GetFilepaths();
	std::set<std::string>::const_iterator itr = filepaths.begin();
	for (int i = 0; itr != filepaths.end(); ++itr, ++i) {
		value["filepaths"][i] = *itr;
	}
	// other
	spr->Store(value, dir);

	return value;
}
Exemple #3
0
CArchiveScanner::~CArchiveScanner()
{
	if (!isDirty)
		return;

	WriteCacheData(GetFilepath());
}
void PackParticle3dSpr::PackToLuaString(ebuilder::CodeGenerator& gen, const ee::TexturePacker& tp) const
{
	gen.line("{");
	gen.tab();

	lua::comments(gen, "file: " + GetFilepath());

	lua::assign_with_end(gen, "type", "\"p3d_spr\"");
	lua::assign_with_end(gen, "id", ee::StringHelper::ToString(GetID()));
	if (!GetName().empty()) {
		lua::assign_with_end(gen, "export", "\"" + GetName() + "\"");
	}

	lua::connect(gen, 1, 
		lua::assign("p3d_id", m_sym->GetID()));

	lua::connect(gen, 4, 
		lua::assign("is_loop", m_loop), 
		lua::assign("is_local", m_local), 
		lua::assign("is_alone", m_alone), 
		lua::assign("reuse_type", m_reuse));

	lua::connect(gen, 1, 
		lua::assign("start_radius", m_start_radius));

	gen.detab();
	gen.line("},");
}
Exemple #5
0
u64 DirList::GetFilesize(int index) const
{
	struct stat st;
	const char *path = GetFilepath(index);

	if(!path || stat(path, &st) != 0)
		return 0;

	return st.st_size;
}
CArchiveScanner::CArchiveScanner()
: isDirty(false)
{
	// the "cache" dir is created in DataDirLocater
	const std:: string cacheFolder = dataDirLocater.GetWriteDirPath() + FileSystem::EnsurePathSepAtEnd(FileSystem::GetCacheBaseDir());
	cachefile = cacheFolder + IntToString(INTERNAL_VER, "ArchiveCache%i.lua");
	ReadCacheData(GetFilepath());
	if (archiveInfos.empty()) {
		// when versioned ArchiveCache%i.lua is missing or empty, try old unversioned filename
		ReadCacheData(cacheFolder + "ArchiveCache.lua");
	}

	const std::vector<std::string>& datadirs = dataDirLocater.GetDataDirPaths();
	std::vector<std::string> scanDirs;
	for (auto d = datadirs.rbegin(); d != datadirs.rend(); ++d) {
		scanDirs.push_back(*d + "maps");
		scanDirs.push_back(*d + "base");
		scanDirs.push_back(*d + "games");
		scanDirs.push_back(*d + "packages");
	}
	// ArchiveCache has been parsed at this point --> archiveInfos is populated
	ScanDirs(scanDirs, true);
	WriteCacheData(GetFilepath());
}
Exemple #7
0
void CArchiveScanner::Reload()
{
	// {Read,Write,Scan}* all grab this too but we need the entire reloading-sequence to appear atomic
	std::lock_guard<spring::recursive_mutex> lck(scannerMutex);

	// dtor
	if (isDirty)
		WriteCacheData(GetFilepath());

	archiveInfos.clear();
	brokenArchives.clear();
	cachefile.clear();

	// ctor
	ReadCacheData(cachefile = FileSystem::EnsurePathSepAtEnd(FileSystem::GetCacheDir()) + IntToString(INTERNAL_VER, "ArchiveCache%i.lua"));
	ScanAllDirs();
}
void PackScale9Spr::PackToLuaString(ebuilder::CodeGenerator& gen, 
									const ee::TexturePacker& tp) const
{
	gen.line("{");
	gen.tab();

	lua::comments(gen, "file: " + GetFilepath());

	lua::assign_with_end(gen, "type", "\"scale9_spr\"");
	lua::assign_with_end(gen, "id", ee::StringHelper::ToString(GetID()));

	lua::connect(gen, 3, 
		lua::assign("sym_id", m_sym->GetID()), 
		lua::assign("width", m_width),
		lua::assign("height", m_height));

	gen.detab();
	gen.line("},");
}
Exemple #9
0
EditDialog::EditDialog(wxWindow* parent, wxGLContext* glctx,
					   const std::shared_ptr<Sprite>& edited, const ee::MultiSpritesImpl* sprite_impl)
	: wxDialog(parent, wxID_ANY, "Edit Texture", wxDefaultPosition, wxSize(800, 600), wxCLOSE_BOX | wxCAPTION | wxMAXIMIZE_BOX)
	, m_sym(NULL)
	, m_stage(NULL)
{
	assert(edited);

	auto sym = std::dynamic_pointer_cast<Symbol>(edited->GetSymbol());
	m_sym = sym;
//	m_sym->ReloadTexture();
	SetTitle(sym->GetFilepath());

	InitLayout(glctx, edited, sprite_impl);

	ee::SetWndDirtySJ::Instance()->SetDirty();

	m_visible_tex_edge = ee::Config::Instance()->GetSettings().visible_tex_edge;
	ee::Config::Instance()->GetSettings().visible_tex_edge = true;
}
Exemple #10
0
void PackMask::PackToLuaString(ebuilder::CodeGenerator& gen, const ee::TexturePacker& tp) const
{
	gen.line("{");
	gen.tab();

	lua::comments(gen, "file: " + GetFilepath());

	lua::assign_with_end(gen, "type", "\"mask\"");
	lua::assign_with_end(gen, "id", ee::StringHelper::ToString(GetID()));
	if (!GetName().empty()) {
		lua::assign_with_end(gen, "export", "\"" + GetName() + "\"");
	}

	lua::connect(gen, 2, 
		lua::assign("base_id", m_base->GetID()),
		lua::assign("mask_id", m_mask->GetID()));

	gen.detab();
	gen.line("},");
}
Exemple #11
0
void CArchiveScanner::ScanAllDirs()
{
	std::lock_guard<spring::recursive_mutex> lck(scannerMutex);

	const std::vector<std::string>& dataDirs = dataDirLocater.GetDataDirPaths();
	std::vector<std::string> scanDirs;
	scanDirs.reserve(dataDirs.size());

	for (auto d = dataDirs.rbegin(); d != dataDirs.rend(); ++d) {
		scanDirs.push_back(*d + "maps");
		scanDirs.push_back(*d + "base");
		scanDirs.push_back(*d + "games");
		scanDirs.push_back(*d + "packages");
	}

	// ArchiveCache has been parsed at this point --> archiveInfos is populated
#if !defined(DEDICATED) && !defined(UNITSYNC)
	ScopedOnceTimer foo("CArchiveScanner::ScanAllDirs");
#endif

	ScanDirs(scanDirs);
	WriteCacheData(GetFilepath());
}
Exemple #12
0
void PackImage::PackToLuaString(ebuilder::CodeGenerator& gen, const ee::TexturePacker& tp) const
{
	gen.line("{");
	gen.tab();

	lua::comments(gen, "file: " + GetFilepath());

	lua::assign_with_end(gen, "type", "\"image\"");
	lua::assign_with_end(gen, "id", ee::StringHelper::ToString(GetID()));

	int idx = tp.QueryIdx(m_img->GetFilepath());
	if (idx == -1) {
		idx = tp.QueryIdx(ee::ImageDataMgr::Instance()->GetDefaultSym());
	}

	char buff[256];

	sm::i16_rect quad;
	sm::ivec2 offset;
	GetPackRegion(tp, quad, offset);
	sprintf(buff, "{ %d, %d, %d, %d }",
		quad.xmin, quad.ymin, quad.xmax, quad.ymax);
	std::string src_str = buff;

	lua::connect(gen, 2, 
		lua::assign("tex", ee::StringHelper::ToString(idx)), 
		lua::assign("quad", src_str));

	if (offset.x != 0 || offset.y != 0) {
		lua::connect(gen, 2, 
			lua::assign("offx", offset.x), 
			lua::assign("offy", offset.y));
	}

	gen.detab();
	gen.line("},");
}
	bool ShaderStage::Compile()
	{
        GLboolean canCompile;
        glGetBooleanv(GL_SHADER_COMPILER, &canCompile);
        
        if ( canCompile != GL_FALSE)
        {
            // Build the source
            source = str(format("#version %d\n") % version);
            source += str(format("%s\n") % materialDef);
            source += readfile(GetFilepath().GetString());
            
            // Compile the stage
            const char * stageSource = source.c_str();
            stageId = glCreateShader(ShaderStageType::GetStageConstant(stageType));
            CheckOpenGLError("Creating shader");
            glShaderSource(stageId, 1, &stageSource, NULL);
            CheckOpenGLError("Setting shader source");
            
            glCompileShader(stageId);
            
            GLint compileState;
            glGetShaderiv(stageId, GL_COMPILE_STATUS, &compileState);
            
            if ( compileState == GL_FALSE)
            {
                stageCompiled = false;
                
                GLint logLength;
                glGetShaderiv(stageId, GL_INFO_LOG_LENGTH, &logLength);
                
                if (logLength > 0 )
                {
                    GLchar * infoLog = (GLchar *)malloc(logLength);
                    glGetShaderInfoLog(stageId, logLength, &logLength, infoLog);
                    Log(std::string(infoLog));
                }
                
                std::string filename = GetFilepath().GetString();
                std::string stageName = ShaderStageType::GetStageName(stageType);
                CheckOpenGLError(str(format("Compiling %s Shader: %s") % stageName % filename ));
                
                if (!stageCompiled)
                {
					// Display an error message and get the shader code line in error
					int lineError = DisplayCompileError(stageId);

					// Insert line numbers and line error message into the shader source
					int lineNum = 1;
					source.insert(0, std::to_string(lineNum++) + ": ");
					
					std::size_t found = source.find("\n");
					bool showError = false;
					while (found != std::string::npos)
					{
						if (showError)
						{
							// Insert an error message before the next newline
							source.insert(--found, "\t<<========== ERROR");
							found+=20;
							showError = false;
						}
						std::string strLineNum = std::to_string(lineNum++) + ": ";
						source.insert(++found, strLineNum);
						found += strLineNum.length();
						found = source.find("\n", found);

						if (lineNum == (lineError+1))
						{
							showError = true;
						}
					}
                    Log(str(format("Shader: %s\n") % filename ),"\n" + source);
                }
            }
            else
            {
                stageCompiled = true;
            }
            
            // Mark the Resource as having loaded
            SetReloaded();
        }
        else
        {
            Log("ShaderStage","Shader Compiling not supported.");
            CheckOpenGLError("Can Compile Shaders");
        }

		return stageCompiled;
	}	
CArchiveScanner::~CArchiveScanner()
{
	if (isDirty) {
		WriteCacheData(GetFilepath());
	}
}
void ExportBodymovin::FixFontLayer(const std::string& filepath, const std::string& dir)
{
	Json::Value val;
	Json::Reader reader;
	std::locale::global(std::locale(""));
	std::ifstream fin(filepath.c_str());
	std::locale::global(std::locale("C"));
	reader.parse(fin, val);
	fin.close();

	Json::Value dst_val;
	dst_val["fps"] = val["fps"];
	dst_val["name"] = val["name"];

	int IDX0 = 0;

	auto layer_name = gum::FilepathHelper::Filename(filepath.c_str());
	layer_name = layer_name.substr(0, layer_name.size() - 10);

	bool dirty = false;
	for (int i = 0, n = val["layer"].size(); i < n; ++i)
	{
		const Json::Value& layer_val = val["layer"][i];
		assert(layer_val.size() > 0 && layer_val["frame"].size() > 0);
		const Json::Value& frame_val = layer_val["frame"][IDX0];
		assert(frame_val.size() > 0 && frame_val["actor"].size() > 0);
		const Json::Value& actor_val = frame_val["actor"][IDX0];
		std::string filename = actor_val["filepath"].asString();
		filename = gum::FilepathHelper::Filename(filename.c_str()).c_str();

		int sz = dst_val["layer"].size();
		dst_val["layer"][sz] = val["layer"][i];
		if (filename.size() != 6 ||
			filename[0] != '0' ||
			filename.substr(2) != ".png") 
		{
			continue;
		}

		auto t_sym = ee::SymbolFactory::Create(s2::SYM_TEXTBOX);
		s2::Textbox tb;
		tb.width = 200;
		tb.height = 200;
		tb.font_type = 0;
		tb.font_size = 40;
		tb.font_color = pt2::Color(0, 0, 0);
		tb.has_edge = false;
		tb.align_hori = s2::Textbox::HA_LEFT;
		tb.align_vert = s2::Textbox::VA_CENTER;
		std::dynamic_pointer_cast<etext::Symbol>(t_sym)->SetTextbox(tb);
		auto t_spr = ee::SpriteFactory::Instance()->Create(t_sym);
		t_spr->UpdateBounding();

		auto text_spr = std::dynamic_pointer_cast<etext::Sprite>(t_spr);
		text_spr->SetExport(true);

		auto c_sym = ee::SymbolFactory::Create(s2::SYM_COMPLEX);
		std::dynamic_pointer_cast<ecomplex::Symbol>(c_sym)->Add(t_spr);
		CU_STR text_path = layer_name + "_" + gum::StringHelper::ToString(i) + "_text_complex.json";
		c_sym->SetFilepath(dir + "\\" + std::string(text_path.c_str()));
		auto c_spr = ee::SpriteFactory::Instance()->Create(c_sym);
		c_spr->UpdateBounding();

		ecomplex::FileStorer::Store(c_sym->GetFilepath(), *std::dynamic_pointer_cast<ecomplex::Symbol>(c_sym), dir, false);

		Json::Value new_layer = layer_val;
		for (int j = 0, m = new_layer["frame"].size(); j < m; ++j)
		{
			Json::Value& frame_val = new_layer["frame"][j];
			assert(frame_val["actor"].size() == 1);
			const Json::Value& src_val = frame_val["actor"][IDX0];

			ee::SpriteIO spr_io;
			spr_io.Load(src_val, dir.c_str());

			sm::vec2 anchor = spr_io.m_position + spr_io.m_offset;

			spr_io.m_position = spr_io.m_position + sm::rotate_vector(-spr_io.m_offset, spr_io.m_angle) + spr_io.m_offset;
			spr_io.m_angle = 0;
			float scale = std::min(fabs(spr_io.m_scale.x), fabs(spr_io.m_scale.y));
			spr_io.m_scale.x = scale;
			spr_io.m_scale.y = scale;
			spr_io.m_offset = anchor - spr_io.m_position;

			Json::Value dst_val;
			dst_val["filepath"] = text_path.c_str();
			spr_io.Store(dst_val, dir.c_str());

			frame_val["actor"][IDX0] = dst_val;
		}

		dst_val["layer"][sz + 1] = new_layer;

		dirty = true;
	}

	if (dirty) 
	{
		Json::StyledStreamWriter writer;
		std::locale::global(std::locale(""));
		std::ofstream fout(filepath.c_str());
		std::locale::global(std::locale("C"));
		writer.write(fout, dst_val);
		fout.close();
	}
}