View Single Post
  #5  
Old 04-14-2010, 06:42 PM
kameko
Sarnak
 
Join Date: Apr 2010
Posts: 30
Default

Hello,

I wrote it in C++

two files...

main.cpp
Code:
#include <wx/wx.h>
#include <wx/dir.h>
#include <wx/string.h>
#include <wx/textfile.h>
#include <wx/ffile.h>
#include <conio.h>
#include <stdio.h>

#include "CDirTraverser.h"

void ProcessFile(const wxString& filename);

int main()
{
	int		iStatus = 0;
	int		iProcessedFiles = 0;

	wxDir	dir(wxGetCwd());
	wxArrayString	files;

	CDirTraverser traverser(files);
	dir.Traverse(traverser);
	
	for(int i = 0; i < files.GetCount(); i++)
		ProcessFile(files[i]);

	printf("Done\n");
	
	while(!_kbhit()) {}

	return iStatus;
}



void ProcessFile(const wxString& filename)
{
	wxTextFile tFile;
	wxArrayString	variableList;
	wxArrayString	asTag1, asTag2, asTag3;
	wxArrayString	asTempTag2;

	// tag1 will be the variable name
	// tag2 is what your character will say
	// tag3 is what will be displayed on screen
	wxString	tag1, tag2, tag3;

	tFile.Open(filename);
	
	tFile.AddLine(wxT(" "));
	tFile.AddLine(wxT(" "));
	tFile.AddLine(wxT(" "));

	for(int i = 0; i < tFile.GetLineCount();i++)
	{
		// Swap out quest::say for plugin::Whisper
		if(tFile[i].Contains(wxT("quest::say")))
			tFile[i].Replace(wxT("quest::say"), wxT("plugin::Whisper"));


		while(tFile[i].Contains('['))
		{
			wxString temp1 = tFile[i].AfterFirst('[');
			tag3 = temp1.BeforeFirst(']');
			
			tag1 = tag3;
			if(tag1.Contains(' '))
				tag1.Replace(wxT(" "), wxT("_"));
			if(tag1.Contains("'"))
				tag1.Replace(wxT("'"), wxT("_"));

			
			// Add tag1 and tag3 to thier arraystrings
			asTag1.Add(tag1);
			asTag3.Add(tag3);

			// Remove the first [ in the line and replace with $
			// Remove the first ] in the line.
			tFile[i].Replace(tag3, "", false);
			tFile[i].Replace("[", "$" + tag1, false);
			tFile[i].Replace("]", "", false);

		} // while(tFile[i].Contains('['))
		
		// Get a list of possible tag2 strings
		if(tFile[i].Contains("$text=~/"))
		{
			wxString temp = tFile[i].AfterFirst(wxT('/'));
			asTempTag2.Add(temp.BeforeFirst(wxT('/')));
		}
	} // for(int i = 0; i < tFile.GetLineCount();i++)

	// Need to go through the file again and get tag2
	for(int i = 0; i < asTag3.Count(); i++)				// For every tag3 look for a 
	{													// matching string
		for(int j = 0; j < asTempTag2.Count(); j++)
		{
			if(asTempTag2[j].Contains(asTag3[i]))
			{
				variableList.Add("my $" + asTag1[i] + " = quest::saylink(\""+ asTempTag2[j] + "\", 0, \"" + asTag3[i] + "\");");
			}
		} // for(int j = 0; j < asTempTag2.Count(); j++)
	} // for(int i = 0; i < asTag3.Count(); i++)
		
	// Now add the variablelist to the begining of the file
	for(int i = 0; i < variableList.Count(); i++)
		tFile.InsertLine(variableList[i], 0);

	puts(filename + "...done!");
	
	tFile.Write();
	tFile.Close();

	return;
}
and
CDirTraverser.h
Code:
#pragma once

#include <wx\dir.h>

class CDirTraverser :
	public wxDirTraverser
{
public:
	CDirTraverser(wxArrayString& files) : m_files(files) { }
	
	virtual wxDirTraverseResult OnFile(const wxString& filename);
	virtual wxDirTraverseResult OnDir(const wxString& WXUNUSED(dirname));
    
	private:
        wxArrayString& m_files;
};
CDirTraverser.cpp
Code:
#include "CDirTraverser.h"

wxDirTraverseResult CDirTraverser::OnFile(const wxString& filename)
{
	if(filename.EndsWith(wxT(".pl")))
	{
		m_files.Add(filename);
		//ProcessFile(filename);
	}
	return wxDIR_CONTINUE;
}

wxDirTraverseResult CDirTraverser::OnDir(const wxString& WXUNUSED(dirname))
{
	return wxDIR_CONTINUE;
}
I have been playing around with wxWidgets for other programming projects, so used some things from it in this code.

It's messy right now... I just hacked this together over the last 2 days. I'll be cleaning it up soon. Been actually playing eq now that I can click on links and not have to type them in!

oh, I have noticed just one thing that this code does affect, the npc quest journal in game isn't getting updated because npcs are now whispering to you... I'll look into this later on

Enjoy

Kameko
Reply With Quote