public static Optional <TextureXImage> From(ByteReader reader) { try { UpperString name = reader.StringWithoutNulls(8); TextureXFlags flags = (TextureXFlags)reader.UShort(); Vector2 scale = new Vector2(reader.Byte(), reader.Byte()); Dimension dimension = new Dimension(reader.Short(), reader.Short()); int columnDirectory = reader.Int(); int patchCount = reader.Short(); List <TextureXPatch> patches = Range(patchCount).Map(i => { Vec2I offset = new Vec2I(reader.Short(), reader.Short()); short patchIndex = reader.Short(); short stepDirection = reader.Short(); short colormap = reader.Short(); return(new TextureXPatch(offset, patchIndex, stepDirection, colormap)); }).ToList(); return(new TextureXImage(name, flags, scale, dimension, columnDirectory, patches)); } catch { return(Empty); } }
private void ConsumeActorStateElement() { // TODO: This can fail if the next state is like `"####" "#"...` which can exist possibly... UpperString text = ConsumeIdentifier(); if (ConsumeIf('.')) { ReadDottedLabel(text); return; } if (TryReadFlowControl(text, out ActorFlowControl flowControl)) { ApplyStateBranch(flowControl); justSeenLabelOrNull = null; return; } if (ConsumeIf(':')) { TrackNewLabel(text); return; } ConsumeActorStateFrames(text); justSeenLabelOrNull = null; }
public ActorFlowControl(ActorStateBranch branchType, UpperString label) { Debug.Assert(branchType == ActorStateBranch.Loop, $"Using wrong branch type constructor ({branchType} should be only Loop)"); FlowType = branchType; Label = label; }
private static bool TryCreateAnyNamespaceTexture(UpperString name, out Texture texture, out ResourceNamespace newNamespace) { if (loadedImages.TryGetAnyValue(name, out RgbaImage loadedImage, out newNamespace)) { texture = CreateAndTrackTexture(name, newNamespace, loadedImage); return(true); } if (TextureDefinitionManager.TryGetAny(name, out TextureDefinition definition, out ResourceNamespace definitionNamespace)) { RgbaImage compiledImage = TextureDefinitionToImage(definition); loadedImages.Add(name, definitionNamespace, compiledImage); texture = CreateAndTrackTexture(name, definitionNamespace, compiledImage); return(true); } if (Data.TryFindAny(name, out IEntry entry)) { if (TryReadImageEntry(entry, entry.Namespace, out RgbaImage newImage)) { loadedImages.Add(name, entry.Namespace, newImage); texture = CreateAndTrackTexture(name, entry.Namespace, newImage); return(true); } } texture = null; newNamespace = ResourceNamespace.Global; return(false); }
/// <summary> /// Finds a map with the name provided. If the map that was found ends /// up being corrupt or it could not be found, this returns false. /// </summary> /// <param name="name">The map name.</param> /// <param name="map">The found map, or null if none was found.</param> /// <returns>The map, or an empty optional if no map name matches. /// </returns> public static bool TryFindMap(UpperString name, out MapData map) { for (int i = Archives.Count - 1; i >= 0; i--) { foreach (MapComponents mapComponents in Archives[i].GetMaps()) { if (mapComponents.Name != name) { continue; } if (MapReader.TryRead(mapComponents, out map)) { return(true); } // If we find the map but its corrupt, we won't keep // looking for other maps since that will be really // confusing to the caller. map = null; return(false); } } map = null; return(false); }
private ActorDefinition ConsumeActorHeader() { UpperString name = ConsumeString(); ActorDefinition parent = DecorateManager.BaseActorDefinition; if (ConsumeIf(':')) { UpperString parentName = ConsumeString(); Optional <ActorDefinition> parentOpt = LookupActor(parentName); if (parentOpt) { parent = parentOpt.Value; } else { throw MakeException($"Unable to find parent {parentName} for actor {name}"); } } if (ConsumeIf("replaces")) { ConsumeString(); throw MakeException("Unsupported 'replaces' keyword temporarily!"); } int?editorId = ConsumeIfInt(); return(new ActorDefinition(name, parent, editorId)); }
private void ResolveFlowOverrides() { foreach (var labelFlowPair in flowOverrides) { UpperString label = labelFlowPair.Key; ActorFlowControl flowControl = labelFlowPair.Value; if (!Labels.Contains(label)) { Log.Error($"Unable to find label {label} in actor {definition.Name}"); continue; } switch (flowControl.FlowType) { case ActorStateBranch.Goto: int newOffset = ResolveOverrideGotoOffset(flowControl) ?? 0; Labels.Add(label, newOffset); break; case ActorStateBranch.Stop: Labels.Remove(label); break; default: Log.Error($"Cannot apply flow override branch type {flowControl.FlowType} to label {label} in actor {definition.Name}"); break; } } }
private int?LabelToOffset(ActorFrame frame) { ActorFlowControl flowControl = frame.FlowControl; ActorStateBranch type = flowControl.FlowType; Debug.Assert(type == ActorStateBranch.Goto || type == ActorStateBranch.Loop, "Expected Goto or Loop label here only"); int? index; UpperString label = flowControl.Label.Value; if (type == ActorStateBranch.Goto && flowControl.Parent) { UpperString parent = flowControl.Parent.Value; index = GetSuperOrParent(parent, label); if (index == null) { Log.Error($"Unable to find label: {parent}::{label}"); return(null); } } else { index = Labels[label]; if (index == null) { Log.Error($"Unable to find label: {label}"); return(null); } } // The offset to the label is the delta from our current position, // plus any extra offset that the flow control will have provided. return(index.Value - frame.FrameIndex + flowControl.Offset); }
private int?ResolveOverrideGotoOffset(ActorFlowControl flowControl) { if (!flowControl.Label) { return(null); } int? index; UpperString label = flowControl.Label.Value; if (flowControl.Parent) { index = GetSuperOrParent(flowControl.Parent.Value, label); } else { index = Labels[label]; } if (index == null) { return(null); } return(index.Value + flowControl.Offset); }
private bool TryReadFlowControl(UpperString text, out ActorFlowControl flowControl) { flowControl = null; if (!TryGetStateBranch(text, out ActorStateBranch branchType)) { return(false); } switch (branchType) { case ActorStateBranch.Goto: flowControl = ReadGotoLabel(); break; case ActorStateBranch.Loop: if (lastSeenLabelOrNull == null) { throw MakeException("Cannot loop when no label has been defined yet"); } flowControl = new ActorFlowControl(branchType, lastSeenLabelOrNull); break; default: flowControl = new ActorFlowControl(branchType); break; } return(true); }
private void ReadDottedLabel(UpperString label) { // We already read the following, so start off with it. StringBuilder labelBuilder = new StringBuilder(label.String); labelBuilder.Append('.'); while (true) { UpperString labelPiece = ConsumeIdentifier(); labelBuilder.Append(labelPiece.String); // We know we're in a label, so the identifier must be followed // by either another separator, or a terminal colon. if (!ConsumeIf('.')) { Consume(':'); break; } labelBuilder.Append('.'); } TrackNewLabel(labelBuilder.ToString()); }
private static SpriteRotations CreateSpriteFrom(UpperString name) { Texture none = TextureManager.NullTexture; Texture[] frames = { none, none, none, none, none, none, none, none }; // If we have a default rotation, set it to be the rotations for // everything and let other valid matches override it later. if (TextureManager.TryGetTexture(name + '0', ResourceNamespace.Sprites, out Texture frame0)) { frames = new[] { frame0, frame0, frame0, frame0, frame0, frame0, frame0, frame0 } } ; // Track how many 2,8 / 3,7 / 4,6 rotations we find. Write them if // we find any. int mirrorsFound = 0; AddMirrorFrameIfExists(name, '2', '8', frames, ref mirrorsFound); AddMirrorFrameIfExists(name, '3', '7', frames, ref mirrorsFound); AddMirrorFrameIfExists(name, '4', '6', frames, ref mirrorsFound); // Lastly if we have a specific rotation for some frame, use that. // This should overwrite all the other ones. for (char index = '1'; index <= '8'; index++) { AddSingleFrameIfExists(name, index, frames); } if (mirrorsFound == 3) { return(new SpriteRotations(name, frames[0], frames[1], frames[2], frames[3], frames[4])); } return(new SpriteRotations(name, frames[0], frames[1], frames[2], frames[3], frames[4], frames[5], frames[6], frames[7])); }
public SpriteRotations(UpperString name, Texture frame1, Texture frame2, Texture frame3, Texture frame4, Texture frame5, Texture frame6, Texture frame7, Texture frame8) { Name = name; textures = new[] { frame1, frame2, frame3, frame4, frame5, frame6, frame7, frame8 }; }
private static bool TryGetStateBranch(UpperString text, out ActorStateBranch branchType) { switch (text.String) { case "FAIL": branchType = ActorStateBranch.Fail; return(true); case "GOTO": branchType = ActorStateBranch.Goto; return(true); case "LOOP": branchType = ActorStateBranch.Loop; return(true); case "STOP": branchType = ActorStateBranch.Stop; return(true); case "WAIT": branchType = ActorStateBranch.Wait; return(true); } branchType = ActorStateBranch.None; return(false); }
public SpriteRotations(UpperString name, Texture frame1, Texture frame2and8, Texture frame3and7, Texture frame4and6, Texture frame5) { Name = name; Mirrored = true; textures = new[] { frame1, frame2and8, frame3and7, frame4and6, frame5, frame4and6, frame3and7, frame2and8 }; }
/// <summary> /// Creates a new wad entry. /// </summary> /// <param name="name">The wad entry name.</param> /// <param name="resourceNamespace">The resource namespace of this /// entry.</param> /// <param name="data">The data for this entry.</param> public WadEntry(UpperString name, ResourceNamespace resourceNamespace, byte[] data) { Path = new EntryPath(name); Name = Path.Name; Namespace = resourceNamespace; Data = data; }
private static bool TryCreateExactNamespaceTexture(UpperString name, ResourceNamespace resourceNamespace, out Texture texture) { if (loadedImages.TryGetValue(name, resourceNamespace, out RgbaImage loadedImage)) { texture = CreateAndTrackTexture(name, resourceNamespace, loadedImage); return(true); } if (TextureDefinitionManager.TryGetExact(name, resourceNamespace, out TextureDefinition definition)) { RgbaImage compiledImage = TextureDefinitionToImage(definition); loadedImages.Add(name, resourceNamespace, compiledImage); texture = CreateAndTrackTexture(name, resourceNamespace, compiledImage); return(true); } if (Data.TryFindExact(name, resourceNamespace, out IEntry entry)) { if (TryReadImageEntry(entry, resourceNamespace, out RgbaImage newImage)) { loadedImages.Add(name, resourceNamespace, newImage); texture = CreateAndTrackTexture(name, resourceNamespace, newImage); return(true); } } texture = null; return(false); }
/// <summary> /// Gets all of the entries that are under the top level folder name /// provided. /// </summary> /// <param name="folderName">The name of the folder.</param> /// <returns>An enumerator that yields entries for the folder name /// provided.</returns> public IEnumerable <IEntry> TopLevelFolderEntries(UpperString folderName) { if (topLevelFolderEntries.TryGetValue(folderName, out List <PK3Entry> folderEntries)) { return(folderEntries); } return(new List <IEntry>()); }
/// <summary> /// 查询航空公司 /// </summary> /// <param name="code">航空公司代码</param> public static Airline QueryAirline(UpperString code) { if (code.IsNullOrEmpty()) { return(null); } return(AirlineCollection.Instance[code]); }
private static WadDirectoryEntry ReadWadEntry(ByteReader reader) { int offset = reader.Int(); int size = reader.Int(); UpperString name = reader.StringWithoutNulls(8); return(new WadDirectoryEntry(offset, size, name)); }
/// <summary> /// Looks up the texture image. The latest texture name in the TextureX /// entry is returned if duplicates exist. /// </summary> /// <param name="name">The name of the texture.</param> /// <returns>The most recent texture image if the texture name exists /// for some definition, null if it cannot find it.</returns> public Optional <TextureXImage> Find(UpperString name) { if (images.TryGetValue(name, out TextureXImage image)) { return(image); } return(Empty); }
public IEnumerable <GeneralBunk> QueryAllGeneralBunks(UpperString airline, UpperString departure, UpperString arrival, DateTime flightDate) { return(Values.Where(item => (item.AirlineCode.IsNullOrEmpty() || airline.Value == item.AirlineCode.Value) && flightDate.Date >= item.FlightBeginDate.Date && (!item.FlightEndDate.HasValue || flightDate.Date <= item.FlightEndDate.Value.Date) && DateTime.Today >= item.ETDZDate.Date && containsDepartureAndArrival(item, departure, arrival)).OfType <GeneralBunk>().OrderByDescending(b => b.Level).ThenByDescending(b => b.FlightBeginDate).ThenByDescending(B => B.ModifyTime).ToList()); }
public IEnumerable <IEntry> FindAll(UpperString name) { if (nameToEntry.TryGetValue(name, out List <WadEntry> existingEntries)) { return(existingEntries); } return(new List <IEntry>()); }
/// <summary> /// Looks up a definition by name. /// </summary> /// <param name="name">The name to look up.</param> /// <returns>The definition if it exists, or the 'missing' definition. /// </returns> public static ActorDefinition Find(UpperString name) { if (nameToDefinition.TryGetValue(name, out ActorDefinition definition)) { return(definition); } return(missingActorDefinition); }
public Optional <IEntry> Find(UpperString name) { if (nameToEntry.TryGetValue(name, out List <WadEntry> existingEntries)) { return(existingEntries.FirstOrDefault()); } return(Empty); }
/// <summary> /// Gets a label for the immediate parent. /// </summary> /// <param name="label">The label name.</param> /// <returns>The label index, or null if no label with the name exists. /// </returns> public int?Super(UpperString label) { if (superOffsets.TryGetValue(label, out int number)) { return(number); } return(null); }
public Optional <IEntry> FindPath(UpperString path) { if (pathToEntry.TryGetValue(path, out PK3Entry entry)) { return(entry); } return(Empty); }
private static void AddSingleFrameIfExists(UpperString name, char first, Texture[] frames) { UpperString lookupName = name + first; if (TextureManager.TryGetTexture(lookupName, ResourceNamespace.Sprites, out Texture texture)) { frames[first - '1'] = texture; } }
public int Delete(UpperString airlineCode) { string sql = "DELETE FROM [T_RefundAndRescheduling] WHERE [AIRLINE]=@AIRLINE"; using (var dbOperator = new DbOperator(Provider, ConnectionString)) { dbOperator.AddParameter("AIRLINE", airlineCode.Value); return(dbOperator.ExecuteNonQuery(sql)); } }
private static UpperString MakeRotation(UpperString name, char first, char second) { StringBuilder builder = new StringBuilder(name.String); builder.Append(first); builder.Append(name[name.Length - 1]); builder.Append(second); return(builder.ToString()); }