DEADSOFTWARE

move video, sound and language options to dfconfig.cfg
[d2df-sdl.git] / src / game / g_console.pas
index b7c30dea57f6bca2b12ac4df0f3ad21e2b5e2936..35530016786688639acf4254fd6435302c00bf47 100644 (file)
@@ -37,6 +37,7 @@ uses
     LAST_ACTION = ACTION_WEAPPREV;
 
 procedure g_Console_Init;
+procedure g_Console_SysInit;
 procedure g_Console_Update;
 procedure g_Console_Draw (MessagesOnly: Boolean = False);
 procedure g_Console_Char (C: AnsiChar);
@@ -85,9 +86,13 @@ implementation
 
 uses
   g_textures, g_main, e_graphics, e_input, g_game,
-  SysUtils, g_basic, g_options, Math, g_touch,
+  SysUtils, g_basic, g_options, Math, g_touch, e_res,
   g_menu, g_gui, g_language, g_net, g_netmsg, e_log, conbuf;
 
+const
+  configScript = 'dfconfig.cfg';
+  autoexecScript = 'autoexec.cfg';
+  configComment = 'generated by doom2d, do not modify';
 
 type
   PCommand = ^TCommand;
@@ -579,7 +584,7 @@ begin
   begin
     // exec <filename>
     if Length(p) = 2 then
-      g_Console_ReadConfig(GameDir + '/' + p[1])
+      g_Console_ReadConfig(p[1])
     else
       g_Console_Add('exec <script file>');
   end;
@@ -588,9 +593,14 @@ begin
   begin
     // writeconfig <filename>
     if Length(p) = 2 then
-      g_Console_WriteConfig(GameDir + '/' + p[1])
+    begin
+      s := e_GetWriteableDir(ConfigDirs);
+      g_Console_WriteConfig(e_CatPath(s, p[1]))
+    end
     else
-      g_Console_Add('writeconfig <file>');
+    begin
+      g_Console_Add('writeconfig <file>')
+    end
   end;
 
   if (cmd = 'ver') or (cmd = 'version') then
@@ -831,11 +841,9 @@ begin
   end
 end;
 
-procedure g_Console_Init();
-  var
-    a: Integer;
+procedure g_Console_SysInit;
+  var a: Integer;
 begin
-  g_Texture_CreateWAD(ID, GameWAD+':TEXTURES\CONSOLE');
   Cons_Y := -Floor(gScreenHeight * ConsoleHeight);
   gConsoleShow := False;
   gChatShow := False;
@@ -852,6 +860,9 @@ begin
 
   AddCommand('segfault', segfault, 'make segfault');
 
+  AddCommand('r_reset', g_Options_Commands);
+  AddCommand('g_language', g_Options_Commands);
+
   AddCommand('bind', BindCommands);
   AddCommand('bindlist', BindCommands);
   AddCommand('unbind', BindCommands);
@@ -1016,10 +1027,14 @@ begin
   WhitelistCommand('g_timelimit');
 
   g_Console_ResetBinds;
-  g_Console_ReadConfig(GameDir + '/dfconfig.cfg');
-  g_Console_ReadConfig(GameDir + '/autoexec.cfg');
+  g_Console_ReadConfig(configScript);
+  g_Console_ReadConfig(autoexecScript);
   gParsingBinds := False;
+end;
 
+procedure g_Console_Init;
+begin
+  g_Texture_CreateWAD(ID, GameWAD+':TEXTURES\CONSOLE');
   g_Console_Add(Format(_lc[I_CONSOLE_WELCOME], [GAME_VERSION]));
   g_Console_Add('');
 end;
@@ -1416,7 +1431,7 @@ begin
     IK_END, IK_KPEND:
       CPos := Length(Line) + 1;
     IK_A..IK_Z, IK_SPACE, IK_SHIFT, IK_RSHIFT, IK_CAPSLOCK, IK_LBRACKET, IK_RBRACKET,
-    IK_SEMICOLON, IK_QUOTE, IK_BACKSLASH, IK_SLASH, IK_COMMA, IK_DOT, IK_EQUALS,
+    IK_SEMICOLON, IK_QUOTE, IK_BACKSLASH, IK_SLASH, IK_COMMA, IK_DOT, (*IK_EQUALS,*)
     IK_0, IK_1, IK_2, IK_3, IK_4, IK_5, IK_6, IK_7, IK_8, IK_9, IK_MINUS, IK_EQUALS:
       (* see TEXTINPUT event *)
   end
@@ -1878,8 +1893,10 @@ end;
 procedure g_Console_ReadConfig (filename: String);
   var f: TextFile; s: AnsiString; i, len: Integer;
 begin
-  if FileExists(filename) then
+  e_LogWritefln('g_Console_ReadConfig (1) "%s"', [filename]);
+  if e_FindResource(ConfigDirs, filename, false) = true then
   begin
+    e_LogWritefln('g_Console_ReadConfig (2) "%s"', [filename]);
     AssignFile(f, filename);
     Reset(f);
     while not EOF(f) do
@@ -1905,7 +1922,7 @@ procedure g_Console_WriteConfig (filename: String);
 begin
   AssignFile(f, filename);
   Rewrite(f);
-  WriteLn(f, '// generated by doom2d, do not modify');
+  WriteLn(f, '// ' + configComment);
   WriteLn(f, 'unbindall');
   for i := 0 to e_MaxInputKeys - 1 do
     if (Length(gInputBinds[i].down) > 0) or (Length(gInputBinds[i].up) > 0) then
@@ -1943,17 +1960,27 @@ begin
       end
     end
   end;
+  if gAskLanguage then
+    WriteLn(f, 'g_language ask')
+  else
+    WriteLn(f, 'g_language ', gLanguage);    
+  WriteLn(f, 'r_reset');
   CloseFile(f)
 end;
 
 procedure g_Console_WriteGameConfig;
+  var s: AnsiString;
 begin
-  if gParsingBinds then
-    Exit;
-  g_Console_WriteConfig(GameDir + '/dfconfig.cfg');
+  if gParsingBinds = false then
+  begin
+    s := e_GetWriteableDir(ConfigDirs);
+    g_Console_WriteConfig(e_CatPath(s, configScript))
+  end
 end;
 
-initialization
+procedure Init;
+  var i: Integer;
+begin
   conRegVar('chat_at_top', @ChatTop, 'draw chat at top border', 'draw chat at top border');
   conRegVar('console_height', @ConsoleHeight, 0.0, 1.0, 'set console size', 'set console size');
   conRegVar('console_trans', @ConsoleTrans, 0.0, 1.0, 'set console transparency', 'set console transparency');
@@ -1967,4 +1994,11 @@ initialization
 {$ENDIF}
   ConsoleTrans := 0.1;
   ConsoleStep := 0.07;
+  conRegVar('d_eres', @debug_e_res, '', '');
+  for i := 1 to e_MaxJoys do
+    conRegVar('joy' + IntToStr(i) + '_deadzone', @e_JoystickDeadzones[i - 1], '', '')
+end;
+
+initialization
+  Init
 end.