diff scn2k/scn2k_impl.cc @ 53:ddbcbd000206

* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons * ParseMoji moved to TextStream * Some cleaning (0 -> NULL when needed, removal of useless returns, ...)
author thib
date Sun, 19 Apr 2009 11:44:05 +0000
parents 15a18fbe6f21
children 6d9146f56ccf
line wrap: on
line diff
--- a/scn2k/scn2k_impl.cc
+++ b/scn2k/scn2k_impl.cc
@@ -45,14 +45,15 @@ void kconv_rev(const unsigned char* src,
 string kconv(const string& s);
 string kconv_rev(const string& s);
 
-Scn2k::Scn2k(Event::Container& _event, PicContainer& _parent, class MuSys& mu, AyuSysConfig& _config) :
+Scn2k::Scn2k(Event::Container& _event, PicContainer& _parent) :
 	Event::Time(_event),
 	event(_event),
 	parent(_parent),
-	config(_config),
-	text_exec(_event, _parent, config),
-	grp_exec(_event, _parent, flag, flag.cgm_data, mu, config)
+	text_exec(_event, _parent),
+	grp_exec(_event, _parent, flag, flag.cgm_data)
 {
+	config = AyuSysConfig::GetInstance();
+
 	system_version = 0;
 	skip_mode = SKIP_NO;
 
@@ -83,7 +84,7 @@ Scn2k::Scn2k(Event::Container& _event, P
 
 	LoadSys();
 	text_exec.InitWindow();
-	grp_exec.InitSel(config);
+	grp_exec.InitSel();
 }
 
 Scn2k::~Scn2k() {
@@ -99,8 +100,10 @@ char* Scn2k::OpenScript(int new_scn_numb
 	int offset = 0;
 	int scenario_magic;
 
+	FileSearcher* file_searcher = FileSearcher::GetInstance();
+
 	sprintf(fname, "SEEN%04d.TXT", new_scn_number);
-	ARCINFO* info = file_searcher.Find(FILESEARCH::SCN, fname, "");
+	ARCINFO* info = file_searcher->Find(FileSearcher::SCN, fname, "");
 	if (info == NULL) goto err;
 	data = info->Read();
 
@@ -390,7 +393,7 @@ void Scn2k::ShowCursor(void) {
 	HideCursor();
 	char key[1024];
 	sprintf(key, "#MOUSE_CURSOR.%03d.NAME",mouse_type);
-	const char* name = config.GetParaStr(key);
+	const char* name = config->GetParaStr(key);
 	if (name == NULL || name[0] == 0) mouse_surface = DEFAULT_MOUSECURSOR;
 	else {
 		mouse_surface = parent.Root().NewSurface(name, COLOR_MASK);
@@ -485,7 +488,7 @@ void Scn2k::SysExec(Cmd& cmd) {
 	}
 	if (cmd.cmd_type == CMD_MENUREQ) {
 		int scn=0, pt=0;
-		config.GetParam("#CANCELCALL", 2, &scn, &pt);
+		config->GetParam("#CANCELCALL", 2, &scn, &pt);
 		if (scn) {
 			// 右クリックされたら global call を行う
 			cmd.cmd_type = CMD_OTHER;
@@ -550,7 +553,7 @@ void Scn2k::SysExec(Cmd& cmd) {
 				new_pt = cmd.args[1].value;
 			}
 			if (new_scn == SCN_INFO_MENU) { // menu call
-				config.GetParam("#CANCELCALL", 2, &new_scn, &new_pt);
+				config->GetParam("#CANCELCALL", 2, &new_scn, &new_pt);
 				stack.push_back(StackItem(SCN_INFO, SCN_INFO_MENU)); // menu call を示す特殊な記号
 			} else {
 				int i;
@@ -701,7 +704,7 @@ void Scn2k::SysExec(Cmd& cmd) {
 			cmd.clear();
 		}
 	} else if (cmd.cmd1 == 2 && cmd.cmd2 == 1 && cmd.cmd3 == 12) { // DLL Call
-		const char* regname = config.GetParaStr("#REGNAME");
+		const char* regname = config->GetParaStr("#REGNAME");
 		const char key_lb[] = "KEY\\LittleBusters";//FIXME: too specific to be here?
 		if (strcmp(regname, key_lb) == 0) {
 			DllCall_LB(cmd, flag);
@@ -719,7 +722,7 @@ void Scn2k::SysExec(Cmd& cmd) {
 			const char* name = cmd.Str(cmd.args[0]);
 			if (name == NULL) name = "";
 			window_title = name;
-			const char* config_name = config.GetParaStr("#CAPTION");
+			const char* config_name = config->GetParaStr("#CAPTION");
 			if (config_name == NULL) config_name = "";
 			string setname = kconv(string(config_name) + "  " + window_title);
 			parent.Root().SetWindowCaption(setname.c_str());
@@ -761,7 +764,7 @@ void Scn2k::SysExec(Cmd& cmd) {
 		} else if (cmd.cmd3 == 0x58d) {
         		// 前にロード|セーブされた番号を返す。
         	int lastsave;
-        	config.GetParam("#LASTSAVE", 1, &lastsave);
+        	config->GetParam("#LASTSAVE", 1, &lastsave);
         	flag.SetSys(lastsave-1);
 		} else if (cmd.cmd3 == 0x585) {
         		// 第一引数の記録された日付、タイトルなどが返される
@@ -792,12 +795,12 @@ fprintf(stderr,"StatSave %d:",cmd.args[0
 			Load(cmd);
 		} else if (cmd.cmd3 == 0x4b1 || cmd.cmd3 == 0x4b3) { // menu へ戻る (4b3: バッドエンド)
 			int scn_start;
-			if (config.GetParam("#SEEN_MENU", 1, &scn_start) == 0) {
+			if (config->GetParam("#SEEN_MENU", 1, &scn_start) == 0) {
 				ChangeScript(scn_start, 0);
 				save_scn = 0;
 				save_point = 0;
 				window_title = "";
-				const char* window_title_config = config.GetParaStr("#CAPTION");
+				const char* window_title_config = config->GetParaStr("#CAPTION");
 				if (window_title_config) window_title = window_title_config;
 				parent.Root().SetWindowCaption(kconv(window_title).c_str());
 				stack.clear();
@@ -858,7 +861,7 @@ string Scn2k::MakeSaveFile(void) const {
 		}
 	}
 	// ファイル名を作る
-	const char* regname = config.GetParaStr("#REGNAME");
+	const char* regname = config->GetParaStr("#REGNAME");
 
 	char* fname = new char[strlen(regname)+1];
 	/* レジストリ名をファイル名として有効なものにする */
@@ -892,10 +895,10 @@ void Scn2k::SaveSys(void) {
 	string save;
 	string path = MakeSaveFile();
 	
-	sprintf(buf, "KEY=%s\n", config.GetParaStr("#REGNAME"));
+	sprintf(buf, "KEY=%s\n", config->GetParaStr("#REGNAME"));
 	save += buf;
 	string save_config;
-	config.DiffOriginal(save_config);
+	config->DiffOriginal(save_config);
 	save += "CONFIG=";
 	save += save_config;
 	save += "\n";
@@ -946,7 +949,7 @@ void Scn2k::LoadSys(void) {
 		savedata[sz] = 0;
 		fclose(f);
 
-		sprintf(buf, "KEY=%s\n", config.GetParaStr("#REGNAME"));
+		sprintf(buf, "KEY=%s\n", config->GetParaStr("#REGNAME"));
 		if (strncmp(savedata, buf, strlen(buf)) != 0) {
 			fprintf(stderr,"Invalid header in save file %s: it must be started with \"%s\"\n", path.c_str(), buf);
 		} else  {
@@ -959,7 +962,7 @@ void Scn2k::LoadSys(void) {
 					char* config_copy = new char[l+1];
 					strncpy(config_copy, config_str, l);
 					config_copy[l] = 0;
-					config.PatchOriginal(config_copy);
+					config->PatchOriginal(config_copy);
 					delete[] config_copy;
 				}
 			}
@@ -997,12 +1000,12 @@ void Scn2k::LoadSys(void) {
 	}
 
 	/* 初期化 */
-	int scn_start; config.GetParam("#SEEN_START", 1, &scn_start);
+	int scn_start; config->GetParam("#SEEN_START", 1, &scn_start);
 	ChangeScript(scn_start, 0);
 	save_scn = 0;
 	save_point = 0;
 	window_title = "";
-	const char* window_title_config = config.GetParaStr("#CAPTION");
+	const char* window_title_config = config->GetParaStr("#CAPTION");
 	if (window_title_config) window_title = window_title_config;
 	parent.Root().SetWindowCaption(kconv(window_title).c_str());
 	stack.clear();
@@ -1033,7 +1036,7 @@ bool Scn2k::StatSaveFile(int num, int& y
 	FILE* savefile = fopen(path.c_str(), "rb");
 	if (savefile == NULL) return false;
 	char regname[1024];
-	sprintf(regname, "KEY=%s\n", config.GetParaStr("#REGNAME"));
+	sprintf(regname, "KEY=%s\n", config->GetParaStr("#REGNAME"));
 	fgets(buf,1000,savefile);
 	if (strncmp(regname, buf, strlen(regname)) != 0) {
 		fprintf(stderr,"invalid save file %s (registory name is not %s)\n",path.c_str(),regname);
@@ -1125,7 +1128,7 @@ void Scn2k::Save(Cmd& cmd) {
 
 	/* セーブファイル確認 */
 	
-	sprintf(buf, "KEY=%s\n", config.GetParaStr("#REGNAME")); save += buf;
+	sprintf(buf, "KEY=%s\n", config->GetParaStr("#REGNAME")); save += buf;
 	string save_sys; SaveImpl(save_sys);
 	string save_flag; flag.Save(save_flag);
 	string save_text; text_exec.Save(save_text, false);
@@ -1148,7 +1151,7 @@ void Scn2k::Save(Cmd& cmd) {
 	}
 	fwrite(save.c_str(), save.length(), 1, f);
 	fclose(f);
-	config.SetParam("#LASTSAVE", 1, file_number);
+	config->SetParam("#LASTSAVE", 1, file_number);
 	cmd.clear();
 }
 
@@ -1187,7 +1190,7 @@ void Scn2k::Load(Cmd& cmd) {
 	savedata[sz] = 0;
 	fclose(f);
 
-	sprintf(buf, "KEY=%s\n", config.GetParaStr("#REGNAME"));
+	sprintf(buf, "KEY=%s\n", config->GetParaStr("#REGNAME"));
 	if (strncmp(savedata, buf, strlen(buf)) != 0) {
 		fprintf(stderr,"Invalid header in save file %s: it must be started with \"%s\"\n", path.c_str(), buf);
 		delete[] savedata;
@@ -1275,7 +1278,7 @@ void Scn2k::LoadImpl(const char* save) {
 			char* s = strchr(save, '\n');
 			if (s == NULL) window_title = save;
 			else window_title.assign(save, s-save);
-			const char* config_name = config.GetParaStr("#CAPTION");
+			const char* config_name = config->GetParaStr("#CAPTION");
 			if (config_name == NULL) config_name = "";
 			string setname = kconv(string(config_name)+"  "+window_title);
 			parent.Root().SetWindowCaption(setname.c_str());
@@ -1898,8 +1901,8 @@ Scn2kMenu::Scn2kMenu(MenuType _type, Scn
 	case MENU_SAVE: pimpl = new LoadMenu(*this); break;
 	case MENU_BACKLOG: pimpl = new BacklogMenu(*this, scn_impl, text_exec); break;
 	}
-	return;
 }
+
 Scn2kMenu::~Scn2kMenu() {
 	if (pimpl) delete pimpl;
 	pimpl = NULL;