- save stuff to the new config.

This commit is contained in:
Christoph Oelckers 2019-10-26 19:24:46 +02:00
parent 288b230ab8
commit f53c9f6947
6 changed files with 93 additions and 35 deletions

View file

@ -2211,22 +2211,6 @@ int osdcmd_cvar_set(osdcmdptr_t parm)
return OSDCMD_OK;
}
void OSD_WriteAliases(buildvfs_FILE fp)
{
for (auto &symb : osd->symbptrs)
{
if (symb == NULL)
break;
else if (symb->func == (void *)OSD_ALIAS)
{
buildvfs_fputstr(fp, "alias \"");
buildvfs_fputstrptr(fp, symb->name);
buildvfs_fputstr(fp, "\" \"");
buildvfs_fputstrptr(fp, symb->help);
buildvfs_fputstr(fp, "\"\n");
}
}
}
void OSD_WriteCvars(buildvfs_FILE fp)
{

View file

@ -658,7 +658,6 @@ void InitBaseRes()
}
}
extern FString currentGame;
FileReader openFromBaseResource(const char* fn)
{
InitBaseRes();

View file

@ -76,7 +76,13 @@ union UCVarValue
bool Bool;
int Int;
float Float;
const char *String;
const char* String;
UCVarValue() = default;
UCVarValue(bool v) { Bool = v; }
UCVarValue(int v) { Int = v; }
UCVarValue(float v) { Float = v; }
UCVarValue(const char * v) { String = v; }
};
enum ECVarType

View file

@ -46,6 +46,9 @@
//#include "doomstat.h"
//#include "gi.h"
//#include "d_main.h"
#include "keyboard.h"
#include "control.h"
#include "osd.h"
#define GAMENAME "Demolition"
#define LASTRUNVERSION "1"
@ -275,15 +278,8 @@ void FGameConfigFile::DoGameSetup (const char *gamename)
const char *name = NULL;
while (NextInSection (key, value))
{
if (stricmp (key, "Name") == 0)
{
name = value;
}
else if (stricmp (key, "Command") == 0 && name != NULL)
{
//C_SetAlias (name, value); does not exist yet but will.
name = NULL;
}
FStringf cmd("alias %s \"%s\"", key, value);
OSD_Dispatch(cmd);
}
}
}
@ -308,7 +304,7 @@ void FGameConfigFile::DoKeySetup(const char *gamename)
//C_SetDefaultBindings ();
/*
#if 0
for (int i = 0; binders[i].label != NULL; ++i)
{
strncpy(subsection, binders[i].label, sublen);
@ -322,8 +318,25 @@ void FGameConfigFile::DoKeySetup(const char *gamename)
}
}
}
#else
strncpy(subsection, "Bindings", sublen);
if (SetSection(section))
{
const char* key;
const char* value;
while (NextInSection(key, value))
{
// The unbind here is necessary because the Build console can do multiple assignments and would not lose the original binding.
FStringf cmd("unbind %s", key);
OSD_Dispatch(cmd);
cmd.Format("bind %s \"%s\"", key, value);
OSD_Dispatch(cmd);
}
}
#endif
OkayToWrite = true;
*/
}
void FGameConfigFile::ReadNetVars ()
@ -390,6 +403,7 @@ void FGameConfigFile::ArchiveGameData (const char *gamename)
ClearCurrentSection ();
C_ArchiveCVars (this, CVAR_ARCHIVE|CVAR_AUTO);
#if 0
strncpy (subsection, "ConsoleAliases", sublen);
SetSection (section, true);
ClearCurrentSection ();
@ -408,6 +422,31 @@ void FGameConfigFile::ArchiveGameData (const char *gamename)
strncpy (subsection, "AutomapBindings", sublen);
SetSection (section, true);
//AutomapBindings.ArchiveBindings (this);
#else
strcpy(subsection, "Bindings");
if (SetSection(section))
{
for (int i = 0; i < MAXBOUNDKEYS + MAXMOUSEBUTTONS; i++)
{
if (CONTROL_KeyIsBound(i))
{
SetValueForKey(CONTROL_KeyBinds[i].key, CONTROL_KeyBinds[i].cmdstr);
}
}
}
strncpy(subsection, "ConsoleAliases", sublen);
if (SetSection(section))
{
for (auto& symb : osd->symbptrs)
{
if (symb == NULL)
break;
SetValueForKey(symb->name, symb->help);
}
}
#endif
}
void FGameConfigFile::ArchiveGlobalData ()
@ -495,12 +534,14 @@ void G_LoadConfig(const char* game)
GameConfig = new FGameConfigFile();
GameConfig->DoGlobalSetup();
GameConfig->DoGameSetup(game);
GameConfig->DoKeySetup(game);
FBaseCVar::EnableCallbacks();
GameName = game;
}
void G_SaveConfig()
{
GameConfig->ArchiveGlobalData();
GameConfig->ArchiveGameData(GameName);
GameConfig->WriteConfigFile();
delete GameConfig;

View file

@ -6,6 +6,7 @@
#include "keyboard.h"
#include "sc_man.h"
#include "c_cvars.h"
#include "gameconfigfile.h"
#include "build.h"
struct GameFuncNameDesc
@ -98,6 +99,8 @@ static const GameFuncNameDesc gamefuncs[] = {
};
extern FString currentGame;
static TMap<FName, int> GF_NameToNum;
static FString GF_NumToName[NUMGAMEFUNCTIONS]; // This one will preserve the original name for writing to the config (which must be loaded before CON scripts can hack around with the alias array.)
static FString GF_NumToAlias[NUMGAMEFUNCTIONS]; // This is for CON scripts to hack apart.
@ -120,10 +123,15 @@ static int osdcmd_button(osdcmdptr_t parm)
return OSDCMD_OK;
}
//==========================================================================
//
//
//
//==========================================================================
void SetupButtonFunctions()
{
unsigned index = 0;
// Note: This must run after the CON scripts had a chance to mess around with the game function name array.
for (auto& func : GF_NumToAlias)
{
if (func[0] == '\0')
@ -133,6 +141,12 @@ void SetupButtonFunctions()
}
//==========================================================================
//
//
//
//==========================================================================
void CONFIG_Init()
{
// This must be done before initializing any data, so doing it late in the startup process won't work.
@ -155,10 +169,17 @@ void CONFIG_Init()
index += 2;
}
SetupButtonFunctions();
CONTROL_ClearAssignments();
CONFIG_SetDefaultKeys(cl_defaultconfiguration == 1 ? "demolition/origbinds.txt" : cl_defaultconfiguration == 2 ? "demolition/leftbinds.txt" : "demolition/defbinds.txt");
}
//==========================================================================
//
//
//
//==========================================================================
int32_t CONFIG_FunctionNameToNum(const char *func)
{
if (!func) return -1;
@ -201,7 +222,12 @@ void CONFIG_DeleteButtonName(int num)
GF_NumToAlias[num] = "";
}
//==========================================================================
//
// wrapper for CONTROL_MapKey(), generates key bindings to reflect changes to keyboard setup
//
//==========================================================================
void CONFIG_MapKey(int which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2)
{
int const keys[] = { key1, key2, oldkey1, oldkey2 };
@ -246,6 +272,12 @@ void CONFIG_MapKey(int which, kb_scancode key1, kb_scancode oldkey1, kb_scancode
}
}
//==========================================================================
//
//
//
//==========================================================================
void CONFIG_SetDefaultKeys(const char *defbinds, bool lazy/*=false*/)
{
FScanner sc;
@ -304,3 +336,4 @@ void CONFIG_SetDefaultKeys(const char *defbinds, bool lazy/*=false*/)
}
}

View file

@ -473,8 +473,6 @@ long FileWriter::Seek(long offset, int mode)
size_t FileWriter::Printf(const char *fmt, ...)
{
// fix me later
#if 0
va_list ap;
FString out;
@ -482,9 +480,6 @@ size_t FileWriter::Printf(const char *fmt, ...)
out.VFormat(fmt, ap);
va_end(ap);
return Write(out.GetChars(), out.Len());
#else
return 0;
#endif
}
size_t BufferWriter::Write(const void *buffer, size_t len)