/*
....[@@@..[@@@..............[@.................. MUD++ is a written from
....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and
....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++.
....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing
....[@......[@..[@@@@@..[@@@@@.................. development project. All
................................................ contributions are welcome.
....Copyright(C).1995.Melvin.Smith.............. Enjoy.
------------------------------------------------------------------------------
Melvin Smith (aka Fusion) msmith@hom.net
MUD++ development mailing list mudpp@van.ml.org
------------------------------------------------------------------------------
edit.h
*/
#ifndef _EDIT_H
#define _EDIT_H
#include "string.h"
#include "llist.h"
#include "index.h"
#include "hash.h"
#include "server.h"
#include "bit.h"
#include "room.h"
class NPC;
class PC;
class Area;
class Object;
class Help;
class TextEditor;
class RoomEditor;
class AreaEditor;
class ObjectEditor;
class NPCEditor;
class HelpEditor;
// Editor states
// Enough to cover all editor types
const int ED_CANCEL = -2; // No save
const int ED_DONE = -1;
const int ED_NONE = 0;
const int ED_TEXT_APPEND = 1;
const int ED_NAME = 20;
const int ED_DESC = 21;
const int ED_SDESC = 22;
const int ED_LDESC = 23;
const int ED_EDESC = 24;
class Editor
{
protected:
// Since objects/npcs have no index, need an index while
// editing, before inserting into a HashTable
PC * pc;
Area * area;
Index index;
int state;
int state_last;
String prompt;
String filename;
String savefile;
TextEditor *text;
public:
Editor()
: pc(0), area(0), state(0), state_last(0), prompt( "Editor>"), text(0)
{
}
Editor( PC * x )
: pc(x), area(0), state(0), state_last(0), prompt( "Editor>" ), text(0)
{
}
virtual ~Editor() { }
virtual void command( const String & ) = 0;
void setPrompt( const String & x ) { prompt = x; }
virtual const String & getPrompt();
const Index & getIndex() { return index; }
void setIndex( const Index & x ) { index = x; }
bool done() { return (bool)( state <= ED_DONE ); }
int getState() { return state; }
void setArea( Area * x ) { area = x; }
Area * getArea() { return area; }
void setFileName( const String & x ) { filename = x; }
const String & getFileName() { return filename; }
void setSaveName( const String & x ) { savefile = x; }
const String & getSaveName() { return savefile; }
void editText( const String & initial_text );
void editFile( const String & filen );
};
class RoomEditor : public Editor
{
protected:
Room *room;
bool autocopy;
int last_slot; // for repop editing
unsigned long room_bits[ MAX_ROOM_BIT_FIELDS ];
public:
RoomEditor()
: room(0), autocopy( false ), last_slot(0)
{
memset( room_bits, 0, sizeof( room_bits[0] ) * MAX_ROOM_BIT_FIELDS );
setPrompt( "RoomEditor>" );
}
RoomEditor( PC * x )
: Editor(x), room(0), autocopy( false ), last_slot(0)
{
memset( room_bits, 0, sizeof( room_bits[0] ) * MAX_ROOM_BIT_FIELDS );
setPrompt( "RoomEditor>" );
}
void command( const String & );
// const String & getPrompt();
void setRoom( Room * x ) { room = x; }
Room * getRoom() { return room; }
void parseRepop( const String & );
void toggleAutoCopy() { autocopy = !autocopy; }
};
class NPCEditor : public Editor
{
protected:
NPC *npc;
public:
NPCEditor()
: npc(0)
{
setPrompt( "NPCEditor>" );
}
NPCEditor( PC * x )
: Editor(x), npc(0)
{
setPrompt( "NPCEditor>" );
}
void command( const String & );
void setNPC( NPC * x ) { npc = x; }
NPC * getNPC() { return npc; }
};
class ObjectEditor : public Editor
{
protected:
Object *obj;
public:
ObjectEditor()
: obj(0)
{
setPrompt( "ObjEditor>" );
}
ObjectEditor( PC * x )
: Editor(x), obj(0)
{
setPrompt( "ObjEditor>" );
}
void command( const String & );
void setObj( Object * x ) { obj = x; }
Object * getObj() { return obj; }
};
class AreaEditor : public Editor
{
public:
AreaEditor()
{
setPrompt( "AreaEditor>" );
}
AreaEditor( PC * x )
: Editor(x)
{
setPrompt( "AreaEditor>" );
}
void command( const String & );
};
class HelpEditor : public Editor
{
protected:
Help * help;
public:
HelpEditor()
: help(0)
{
setPrompt( "AreaEditor>");
}
HelpEditor( PC * x )
: Editor(x), help(0)
{
setPrompt( "HelpEditor>");
}
void command( const String & );
void setHelp( Help * x ) { help = x; }
Help * getHelp() { return help; }
};
#define MAX_LINES 256
class TextEditor : public Editor
{
protected:
int lines;
int current;
int clipped;
String output;
String text[ MAX_LINES + 1 ];
String clipboard[32];
TextEditor()
: lines(0), current(0), clipped(0)
{
}
public:
TextEditor( PC * x, const String & str )
: Editor( x ),
lines(0), current(0), clipped(0)
{
for( int i = 1; i < MAX_LINES; i++ )
{
text[ i - 1 ] = str.getLine( i );
if( !(bool)text[ i - 1 ] )
break;
text[ i - 1 ].rtrim();
lines++;
current++;
}
state = ED_TEXT_APPEND;
}
virtual void command( const String & );
const char *chars();
const String & asStr();
const String & operator [] ( int i );
const String & format();
void clr();
void clrLine( int );
void cutLine( int );
void insertLine( const String &, int );
void insertLine( const char *, int );
void replaceLine( const String &, int );
void replaceLine( const char *, int );
void cutLines( int, int );
void pasteLines( int );
void append( const char * );
void append( const String & );
const String & getPrompt();
};
// Just a wrapper around file edit functions
class TextfileEditor : public Editor
{
public:
TextfileEditor(PC * x) :
Editor(x)
{}
virtual void command( const String & );
};
#endif