public StateManager(StateSystem statesystem, Combat.Character character, ReadOnlyKeyedCollection <Int32, State> states) { if (statesystem == null) { throw new ArgumentNullException("statesystem"); } if (character == null) { throw new ArgumentNullException("character"); } if (states == null) { throw new ArgumentNullException("states"); } m_statesystem = statesystem; m_character = character; m_states = states; m_persistencemap = new Dictionary <StateController, Int32>(); m_foreignmanager = null; m_statetime = 0; #if DEBUG m_stateorder = new CircularBuffer <State>(10); #else m_currentstate = null; m_previousstate = null; #endif }
private void LoadExtensions() { var projectRegistry = new ProjectExtensionRegistry(); RegistryUtil.ForEachPackage(this, "Projects", (packageId, key) => { foreach (string projectId in key.GetSubKeyNames()) { using (var subKey = key.OpenSubKey(projectId + "\\Extensions")) { if (subKey != null) { projectRegistry.Add(LoadExtensionRegistry(new Guid(projectId), subKey)); } } } }); ProjectRegistries = new ReadOnlyKeyedCollection <Guid, IKeyedCollection <string, ExtensionRegistration> >(projectRegistry); RegistryUtil.ForEachPackage(this, "Extensions", (packageId, key) => { DefaultRegistry = new ReadOnlyKeyedCollection <string, ExtensionRegistration>(LoadExtensionRegistry(null, key)); }); }
private ReadOnlyKeyedCollection <int, State> GetStates(string filepath) { if (filepath == null) { throw new ArgumentNullException(nameof(filepath)); } if (_statefiles.ContainsKey(filepath)) { return(_statefiles[filepath]); } var states = new KeyedCollection <int, State>(x => x.Number); var textfile = GetSubSystem <FileSystem>().OpenTextFile(filepath); TextSection laststatesection = null; List <StateController> controllers = null; foreach (var textsection in textfile) { if (_staterTitleRegex.IsMatch(textsection.Title)) { if (laststatesection != null) { var newstate = CreateState(laststatesection, controllers); if (newstate != null) { AddStateToCollection(states, newstate); } } laststatesection = textsection; controllers = new List <StateController>(); } else { var controller = CreateController(textsection); if (controller != null) { controllers?.Add(controller); } } } if (laststatesection != null) { var newstate = CreateState(laststatesection, controllers); if (newstate != null) { AddStateToCollection(states, newstate); } } var roStates = new ReadOnlyKeyedCollection <int, State>(states); _statefiles.Add(filepath, roStates); return(roStates); }
public StateSystem(SubSystems subsystems) : base(subsystems) { m_statefiles = new Dictionary<String, ReadOnlyKeyedCollection<Int32, State>>(StringComparer.OrdinalIgnoreCase); m_controllertitleregex = new Regex(@"^State\s+(\S.*)$", RegexOptions.IgnoreCase); m_statertitleregex = new Regex("Statedef\\s*(-?\\d+).*", RegexOptions.IgnoreCase); m_controllermap = BuildControllerMap(); m_internalstates = GetStates("xnaMugen.data.Internal.cns"); }
public NiLocalRegistry(IServiceProvider serviceProvider) : base(serviceProvider) { Registrations = ReadOnlyKeyedCollection.Create(_registrations); LoadProjectFactories(); LoadToolWindows(); LoadClasses(); LoadOptionPages(); }
public StateManager(StateSystem statesystem, Combat.Character character, ReadOnlyKeyedCollection<Int32, State> states) { if (statesystem == null) throw new ArgumentNullException("statesystem"); if (character == null) throw new ArgumentNullException("character"); if (states == null) throw new ArgumentNullException("states"); m_statesystem = statesystem; m_character = character; m_states = states; m_persistencemap = new Dictionary<StateController, Int32>(); m_foreignmanager = null; m_statetime = 0; #if DEBUG m_stateorder = new CircularBuffer<State>(10); #else m_currentstate = null; m_previousstate = null; #endif }
public StateManager CreateManager(Combat.Character character, ReadOnlyList <String> filepaths) { if (character == null) { throw new ArgumentNullException("character"); } if (filepaths == null) { throw new ArgumentNullException("filepaths"); } KeyedCollection <Int32, State> states = new KeyedCollection <Int32, State>(x => x.Number); foreach (String filepath in filepaths) { ReadOnlyKeyedCollection <Int32, State> loadedstates = GetStates(filepath); foreach (State state in loadedstates) { if (states.Contains(state.Number) == true) { states.Remove(state.Number); } states.Add(state); } } foreach (State state in m_internalstates) { if (states.Contains(state.Number) == false) { states.Add(state); } } return(new StateManager(this, character, new ReadOnlyKeyedCollection <Int32, State>(states))); }
static StandardSubtags() { // JohnT: can't find anywhere else to document this, so here goes: TwoToThreeMap is a file adapted from // FieldWorks Ethnologue\Data\iso-639-3_20080804.tab, by discarding all but the first column (3-letter // ethnologue codes) and the fourth (two-letter IANA codes), and all the rows where the fourth column is empty. // I then swapped the columns. So, in this resource, the string before the tab in each line is a 2-letter // Iana code, and the string after it is the one we want to return as the corresponding ISO3Code. // The following block of code assembles these lines into a map we can use to fill this slot properly // when building the main table. var twoToThreeMap = new Dictionary<string, string>(); string[] encodingPairs = LanguageRegistryResources.TwoToThreeCodes.Replace("\r\n", "\n").Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (string pair in encodingPairs) { var items = pair.Split('\t'); if (items.Length != 2) continue; twoToThreeMap[items[0]] = items[1]; } var languages = new List<LanguageSubtag>(); var scripts = new List<ScriptSubtag>(); var regions = new List<RegionSubtag>(); var variants = new List<VariantSubtag>(); string[] ianaSubtagsAsStrings = LanguageRegistryResources.ianaSubtagRegistry.Split(new[] { "%%" }, StringSplitOptions.None); foreach (string ianaSubtagAsString in ianaSubtagsAsStrings) { string[] subTagComponents = ianaSubtagAsString.Replace("\r\n", "\n").Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); if (subTagComponents[0].Contains("File-Date")) { continue; //This is the first line of the file. } CheckIfIanaSubtagFromFileHasExpectedForm(subTagComponents); string type = subTagComponents[0].Split(' ')[1]; string subtag = subTagComponents[1].Split(' ')[1]; string description = SubTagComponentDescription(subTagComponents[2]); if (subtag.Contains("..")) // do not add private use subtags to the list { continue; } /* Note: currently we are only using the first "Description:" line in each entry. * A few script entries contain multiple Description: lines, as in the example below: * * Type: script * Subtag: Deva * Description: Devanagari * Description: Nagari * Added: 2005-10-16 * * In the future it may be necessary to build a separate iana script entry collection * that contains duplicate script codes, for the purposes of including all possible * script Descriptions. */ switch (type) { case "language": string iso3Code; if (!twoToThreeMap.TryGetValue(subtag, out iso3Code)) iso3Code = subtag; languages.Add(new LanguageSubtag(subtag, description, false, iso3Code)); break; case "script": scripts.Add(new ScriptSubtag(subtag, description, false)); break; case "region": regions.Add(new RegionSubtag(subtag, description, false)); break; case "variant": variants.Add(new VariantSubtag(subtag, description, false, GetVariantPrefixes(subTagComponents))); break; } } IEnumerable<LanguageSubtag> sortedLanguages = languages.OrderBy(l => Regex.Replace(l.Name, @"[^\w]", "")) .Concat(new[] {new LanguageSubtag(WellKnownSubtags.UnlistedLanguage, "Language Not Listed", true, string.Empty)}); RegisteredLanguages = new ReadOnlyKeyedCollection<string, LanguageSubtag>(new KeyedList<string, LanguageSubtag>(sortedLanguages, l => l.Code, StringComparer.InvariantCultureIgnoreCase)); RegisteredScripts = new ReadOnlyKeyedCollection<string, ScriptSubtag>(new KeyedList<string, ScriptSubtag>(scripts.OrderBy(s => s.Name), s => s.Code, StringComparer.InvariantCultureIgnoreCase)); RegisteredRegions = new ReadOnlyKeyedCollection<string, RegionSubtag>(new KeyedList<string, RegionSubtag>(regions.OrderBy(r => r.Name), r => r.Code, StringComparer.InvariantCultureIgnoreCase)); RegisteredVariants = new ReadOnlyKeyedCollection<string, VariantSubtag>(new KeyedList<string, VariantSubtag>(variants.OrderBy(v => v.Name), v => v.Code, StringComparer.InvariantCultureIgnoreCase)); CommonPrivateUseVariants = new ReadOnlyKeyedCollection<string, VariantSubtag>(new KeyedList<string, VariantSubtag>(new[] { new VariantSubtag(WellKnownSubtags.IpaPhoneticPrivateUse, "Phonetic"), new VariantSubtag(WellKnownSubtags.IpaPhonemicPrivateUse, "Phonemic"), new VariantSubtag(WellKnownSubtags.AudioPrivateUse, "Audio") }, v => v.Code, StringComparer.InvariantCultureIgnoreCase)); Iso3Languages = RegisteredLanguages.Where(l => !string.IsNullOrEmpty(l.Iso3Code)).ToDictionary(l => l.Iso3Code, StringComparer.InvariantCultureIgnoreCase); }
public NiPackageManager(IServiceProvider serviceProvider) : base(serviceProvider) { Packages = ReadOnlyKeyedCollection.Create(_packages); }
ReadOnlyKeyedCollection<Int32, State> GetStates(String filepath) { if (filepath == null) throw new ArgumentNullException("filepath"); if (m_statefiles.ContainsKey(filepath) == true) return m_statefiles[filepath]; KeyedCollection<Int32, State> states = new KeyedCollection<Int32, State>(x => x.Number); TextFile textfile = GetSubSystem<IO.FileSystem>().OpenTextFile(filepath); TextSection laststatesection = null; List<StateController> controllers = null; foreach (TextSection textsection in textfile) { if (m_statertitleregex.IsMatch(textsection.Title) == true) { if (laststatesection != null) { State newstate = CreateState(laststatesection, controllers); if (newstate != null) AddStateToCollection(states, newstate); laststatesection = null; controllers = null; } laststatesection = textsection; controllers = new List<StateController>(); } else { StateController controller = CreateController(textsection); if (controller != null && controllers != null) controllers.Add(controller); } } if (laststatesection != null) { State newstate = CreateState(laststatesection, controllers); if (newstate != null) AddStateToCollection(states, newstate); laststatesection = null; controllers = null; } ReadOnlyKeyedCollection<Int32, State> ro_states = new ReadOnlyKeyedCollection<Int32, State>(states); m_statefiles.Add(filepath, ro_states); return ro_states; }
ReadOnlyKeyedCollection <Int32, State> GetStates(String filepath) { if (filepath == null) { throw new ArgumentNullException("filepath"); } if (m_statefiles.ContainsKey(filepath) == true) { return(m_statefiles[filepath]); } KeyedCollection <Int32, State> states = new KeyedCollection <Int32, State>(x => x.Number); TextFile textfile = GetSubSystem <IO.FileSystem>().OpenTextFile(filepath); TextSection laststatesection = null; List <StateController> controllers = null; foreach (TextSection textsection in textfile) { if (m_statertitleregex.IsMatch(textsection.Title) == true) { if (laststatesection != null) { State newstate = CreateState(laststatesection, controllers); if (newstate != null) { AddStateToCollection(states, newstate); } laststatesection = null; controllers = null; } laststatesection = textsection; controllers = new List <StateController>(); } else { StateController controller = CreateController(textsection); if (controller != null && controllers != null) { controllers.Add(controller); } } } if (laststatesection != null) { State newstate = CreateState(laststatesection, controllers); if (newstate != null) { AddStateToCollection(states, newstate); } laststatesection = null; controllers = null; } ReadOnlyKeyedCollection <Int32, State> ro_states = new ReadOnlyKeyedCollection <Int32, State>(states); m_statefiles.Add(filepath, ro_states); return(ro_states); }
internal static void InitialiseIanaSubtags(string twotothreecodes, string subtagregistry) { // JohnT: can't find anywhere else to document this, so here goes: TwoToThreeMap is a file adapted from // FieldWorks Ethnologue\Data\iso-639-3_20080804.tab, by discarding all but the first column (3-letter // ethnologue codes) and the fourth (two-letter IANA codes), and all the rows where the fourth column is empty. // I then swapped the columns. So, in this resource, the string before the tab in each line is a 2-letter // Iana code, and the string after it is the one we want to return as the corresponding ISO3Code. // The following block of code assembles these lines into a map we can use to fill this slot properly // when building the main table. var twoToThreeMap = TwoAndThreeMap(twotothreecodes, false); string[] ianaSubtagsAsStrings = subtagregistry.Split(new[] { "%%" }, StringSplitOptions.None); var languages = new List <LanguageSubtag>(); var scripts = new List <ScriptSubtag>(); var regions = new List <RegionSubtag>(); var variants = new List <VariantSubtag>(); foreach (string ianaSubtagAsString in ianaSubtagsAsStrings) { string[] subTagComponents = ianaSubtagAsString.Replace("\r\n", "\n").Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); if (subTagComponents[0].Contains("File-Date")) { continue; //This is the first line of the file. } CheckIfIanaSubtagFromFileHasExpectedForm(subTagComponents); var descriptions = new List <string>(); bool macrolanguage = false, deprecated = false, comment = false, collection = false; string type = null, subtag = null, description = null; foreach (string component in subTagComponents) { if (comment || String.IsNullOrEmpty(component.Trim())) { continue; } if (component.Split(':').Length < 2) // the description for ia (Interlingua) is spread over 2 lines { if (descriptions.Count() > 0) { description = description + component.Substring(1); descriptions.Clear(); descriptions.Add(description); } continue; } string field = component.Split(':')[0]; string value = component.Split(':')[1].Trim(); switch (field) { case "Type": type = value; break; case "Subtag": subtag = value; break; case "Tag": subtag = value; break; case "Description": // so that the description spread over 2 lines can be appended to description = SubTagComponentDescription(component); descriptions.Add(description); break; case "Deprecated": deprecated = true; break; case "Scope": if (String.Equals(value, "macrolanguage")) { macrolanguage = true; } if (String.Equals(value, "collection")) { collection = true; } break; case "Comments": comment = true; break; } } description = descriptions.First(); if (String.IsNullOrEmpty(subtag) || String.IsNullOrEmpty(description) || String.IsNullOrEmpty(type)) { continue; } if (subtag.Contains("..") || collection) // do not add private use subtags or collections to the list { continue; } /* Note: currently we are only using the first "Description:" line in each entry. * A few script entries contain multiple Description: lines, as in the example below: * * Type: script * Subtag: Deva * Description: Devanagari * Description: Nagari * Added: 2005-10-16 * * In the future it may be necessary to build a separate iana script entry collection * that contains duplicate script codes, for the purposes of including all possible * script Descriptions. */ switch (type) { case "language": string iso3Code; if (!twoToThreeMap.TryGetValue(subtag, out iso3Code)) { iso3Code = subtag; } languages.Add(new LanguageSubtag(subtag, description, false, iso3Code, descriptions, macrolanguage, deprecated)); break; case "script": scripts.Add(new ScriptSubtag(subtag, description, false, deprecated)); break; case "region": regions.Add(new RegionSubtag(subtag, description, false, deprecated)); break; case "variant": variants.Add(new VariantSubtag(subtag, description, false, deprecated, GetVariantPrefixes(subTagComponents))); break; } } IEnumerable <LanguageSubtag> sortedLanguages = languages.OrderBy(l => Regex.Replace(l.Name, @"[^\w]", "")) .Concat(new[] { new LanguageSubtag(WellKnownSubtags.UnlistedLanguage, "Language Not Listed", true, string.Empty) }); RegisteredLanguages = new KeyedList <string, LanguageSubtag>(sortedLanguages, l => l.Code, StringComparer.InvariantCultureIgnoreCase); RegisteredScripts = new KeyedList <string, ScriptSubtag>(scripts.OrderBy(s => s.Name), s => s.Code, StringComparer.InvariantCultureIgnoreCase); RegisteredRegions = new ReadOnlyKeyedCollection <string, RegionSubtag>(new KeyedList <string, RegionSubtag>(regions.OrderBy(r => r.Name), r => r.Code, StringComparer.InvariantCultureIgnoreCase)); RegisteredVariants = new ReadOnlyKeyedCollection <string, VariantSubtag>(new KeyedList <string, VariantSubtag>(variants.OrderBy(v => v.Name), v => v.Code, StringComparer.InvariantCultureIgnoreCase)); CommonPrivateUseVariants = new ReadOnlyKeyedCollection <string, VariantSubtag>(new KeyedList <string, VariantSubtag>(new[] { new VariantSubtag(WellKnownSubtags.IpaPhoneticPrivateUse, "Phonetic"), new VariantSubtag(WellKnownSubtags.IpaPhonemicPrivateUse, "Phonemic"), new VariantSubtag(WellKnownSubtags.AudioPrivateUse, "Audio") }, v => v.Code, StringComparer.InvariantCultureIgnoreCase)); }