implemented script configurations

This commit is contained in:
codeimp 2008-10-31 13:47:52 +00:00
parent 927302bcca
commit 28d47f88d7
9 changed files with 224 additions and 72 deletions

View file

@ -2,20 +2,9 @@
Doom Builder Script highlighting definitions for DED
\*******************************************************************/
casesensitive = 0;
insertcase = 0; // 0=Normal, 1=Lowercase, 2=Uppercase
linecomment = "#";
commentopen = "";
commentclose = "";
string = "\"";
escape = "\\";
terminator = "";
scopeopen = "{";
scopeclose = "}";
delimiters = " \n\r\t(){}[]:;!%^&*-+=.,<>/\?|\"";
functionopen = "";
functionclose = "";
argumentdelimiter = "";
casesensitive = false;
insertcase = 0; // 0=Normal, 1=Lowercase, 2=Uppercase
lexer = 0;
keywordhelp = "";
keywords

View file

@ -2,20 +2,9 @@
Doom Builder Script highlighting definitions for DED
\*******************************************************************/
casesensitive = 0;
insertcase = 0; // 0=Normal, 1=Lowercase, 2=Uppercase
linecomment = "#";
commentopen = "#>";
commentclose = "<#";
string = "\"";
escape = "\\";
terminator = "";
scopeopen = "{";
scopeclose = "}";
delimiters = " \n\r\t(){}[]:;!%^&*-+=.,<>/\?|\"";
functionopen = "";
functionclose = "";
argumentdelimiter = "";
casesensitive = false;
insertcase = 0; // 0=Normal, 1=Lowercase, 2=Uppercase
lexer = 0;
keywordhelp = "http://deng.sourceforge.net/dew/Editing/%K";
keywords

View file

@ -2,20 +2,9 @@
Doom Builder Script highlighting definitions for FS
\*******************************************************************/
casesensitive = 1;
insertcase = 0; // 0=Normal, 1=Lowercase, 2=Uppercase
linecomment = "//";
commentopen = "/*";
commentclose = "*/";
string = "\"";
escape = "\\";
terminator = ";";
scopeopen = "{";
scopeclose = "}";
delimiters = " \n\r\t(){}[]:;!%^&*-+=.,<>/\?|\"";
functionopen = "(";
functionclose = ")";
argumentdelimiter = ",";
casesensitive = true;
insertcase = 0; // 0=Normal, 1=Lowercase, 2=Uppercase
lexer = 0;
keywordhelp = "";
keywords

View file

@ -2,20 +2,9 @@
Doom Builder Script highlighting definitions for Text
\*******************************************************************/
casesensitive = 0;
insertcase = 0; // 0=Normal, 1=Lowercase, 2=Uppercase
linecomment = "";
commentopen = "";
commentclose = "";
string = """;
escape = "";
terminator = "";
scopeopen = "";
scopeclose = "";
delimiters = "";
functionopen = "";
functionclose = "";
argumentdelimiter = "";
casesensitive = false;
insertcase = 0; // 0=Normal, 1=Lowercase, 2=Uppercase
lexer = 0;
keywordhelp = "";
keywords

View file

@ -8,20 +8,9 @@ parameters = "%FI %FO";
resultlump = "BEHAVIOR";
// Editor settings
casesensitive = 0;
insertcase = 0; // 0=Normal, 1=Lowercase, 2=Uppercase
linecomment = "//";
commentopen = "/*";
commentclose = "*/";
string = "\"";
escape = "\\";
terminator = ";";
scopeopen = "{";
scopeclose = "}";
delimiters = " \n\r\t(){}[]:;!%^&*-+=.,<>/\?|\"";
functionopen = "(";
functionclose = ")";
argumentdelimiter = ",";
casesensitive = false;
insertcase = 0; // 0=Normal, 1=Lowercase, 2=Uppercase
lexer = 35; // CPP-style, case-insensitive
keywordhelp = "http://www.zdoom.org/wiki/index.php?title=%K";
keywords

View file

@ -46,6 +46,7 @@
-->
<ItemGroup>
<Compile Include="Config\ArgumentInfo.cs" />
<Compile Include="Config\ScriptConfiguration.cs" />
<Compile Include="Config\DefinedTextureSet.cs" />
<Compile Include="Config\EnumItem.cs" />
<Compile Include="Config\EnumList.cs" />

View file

@ -0,0 +1,141 @@
#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Data;
using System.IO;
using System.Diagnostics;
using System.Windows.Forms;
using CodeImp.DoomBuilder.Map;
#endregion
namespace CodeImp.DoomBuilder.Config
{
internal class ScriptConfiguration
{
#region ================== Constants
#endregion
#region ================== Variables
// Original configuration
private Configuration cfg;
// Compiler settings
private CompilerInfo compiler;
private string parameters;
private string resultlump;
// Editor settings
private bool casesensitive;
private int insertcase;
private int lexer;
private string keywordhelp;
// Collections
private Dictionary<string, string> keywords;
private List<string> constants;
#endregion
#region ================== Properties
// Compiler settings
public CompilerInfo Compiler { get { return compiler; } }
public string Parameters { get { return parameters; } }
public string ResultLump { get { return resultlump; } }
// Editor settings
public bool CaseSensitive { get { return casesensitive; } }
public int InsertCase { get { return insertcase; } }
public int Lexer { get { return lexer; } }
public string KeywordHelp { get { return keywordhelp; } }
// Collections
public Dictionary<string, string>.KeyCollection Keywords { get { return keywords.Keys; } }
public Dictionary<string, string>.ValueCollection KeywordFunctions { get { return keywords.Values; } }
public ICollection<string> Constants { get { return constants; } }
#endregion
#region ================== Constructor / Disposer
// Constructor
internal ScriptConfiguration(Configuration cfg)
{
string compilername;
IDictionary dic;
// Initialize
this.cfg = cfg;
this.keywords = new Dictionary<string,string>();
this.constants = new List<string>();
// Read settings
compilername = cfg.ReadSetting("compiler", "");
parameters = cfg.ReadSetting("parameters", "");
resultlump = cfg.ReadSetting("resultlump", "");
casesensitive = cfg.ReadSetting("casesensitive", true);
insertcase = cfg.ReadSetting("insertcase", 0);
lexer = cfg.ReadSetting("lexer", 0);
keywordhelp = cfg.ReadSetting("keywordhelp", "");
// Load keywords
dic = cfg.ReadSetting("keywords", new Hashtable());
foreach(DictionaryEntry de in dic)
keywords.Add(de.Key.ToString(), de.Value.ToString());
// Load constants
dic = cfg.ReadSetting("constants", new Hashtable());
foreach(DictionaryEntry de in dic)
constants.Add(de.Key.ToString());
// Compiler specified?
if(compilername.Length > 0)
{
// Find compiler
foreach(CompilerInfo c in General.Compilers)
{
// Compiler name matches?
if(c.Name == compilername)
{
// Apply compiler
this.compiler = c;
break;
}
}
// No compiler found?
if(this.compiler == null) throw new Exception("No such compiler defined: '" + compilername + "'");
}
}
#endregion
#region ================== Methods
#endregion
}
}

View file

@ -79,7 +79,10 @@ namespace CodeImp.DoomBuilder.Controls
#endregion
#region ================== Methods
// This sets up the script editor with a script configuration
#endregion
#region ================== Events

View file

@ -97,6 +97,7 @@ namespace CodeImp.DoomBuilder
private const string GAME_CONFIGS_DIR = "Configurations";
private const string COMPILERS_DIR = "Compilers";
private const string PLUGINS_DIR = "Plugins";
private const string SCRIPTS_DIR = "Scripting";
private const string SETUP_DIR = "Setup";
#endregion
@ -111,6 +112,7 @@ namespace CodeImp.DoomBuilder
private static string temppath;
private static string configspath;
private static string compilerspath;
private static string scriptspath;
private static string pluginspath;
// Main objects
@ -128,6 +130,7 @@ namespace CodeImp.DoomBuilder
private static List<ConfigurationInfo> configs;
private static List<CompilerInfo> compilers;
private static List<NodebuilderInfo> nodebuilders;
private static Dictionary<string, ScriptConfiguration> scriptconfigs;
// States
private static bool debugbuild;
@ -157,6 +160,7 @@ namespace CodeImp.DoomBuilder
internal static List<ConfigurationInfo> Configs { get { return configs; } }
internal static List<NodebuilderInfo> Nodebuilders { get { return nodebuilders; } }
internal static List<CompilerInfo> Compilers { get { return compilers; } }
internal static Dictionary<string, ScriptConfiguration> ScriptConfigs { get { return scriptconfigs; } }
public static MapManager Map { get { return map; } }
internal static ActionManager Actions { get { return actions; } }
internal static PluginManager Plugins { get { return plugins; } }
@ -369,6 +373,58 @@ namespace CodeImp.DoomBuilder
nodebuilders.Sort();
}
// This loads all script configurations
private static void LoadAllScriptConfigurations()
{
Configuration cfg;
string[] filenames;
// Display status
mainwindow.DisplayStatus("Loading script configurations...");
// Make collection
scriptconfigs = new Dictionary<string, ScriptConfiguration>();
// Go for all cfg files in the scripts directory
filenames = Directory.GetFiles(scriptspath, "*.cfg", SearchOption.TopDirectoryOnly);
foreach(string filepath in filenames)
{
try
{
// Try loading the configuration
cfg = new Configuration(filepath, true);
// Check for erors
if(cfg.ErrorResult != 0)
{
// Error in configuration
ShowErrorMessage("Unable to load the script configuration file \"" + Path.GetFileName(filepath) + "\".\n" +
"Error near line " + cfg.ErrorLine + ": " + cfg.ErrorDescription, MessageBoxButtons.OK);
}
else
{
try
{
// Make script configuration
ScriptConfiguration scfg = new ScriptConfiguration(cfg);
string filename = Path.GetFileName(filepath);
scriptconfigs.Add(filename, scfg);
}
catch(Exception e)
{
// Unable to load configuration
ShowErrorMessage("Unable to load the script configuration \"" + Path.GetFileName(filepath) + "\". Error: " + e.Message, MessageBoxButtons.OK);
}
}
}
catch(Exception)
{
// Unable to load configuration
ShowErrorMessage("Unable to load the script configuration file \"" + Path.GetFileName(filepath) + "\".", MessageBoxButtons.OK);
}
}
}
// This loads all compiler configurations
private static void LoadAllCompilerConfigurations()
{
@ -478,6 +534,7 @@ namespace CodeImp.DoomBuilder
configspath = Path.Combine(apppath, GAME_CONFIGS_DIR);
compilerspath = Path.Combine(apppath, COMPILERS_DIR);
pluginspath = Path.Combine(apppath, PLUGINS_DIR);
scriptspath = Path.Combine(apppath, SCRIPTS_DIR);
logfile = Path.Combine(settingspath, LOG_FILE);
// Make program settings directory if missing
@ -492,6 +549,7 @@ namespace CodeImp.DoomBuilder
General.WriteLogLine("Configurations path: " + configspath);
General.WriteLogLine("Compilers path: " + compilerspath);
General.WriteLogLine("Plugins path: " + pluginspath);
General.WriteLogLine("Scripts path: " + scriptspath);
General.WriteLogLine("Command-line arguments: " + args.Length);
for(int i = 0; i < args.Length; i++)
General.WriteLogLine("Argument " + i + ": \"" + args[i] + "\"");
@ -553,7 +611,11 @@ namespace CodeImp.DoomBuilder
// Load nodebuilder configurations
General.WriteLogLine("Loading nodebuilder configurations...");
LoadAllNodebuilderConfigurations();
// Load script configurations
General.WriteLogLine("Loading script configurations...");
LoadAllScriptConfigurations();
// Load color settings
General.WriteLogLine("Loading color settings...");
colors = new ColorCollection(settings.Config);