private IMongoClient MakeMongoClient(OutputConfig importOptions) { MongoClientSettings settings = MongoClientSettingsFactory.CreateMongoClientSettings(importOptions); return(new MongoClient(settings)); }
public bool LoadInfoConfig(string ConfigFileName, int PadIndex) { string[] array = File.ReadAllLines(ConfigFileName); List <string> list = new List <string>(); List <string> list2 = new List <string>(); List <string> list3 = new List <string>(); List <string> list4 = new List <string>(); List <string> list5 = new List <string>(); for (int i = 0; i < array.Length; i++) { string text = ""; string text2 = ""; string text3 = ""; string text4 = ""; string text5 = ""; string[] array2 = array[i].Split(new char[] { '$' }); for (int j = 0; j < array2.Length; j++) { if (array2[j].StartsWith("G:")) { string input = array2[j].Remove(0, 2); Regex regex = new Regex("[^0-9, ,\\-,^a-z,^A-Z]"); text2 += regex.Replace(input, string.Empty); } else if (array2[j].StartsWith("B:")) { Regex regex2 = new Regex("[^0-9, ]"); text3 += regex2.Replace(array2[j], string.Empty); } else if (array2[j].StartsWith("A:")) { Regex regex3 = new Regex("[^0-9, ]"); text4 += regex3.Replace(array2[j], string.Empty); } else if (array2[j].StartsWith("D:")) { Regex regex4 = new Regex("[^0-9, ]"); text5 += regex4.Replace(array2[j], string.Empty); } else { text += array2[j]; } } text = text.TrimStart(new char[] { ' ' }); text = text.TrimEnd(new char[] { ' ' }); text2 = text2.TrimStart(new char[] { ' ' }); text2 = text2.TrimEnd(new char[] { ' ' }); if (text != "") { list.Add(text); } if (text2 != "") { list2.Add(text2); } if (text3 != "") { list3.Add(text3); } if (text4 != "") { list4.Add(text4); } if (text5 != "") { list5.Add(text5); } } for (int k = 0; k < list2.Count; k++) { string[] array3 = list2[k].Split(new char[] { '-' }); if (array3.Length != 5 || array3[0].Length != 8 || array3[1].Length != 4 || array3[2].Length != 4 || array3[3].Length != 4 || array3[4].Length != 12) { list2.Remove(list2[k]); list.Remove(list[k]); list3.Remove(list3[k]); list4.Remove(list4[k]); list5.Remove(list5[k]); } } int num = 0; int[] array4 = new int[18]; int[] array5 = array4; int[] array6 = new int[4]; int[] array7 = array6; int mDeadZone = 0; byte mMovementType = 0; foreach (string text6 in list2) { string[] array8 = list3[num].Split(new char[] { ' ' }); int l; for (l = 0; l < array8.Length; l++) { if (l >= 18) { break; } if (array8[l] != "") { array5[l] = Convert.ToInt32(array8[l]); } else { array5[l] = 0; } } while (l < 18) { array5[l] = 0; l++; } int num2 = array8.Length - 1; while (array8[num2] == "" && num2 >= 0) { num2--; } mMovementType = Convert.ToByte(array8[num2]); string[] array9 = list4[num].Split(new char[] { ' ' }); for (l = 0; l < array9.Length; l++) { if (l >= 4) { break; } if (array9[l] != "") { array7[l] = Convert.ToInt32(array9[l]); } else { array7[l] = 0; } } while (l < 4) { array7[l] = 0; l++; } if (list5[num] != "") { mDeadZone = Convert.ToInt32(list5[num]); } else { mDeadZone = 0; } bool flag = false; if (PadIndex < 0) { foreach (OutputConfig outputConfig in GlobalDefs.OutputConfigList) { Guid guid = new Guid("00000000-0000-0000-0000-000000000000"); if (text6 == guid.ToString()) { flag = true; break; } if (text6 == outputConfig.mProductGuid.ToString()) { array5.CopyTo(outputConfig.mButtonMap, 0); array7.CopyTo(outputConfig.mAxisMap, 0); outputConfig.mDeadZone = mDeadZone; outputConfig.mMovementType = mMovementType; flag = true; break; } } if (!flag) { OutputConfig outputConfig2 = new OutputConfig(); outputConfig2.mProductGuid = new Guid(text6); outputConfig2.mProductName = list[num]; array5.CopyTo(outputConfig2.mButtonMap, 0); array7.CopyTo(outputConfig2.mAxisMap, 0); outputConfig2.mDeadZone = mDeadZone; outputConfig2.mMovementType = mMovementType; GlobalDefs.OutputConfigList.Add(outputConfig2); } } else { if (PadIndex >= GlobalDefs.OutputConfigList.Count <OutputConfig>()) { return(false); } if (text6 == GlobalDefs.OutputConfigList[PadIndex].mProductGuid.ToString()) { array5.CopyTo(GlobalDefs.OutputConfigList[PadIndex].mButtonMap, 0); array7.CopyTo(GlobalDefs.OutputConfigList[PadIndex].mAxisMap, 0); GlobalDefs.OutputConfigList[PadIndex].mDeadZone = mDeadZone; GlobalDefs.OutputConfigList[PadIndex].mMovementType = mMovementType; return(true); } } num++; } return(PadIndex == -1); }
/// <summary> /// Create and set the output for a giving output config, output object, input object and a given farmer. /// If the farmer is not passed, the default one will be used. /// </summary> /// <param name="outputConfig">The output config</param> /// <param name="output">The output to load the name on</param> /// <param name="input">The input used</param> /// <param name="who">The farmer to be used</param> public static void LoadOutputName(OutputConfig outputConfig, Object output, Object input, Farmer who = null) { string outputName = null; bool inputUsed = false; who = who ?? Game1.player; if (outputConfig.PreserveType.HasValue) { string inputName = input?.Name ?? outputConfig.OutputGenericParentName ?? ""; if (outputConfig.KeepInputParentIndex) { if (input?.preservedParentSheetIndex.Value == -1) { inputName = outputConfig.OutputGenericParentName; } else if (input?.preservedParentSheetIndex.Value > 0 && Game1.objectInformation.ContainsKey(input.preservedParentSheetIndex.Value)) { inputName = ObjectUtils.GetObjectParameter(Game1.objectInformation[input.preservedParentSheetIndex.Value], (int)ObjectParameter.Name); } } else if (input?.preservedParentSheetIndex.Value > 0 && Game1.objectInformation.ContainsKey(input.ParentSheetIndex)) { inputName = ObjectUtils.GetObjectParameter(Game1.objectInformation[input.ParentSheetIndex], (int)ObjectParameter.Name); } outputName = ObjectUtils.GetPreserveName(outputConfig.PreserveType.Value, inputName); output.preserve.Value = outputConfig.PreserveType; inputUsed = true; } else if (output.parentSheetIndex == 340) { outputName = $"{input?.Name ?? "Wild"} Honey"; inputUsed = true; } else if (outputConfig.OutputName != null) { string inputName = input?.Name ?? outputConfig.OutputGenericParentName ?? ""; if (outputConfig.KeepInputParentIndex) { if (input?.preservedParentSheetIndex.Value == -1) { inputName = outputConfig.OutputGenericParentName; } else if (input?.preservedParentSheetIndex.Value > 0 && Game1.objectInformation.ContainsKey(input.preservedParentSheetIndex.Value)) { inputName = ObjectUtils.GetObjectParameter(Game1.objectInformation[input.preservedParentSheetIndex.Value], (int)ObjectParameter.Name); } } else if (input?.preservedParentSheetIndex.Value > 0 && Game1.objectInformation.ContainsKey(input.ParentSheetIndex)) { inputName = ObjectUtils.GetObjectParameter(Game1.objectInformation[input.ParentSheetIndex], (int)ObjectParameter.Name); } outputName = outputConfig.OutputName .Replace("{inputName}", inputName) .Replace("{outputName}", output.Name) .Replace("{farmerName}", who.Name) .Replace("{farmName}", who.farmName.Value); inputUsed = outputConfig.OutputName.Contains("{inputName}"); } if (outputName != null) { Regex regex = new Regex("[ ]{2,}", RegexOptions.None); output.Name = regex.Replace(outputName, " ").Trim(); } if (inputUsed) { output.preservedParentSheetIndex.Value = input == null ? -1 : outputConfig.KeepInputParentIndex && input.preservedParentSheetIndex.Value != 0 ? input.preservedParentSheetIndex.Value : input.ParentSheetIndex; } if (outputName != null) { output.AddCustomName(outputConfig); output.AddGenericParentName(outputConfig); output.AddContentPackUniqueID(outputConfig); } //Called just to load the display name. string loadingDisplayName = output.DisplayName; }
/// <summary> /// Choose and an output config from a list of output configs. /// </summary> /// <param name="producerRuleOutputConfig">The list of outputConfigs to choose from</param> /// <param name="random">The random object that should be used if necessary</param> /// <param name="fuelSearch">Function to search the fuel for the production. Receive the fuel id and stack amount. Should return true if there is enough fuel.</param> /// <param name="location">The location of the producer.</param> /// <param name="input">The input Object</param> /// <returns>The chosen output config</returns> /// <exception cref="RestrictionException">If there is no output config option, an exception is throw with the restriction message.</exception> public static OutputConfig ChooseOutput(List <OutputConfig> producerRuleOutputConfig, Random random, Func <int, int, bool> fuelSearch, GameLocation location, Object input = null) { List <OutputConfig> filteredOutputConfigs = FilterOutputConfig(producerRuleOutputConfig, o => o.RequiredInputQuality.Count == 0 || o.RequiredInputQuality.Any(q => q == input?.Quality), "Quality"); filteredOutputConfigs = FilterOutputConfig(filteredOutputConfigs, o => !o.RequiredInputStack.HasValue || input.stack >= o.RequiredInputStack.Value, "InputStack"); filteredOutputConfigs = FilterOutputConfig(filteredOutputConfigs, o => o.FuelList.All(f => fuelSearch(f.Item1, f.Item2)), "Fuel"); filteredOutputConfigs = FilterOutputConfig(filteredOutputConfigs, o => o.RequiredSeason.Count == 0 || o.RequiredSeason.Any(q => q == location.GetSeasonForLocation()), "Season"); filteredOutputConfigs = FilterOutputConfig(filteredOutputConfigs, o => o.RequiredWeather.Count == 0 || o.RequiredWeather.Any(q => q == GameUtils.GetCurrentWeather()), "Weather"); filteredOutputConfigs = FilterOutputConfig(filteredOutputConfigs, o => o.RequiredLocation.Count == 0 || o.RequiredLocation.Any(q => q == location.Name), "Location"); filteredOutputConfigs = FilterOutputConfig(filteredOutputConfigs, o => o.RequiredMail.Count == 0 || o.RequiredMail.Any(q => Game1.player.mailReceived.Contains(q)), "Mail"); filteredOutputConfigs = FilterOutputConfig(filteredOutputConfigs, o => o.RequiredEvent.Count == 0 || o.RequiredEvent.Any(q => Game1.player.eventsSeen.Contains(q)), "Event"); filteredOutputConfigs = FilterOutputConfig(filteredOutputConfigs, o => o.RequiredOutdoors == null || o.RequiredOutdoors == location.IsOutdoors, "Location"); if (input != null) { Object parent = null; if (input.preservedParentSheetIndex.Value > 0) { parent = new Object(input.preservedParentSheetIndex.Value, 1); } filteredOutputConfigs = FilterOutputConfig( filteredOutputConfigs , o => o.RequiredInputParentIdentifier.Count == 0 || o.RequiredInputParentIdentifier.Any( q => q == input.preservedParentSheetIndex.Value.ToString() || q == parent?.Name || q == parent?.Category.ToString() || parent?.HasContextTag(q) == true) , "InputParent", input); } List <OutputConfig> outputConfigs = filteredOutputConfigs.FindAll(o => o.OutputProbability > 0); Double chance = random.NextDouble(); Double probabilities = 0; OutputConfig result = null; foreach (OutputConfig outputConfig in outputConfigs) { probabilities += outputConfig.OutputProbability; if (chance - probabilities < 0) { result = outputConfig; break; } } if (result == null) { outputConfigs = filteredOutputConfigs.FindAll(o => o.OutputProbability <= 0); double increment = (1 - probabilities) / outputConfigs.Count; foreach (OutputConfig outputConfig in outputConfigs) { probabilities += increment; if (chance - probabilities < 0) { result = outputConfig; break; } } } result = result ?? filteredOutputConfigs.FirstOrDefault(); if (result != null && result.ReplaceWithInputParentIndex && input != null && input.preservedParentSheetIndex.Value > 0) { result = result.Clone(); result.OutputIndex = input.preservedParentSheetIndex.Value; } return(result); }
//Switch between 180 210 and 230° void SwitchConfig(OutputConfig c) { switch (c) { case OutputConfig.dome_180: SetActiveRecursive(stitcher180_back, true); SetActiveRecursive(stitcher180_front, true); SetActiveRecursive(stitcher180_One, true); SetActiveRecursive(stitcher210_back, false); SetActiveRecursive(stitcher210_front, false); SetActiveRecursive(stitcher210_One, false); SetActiveRecursive(stitcher230_back, false); SetActiveRecursive(stitcher230_front, false); SetActiveRecursive(stitcher230_One, false); break; case OutputConfig.dome_210: SetActiveRecursive(stitcher180_back, false); SetActiveRecursive(stitcher180_front, false); SetActiveRecursive(stitcher180_One, false); SetActiveRecursive(stitcher210_back, true); SetActiveRecursive(stitcher210_front, true); SetActiveRecursive(stitcher210_One, true); SetActiveRecursive(stitcher230_back, false); SetActiveRecursive(stitcher230_front, false); SetActiveRecursive(stitcher230_One, false); break; case OutputConfig.dome_230: SetActiveRecursive(stitcher180_back, false); SetActiveRecursive(stitcher180_front, false); SetActiveRecursive(stitcher180_One, false); SetActiveRecursive(stitcher210_back, false); SetActiveRecursive(stitcher210_front, false); SetActiveRecursive(stitcher210_One, false); SetActiveRecursive(stitcher230_back, true); SetActiveRecursive(stitcher230_front, true); SetActiveRecursive(stitcher230_One, true); break; case OutputConfig.dome_18015: SetActiveRecursive(stitcher180_back, true); SetActiveRecursive(stitcher180_front, true); SetActiveRecursive(stitcher180_One, true); SetActiveRecursive(stitcher210_back, false); SetActiveRecursive(stitcher210_front, false); SetActiveRecursive(stitcher210_One, false); SetActiveRecursive(stitcher230_back, false); SetActiveRecursive(stitcher230_front, false); SetActiveRecursive(stitcher230_One, false); break; case OutputConfig.dome_18025: SetActiveRecursive(stitcher180_back, true); SetActiveRecursive(stitcher180_front, true); SetActiveRecursive(stitcher180_One, true); SetActiveRecursive(stitcher210_back, false); SetActiveRecursive(stitcher210_front, false); SetActiveRecursive(stitcher210_One, false); SetActiveRecursive(stitcher230_back, false); SetActiveRecursive(stitcher230_front, false); SetActiveRecursive(stitcher230_One, false); break; } currentConfig = c; }
public OutputConfig GetConfig(float borderHeight) { var rb = GetComponent <Rigidbody2D>(); OutputConfig cfg = new OutputConfig() { type = shapeType.ToString(), physicType = rb.bodyType.ToString(), name = name }; cfg.init = new InitConfig(); cfg.init.position = new float[] { FixFloat(tran.position.x * 100 / Factor), FixFloat(borderHeight - tran.position.y * 100 / Factor) }; switch (shapeType) { case DynamicObjectType.box: cfg.init.width = FixFloat(tran.lossyScale.x * 100 / Factor); cfg.init.height = FixFloat(tran.lossyScale.y * 100 / Factor); break; case DynamicObjectType.circle: case DynamicObjectType.triangle: case DynamicObjectType.hexagon: case DynamicObjectType.star: cfg.init.radius = FixFloat(tran.lossyScale.x * 100 / Factor); break; case DynamicObjectType.cross: { var cross = GetComponent <CrossDetails>(); cfg.init.width = FixFloat(cross.LRWidth * 100 / Factor); cfg.init.height = FixFloat(cross.TDHeight * 100 / Factor); cfg.init.thickness = FixFloat(cross.LRHeight * 100 / Factor); cfg.init.thickness2 = FixFloat(cross.TDWidth * 100 / Factor); } break; case DynamicObjectType.concave: { var concave = GetComponent <ConcaveDetails>(); cfg.init.width = FixFloat(concave.Bottom_Width * 100 / Factor); cfg.init.height = FixFloat(concave.Wall_Height * 100 / Factor); cfg.init.thickness = FixFloat(concave.Thickness * 100 / Factor); } break; case DynamicObjectType.rope: { var rope = GetComponent <RopeDetails>(); cfg.init.thickness = FixFloat(rope.LineThickness * 100 / Factor); cfg.special = new SpecialConfig { ropeHang = rope.Hang, lineLength = FixFloat(rope.LineLength * 100 / Factor), ropeBallCount = rope.BallCount, ballRadius = FixFloat(rope.BallRadius * 100 / Factor) }; } break; case DynamicObjectType.diamond: cfg.init.width = FixFloat(tran.lossyScale.x * 174 / Factor); cfg.init.height = FixFloat(tran.lossyScale.y * 300 / Factor); break; case DynamicObjectType.balloon: break; case DynamicObjectType.garland: cfg.init.radius = FixFloat(tran.lossyScale.x * 150 / Factor); break; case DynamicObjectType.windmill: { var windmill = GetComponent <WindmillDetails>(); cfg.init.thickness = FixFloat(windmill.Thickness * 100 / Factor); cfg.special = new SpecialConfig { gap = FixFloat(windmill.Gap * 100 / Factor), lineLength = FixFloat(windmill.LineWidth * 100 / Factor), ballRadius = FixFloat(windmill.Radius * 100 / Factor) }; } break; case DynamicObjectType.snow: cfg.init.radius = FixFloat(tran.lossyScale.x * 50 / Factor); break; case DynamicObjectType.arrow: { var arrow = GetComponent <ArrowDetails>(); cfg.init.thickness = FixFloat(arrow.Thickness * 100 / Factor); cfg.special = new SpecialConfig { lineLength = FixFloat(arrow.LineLenght * 100 / Factor), ballRadius = FixFloat(arrow.HeadRadius * 100 / Factor) }; } break; case DynamicObjectType.triangle2: cfg.init.width = FixFloat(tran.lossyScale.x * 150 / Mathf.Cos(Mathf.PI / 6) / Factor); cfg.init.height = FixFloat(tran.lossyScale.y * 150 / Factor); break; case DynamicObjectType.dandelion: cfg.init.width = FixFloat(tran.lossyScale.x * 100 / Factor); cfg.init.height = FixFloat(tran.lossyScale.y * 200 / Factor); break; case DynamicObjectType.bird: cfg.init.width = FixFloat(tran.lossyScale.x * 200 / Factor); cfg.init.height = FixFloat(tran.lossyScale.y * 100 / Factor); break; case DynamicObjectType.pendulum: { var pendulum = GetComponent <PendulumDetails>(); cfg.init.thickness = FixFloat(pendulum.LineThickness * 100 / Factor); cfg.special = new SpecialConfig { lineLength = FixFloat(pendulum.LineLength * 100 / Factor), ballRadius = FixFloat(pendulum.BallRadius * 100 / Factor) }; } break; } if (Mathf.Abs(tran.rotation.eulerAngles.z) > Mathf.Epsilon) { cfg.init.rotation = FixFloat(-tran.rotation.eulerAngles.z); } cfg.init.mass = FixFloat(rb.mass); //cfg.init.velocity = new float[] { initialVelocity.x, initialVelocity.y }; //if (Math.Abs(initialAngularVelocity) > Mathf.Epsilon) //cfg.init.angularVelocity = initialAngularVelocity; if (Mathf.Abs(triggerDistance) > Mathf.Epsilon) { cfg.trigger = new TriggerConfig(); cfg.trigger.distance = FixFloat(triggerDistance * 100 / Factor); if (Mathf.Abs(fireInterval) > Mathf.Epsilon) { cfg.trigger.interval = fireInterval; } if (triggerVelocity != Vector2.zero) { cfg.trigger.velocity = new float[] { FixFloat(triggerVelocity.x), FixFloat(-triggerVelocity.y) } } ; if (Mathf.Abs(triggerAngularVelocity) > Mathf.Epsilon) { cfg.trigger.angularVelocity = FixFloat(triggerAngularVelocity); } if (randomVelocityRange != Vector2.zero) { cfg.trigger.randomVelocityRange = new float[] { FixFloat(randomVelocityRange.x), FixFloat(-randomVelocityRange.y) } } ; if (Mathf.Abs(randomAngularVelocityRange) > Mathf.Epsilon) { cfg.trigger.randomAngularVelocityRange = FixFloat(randomAngularVelocityRange); } } return(cfg); }
internal static void AddCustomName(this SObject obj, OutputConfig outputConfig) { obj.modData[OutputTranslationKey] = outputConfig.OutputTranslationKey ?? outputConfig.OutputName; }
/// <summary> /// Initialize FontInfo instance based on source string and user configurations. /// </summary> /// <param name="srcStr">Source string.</param> /// <param name="cfg">User output configurtion.</param> public FontInfo(String srcStr, OutputConfig cfg) { if (srcStr == null) { throw new ArgumentNullException(nameof(srcStr)); } if (cfg == null) { throw new ArgumentNullException(nameof(cfg)); } if (cfg.OutputFont == null) { throw new ArgumentNullException(nameof(cfg)); } // Generate char info for each character in the string using the largest bitmap size we're going to draw. var chrs = srcStr.ToCharArray() .Distinct() .Where(x => (cfg.SpaceGeneration || x != ' ') && x != '\n' && x != '\r') .OrderBy(x => x) .ToArray(); var charSizes = chrs.Select(x => TextRenderer.MeasureText(x.ToString(), cfg.OutputFont)).ToArray(); var maxSize = new Size(charSizes.Max(x => x.Width), charSizes.Max(x => x.Height)); CharInfos = chrs.Select(x => new CharInfo(x, maxSize, cfg)).ToArray(); // Character clipping configuration. var left = 0; var right = maxSize.Width - 1; var top = 0; var bottom = maxSize.Height - 1; var cropSyle = CropStyle.None; switch (cfg.HorizontalPaddingRemove) { case PaddingRemoval.None: break; case PaddingRemoval.Tighest: cropSyle |= CropStyle.Left | CropStyle.Right; break; case PaddingRemoval.Fixed: left = CharInfos.Min(x => x.TrimRect.Left); right = CharInfos.Max(x => x.TrimRect.Right); cropSyle |= CropStyle.Hfix; break; default: throw new ArgumentOutOfRangeException(); } switch (cfg.VerticalPaddingRemove) { case PaddingRemoval.None: break; case PaddingRemoval.Tighest: cropSyle |= CropStyle.Top | CropStyle.Bot; break; case PaddingRemoval.Fixed: top = CharInfos.Min(x => x.TrimRect.Top); bottom = CharInfos.Max(x => x.TrimRect.Bottom); cropSyle |= CropStyle.Vfih; break; default: throw new ArgumentOutOfRangeException(); } var cropRect = new Rectangle(left, top, right - left, bottom - top); foreach (var charInfo in CharInfos) { charInfo.CropBitmap(cropRect, cropSyle); } }
static bool UpdateOuput(IntPtr opaque, RenderConfig *config, ref OutputConfig output) { ReleaseTextures(); var renderFormat = DXGI_FORMAT_R8G8B8A8_UNORM; var texDesc = new D3D11_TEXTURE2D_DESC { MipLevels = 1, SampleDesc = new DXGI_SAMPLE_DESC { Count = 1 }, BindFlags = (uint)(D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE), Usage = D3D11_USAGE_DEFAULT, CPUAccessFlags = 0, ArraySize = 1, Format = renderFormat, Height = config->Height, Width = config->Width, MiscFlags = (uint)(D3D11_RESOURCE_MISC_SHARED | D3D11_RESOURCE_MISC_SHARED_NTHANDLE) }; fixed(ID3D11Texture2D **texture = &_texture) ThrowIfFailed(_d3dDevice->CreateTexture2D(&texDesc, null, texture)); IDXGIResource1 *sharedResource = null; var iid = IID_IDXGIResource1; _texture->QueryInterface(&iid, (void **)&sharedResource); fixed(void *handle = &_sharedHandle) ThrowIfFailed(sharedResource->CreateSharedHandle(null, DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE, null, (IntPtr *)handle)); sharedResource->Release(); ID3D11Device1 *d3d11VLC1; iid = IID_ID3D11Device1; _d3deviceVLC->QueryInterface(&iid, (void **)&d3d11VLC1); iid = IID_ID3D11Texture2D; fixed(ID3D11Texture2D **texture = &_textureVLC) ThrowIfFailed(d3d11VLC1->OpenSharedResource1(_sharedHandle, &iid, (void **)texture)); d3d11VLC1->Release(); var shaderResourceViewDesc = new D3D11_SHADER_RESOURCE_VIEW_DESC { ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D, Format = texDesc.Format }; shaderResourceViewDesc.Texture2D.MipLevels = 1; ID3D11Resource *res; iid = IID_ID3D11Resource; _texture->QueryInterface(&iid, (void **)&res); fixed(ID3D11ShaderResourceView **tsi = &_textureShaderInput) { ThrowIfFailed(_d3dDevice->CreateShaderResourceView(res, &shaderResourceViewDesc, tsi)); res->Release(); _d3dctx->PSSetShaderResources(0, 1, tsi); } var renderTargetViewDesc = new D3D11_RENDER_TARGET_VIEW_DESC { Format = texDesc.Format, ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D }; iid = IID_ID3D11Resource; _textureVLC->QueryInterface(&iid, (void **)&res); fixed(ID3D11RenderTargetView **trt = &_textureRenderTarget) { ThrowIfFailed(_d3deviceVLC->CreateRenderTargetView(res, &renderTargetViewDesc, trt)); res->Release(); _d3dctxVLC->OMSetRenderTargets(1, trt, null); } output.Union.DxgiFormat = (int)renderFormat; output.FullRange = true; output.ColorSpace = ColorSpace.BT709; output.ColorPrimaries = ColorPrimaries.BT709; output.TransferFunction = TransferFunction.SRGB; return(true); }
public static OutputConfig ProduceOutput(ProducerRule producerRule, Object producer, Func <int, int, bool> fuelSearch, Farmer who, GameLocation location , ProducerConfig producerConfig = null, Object input = null , bool probe = false, bool noSoundAndAnimation = false) { if (who == null) { who = Game1.getFarmer((long)producer.owner); } Vector2 tileLocation = producer.TileLocation; Random random = ProducerRuleController.GetRandomForProducing(tileLocation); OutputConfig outputConfig = OutputConfigController.ChooseOutput(producerRule.OutputConfigs, random, fuelSearch, location, input); if (outputConfig != null) { Object output = producerRule.LookForInputWhenReady == null?OutputConfigController.CreateOutput(outputConfig, input, random) : new Object(outputConfig.OutputIndex, 1); producer.heldObject.Value = output; if (!probe) { if (producerRule.LookForInputWhenReady == null) { OutputConfigController.LoadOutputName(outputConfig, producer.heldObject.Value, input, who); } if (!noSoundAndAnimation) { SoundUtil.PlaySound(producerRule.Sounds, location); SoundUtil.PlayDelayedSound(producerRule.DelayedSounds, location); } producer.minutesUntilReady.Value = outputConfig.MinutesUntilReady ?? producerRule.MinutesUntilReady; if (producerRule.SubtractTimeOfDay) { producer.minutesUntilReady.Value = Math.Max(producer.minutesUntilReady.Value - Utility.ConvertTimeToMinutes(Game1.timeOfDay) + 360, 1); } if (producerConfig != null) { producer.showNextIndex.Value = producerConfig.AlternateFrameProducing; } if (producerRule.PlacingAnimation.HasValue && !noSoundAndAnimation) { AnimationController.DisplayAnimation(producerRule.PlacingAnimation.Value, producerRule.PlacingAnimationColor, location, tileLocation, new Vector2(producerRule.PlacingAnimationOffsetX, producerRule.PlacingAnimationOffsetY)); } if (location.hasLightSource(LightSourceConfigController.GenerateIdentifier(tileLocation))) { location.removeLightSource(LightSourceConfigController.GenerateIdentifier(tileLocation)); } producer.initializeLightSource(tileLocation, false); producerRule.IncrementStatsOnInput.ForEach(s => StatsController.IncrementStardewStats(s, outputConfig.RequiredInputStack ?? producerRule.InputStack)); producerRule.IncrementStatsLabelOnInput.ForEach(s => StatsController.IncrementStardewStats(s, outputConfig.RequiredInputStack ?? producerRule.InputStack)); } } return(outputConfig); }
/// <summary> /// Adapted from https://github.com/Digus/StardewValleyMods/blob/master/PFMAutomate/Automate/CustomProducerMachine.cs /// </summary> /// <param name="input"></param> /// <returns></returns> public bool SetInput(IStorage input) { if (IsMassProducer) { MassProductionMachineDefinition mpm = ModEntry.GetMPMMachine(Machine.name, Machine.GetMassProducerKey()); foreach (ITrackedStack trackedStack in input.GetItems()) { if (trackedStack.Sample is SObject objectInput && !objectInput.bigCraftable.Value && ProducerController.GetProducerItem(Machine.Name, objectInput) is ProducerRule producerRule && !PFMCompatability.IsInputExcluded(producerRule, mpm, objectInput)) { ProducerConfig producerConfig = mpm.GetBaseProducerConfig(); if (producerConfig == null || (producerConfig.CheckLocationCondition(Location) && producerConfig.CheckSeasonCondition())) { List <InputInfo> inputsRequired = InputInfo.ConvertPFMInputs(producerRule, objectInput); if (inputsRequired.Count > 0 && input.TryGetIngredient(objectInput.ParentSheetIndex, mpm.Settings.CalculateInputRequired(inputsRequired.First()), out IConsumable inputConsumable)) { objectInput = inputConsumable.Sample as SObject; List <IConsumable> requiredFuels = GetRequiredFuels(inputsRequired, mpm.Settings, input); if (requiredFuels != null) { try { Dictionary <int, int> fuelQuantities = new Dictionary <int, int>(); foreach (InputInfo inputInfo in inputsRequired) { if (inputInfo.IsFuel) { fuelQuantities.Add(inputInfo.ID, mpm.Settings.CalculateInputRequired(inputInfo)); } } Func <int, int, bool> fuelSearch = (i, q) => input.TryGetIngredient(i, fuelQuantities[i], out IConsumable fuel); OutputConfig outputConfig = PFMCompatability.ProduceOutput(producerRule, mpm.Settings, Machine, fuelSearch, null, Location, producerConfig, objectInput, inputQuantity: mpm.Settings.CalculateInputRequired(inputsRequired.First()), noSoundAndAnimation: true, inputInfo: inputsRequired); if (outputConfig != null) { inputConsumable.Take(); requiredFuels.ForEach(f => f.Reduce()); List <IConsumable> outputRequiredFuels = GetRequiredFuels(InputInfo.ConvertPFMInputs(outputConfig), mpm.Settings, input); outputRequiredFuels.ForEach(f => f.Reduce()); return(true); } } catch (RestrictionException) { /* No action needed */ } } } } } } } else { foreach (ITrackedStack trackedStack in input.GetItems()) { if (trackedStack.Sample is SObject objectInput && !objectInput.bigCraftable.Value && ProducerController.GetProducerItem(Machine.Name, objectInput) is ProducerRule producerRule && !ProducerRuleController.IsInputExcluded(producerRule, objectInput)) { ProducerConfig producerConfig = ProducerController.GetProducerConfig(Machine.name); if (producerConfig == null || (producerConfig.CheckLocationCondition(Location) && producerConfig.CheckSeasonCondition())) { if (input.TryGetIngredient(objectInput.ParentSheetIndex, producerRule.InputStack, out IConsumable inputConsumable)) { objectInput = inputConsumable.Sample as SObject; List <IConsumable> requiredFuels = GetRequiredFuels(InputInfo.ConvertPFMInputs(producerRule, objectInput), null, input); if (requiredFuels != null) { try { Func <int, int, bool> fuelSearch = (i, q) => input.TryGetIngredient(i, q, out IConsumable fuel); OutputConfig outputConfig = ProducerRuleController.ProduceOutput(producerRule, Machine, fuelSearch, null, Location, producerConfig, objectInput, noSoundAndAnimation: true); if (outputConfig != null) { inputConsumable.Take(); requiredFuels.ForEach(f => f.Reduce()); List <IConsumable> outputRequiredFuels = GetRequiredFuels(InputInfo.ConvertPFMInputs(outputConfig), null, input); outputRequiredFuels.ForEach(f => f.Reduce()); return(true); } } catch (RestrictionException) { /* No action needed */ } } } } } } } return(false); }
//Switch between 180 210 and 230° void SwitchConfig(OutputConfig c) { Debug.Log("Switch Config.."); switch (c) { case OutputConfig.dome_180: //camrig.transform.rotation=Quaternion.Euler(0,0,0); stitcher180_back.SetActive(true); stitcher180_front.SetActive(true); stitcher180_One.SetActive(true); stitcher210_back.SetActive(false); stitcher210_front.SetActive(false); stitcher210_One.SetActive(false); stitcher230_back.SetActive(false); stitcher230_front.SetActive(false); stitcher230_One.SetActive(false); break; case OutputConfig.dome_210: //camrig.transform.rotation=Quaternion.Euler(0,0,0); stitcher180_back.SetActive(false); stitcher180_front.SetActive(false); stitcher180_One.SetActive(false); stitcher210_back.SetActive(true); stitcher210_front.SetActive(true); stitcher210_One.SetActive(true); stitcher230_back.SetActive(false); stitcher230_front.SetActive(false); stitcher230_One.SetActive(false); break; case OutputConfig.dome_230: //camrig.transform.rotation=Quaternion.Euler(0,0,0); stitcher180_back.SetActive(false); stitcher180_front.SetActive(false); stitcher180_One.SetActive(false); stitcher210_back.SetActive(false); stitcher210_front.SetActive(false); stitcher210_One.SetActive(false); stitcher230_back.SetActive(true); stitcher230_front.SetActive(true); stitcher230_One.SetActive(true); break; case OutputConfig.dome_18015: //camrig.transform.rotation=Quaternion.Euler(0,0,0); stitcher180_back.SetActive(true); stitcher180_front.SetActive(true); stitcher180_One.SetActive(true); stitcher210_back.SetActive(false); stitcher210_front.SetActive(false); stitcher210_One.SetActive(false); stitcher230_back.SetActive(false); stitcher230_front.SetActive(false); stitcher230_One.SetActive(false); break; case OutputConfig.dome_18025: //camrig.transform.rotation=Quaternion.Euler(245,180,0); stitcher180_back.SetActive(true); stitcher180_front.SetActive(true); stitcher180_One.SetActive(true); stitcher210_back.SetActive(false); stitcher210_front.SetActive(false); stitcher210_One.SetActive(false); stitcher230_back.SetActive(false); stitcher230_front.SetActive(false); stitcher230_One.SetActive(false); break; } currentConfig = c; }
/// <summary> /// Makes the machine produce an appropriate output. /// Adapted from https://github.com/Digus/StardewValleyMods/blob/master/ProducerFrameworkMod/OutputConfigController.cs /// </summary> /// <param name="producerRule"></param> /// <param name="settings"></param> /// <param name="producer"></param> /// <param name="fuelSearch"></param> /// <param name="who"></param> /// <param name="location"></param> /// <param name="producerConfig"></param> /// <param name="input"></param> /// <param name="probe"></param> /// <param name="noSoundAndAnimation"></param> /// <returns>Base output config - no values altered for mass production machine</returns> public static OutputConfig ProduceOutput(ProducerRule producerRule, MPMSettings settings, SObject producer, Func <int, int, bool> fuelSearch, Farmer who, GameLocation location, ProducerConfig producerConfig = null, SObject input = null, int inputQuantity = 0, bool probe = false, bool noSoundAndAnimation = false, List <InputInfo> inputInfo = null) { if (who == null) { who = Game1.getFarmer((long)producer.owner); } if (inputInfo == null) { inputInfo = new List <InputInfo>(); } Vector2 tileLocation = producer.TileLocation; Random random = ProducerRuleController.GetRandomForProducing(tileLocation); OutputConfig outputConfig = OutputConfigController.ChooseOutput(producerRule.OutputConfigs, random, fuelSearch, location, input); if (outputConfig != null) { SObject output = producerRule.LookForInputWhenReady == null?OutputConfigController.CreateOutput(outputConfig, input, random) : new SObject(outputConfig.OutputIndex, 1); output.Stack = settings.CalculateOutputProduced(output.Stack, inputInfo.ToArray()); if (settings.Quality.HasValue) { if (settings.Quality == QualitySetting.KeepInput) { output.Quality = input.Quality; } else { output.Quality = settings.GetOutputQuality(); } } producer.heldObject.Value = output; if (!probe) { if (producerRule.LookForInputWhenReady == null) { OutputConfigController.LoadOutputName(outputConfig, producer.heldObject.Value, input, who); } //if (!noSoundAndAnimation) //{ // SoundUtil.PlaySound(producerRule.Sounds, location); // SoundUtil.PlayDelayedSound(producerRule.DelayedSounds, location); //} int minutesUntilReadyBase = outputConfig.MinutesUntilReady ?? producerRule.MinutesUntilReady; int minutesUntilReady = settings.CalculateTimeRequired(minutesUntilReadyBase, inputInfo.ToArray()); producer.minutesUntilReady.Value = minutesUntilReady; if (producerRule.SubtractTimeOfDay) { producer.minutesUntilReady.Value = Math.Max(producer.minutesUntilReady.Value - Game1.timeOfDay, 1); } if (producerConfig != null) { producer.showNextIndex.Value = producerConfig.AlternateFrameProducing; } //if (producerRule.PlacingAnimation.HasValue && !noSoundAndAnimation) //{ // AnimationController.DisplayAnimation(producerRule.PlacingAnimation.Value, // producerRule.PlacingAnimationColor, location, tileLocation, // new Vector2(producerRule.PlacingAnimationOffsetX, producerRule.PlacingAnimationOffsetY)); //} if (location.hasLightSource(LightSourceConfigController.GenerateIdentifier(tileLocation))) { location.removeLightSource(LightSourceConfigController.GenerateIdentifier(tileLocation)); } producer.initializeLightSource(tileLocation, false); int statsIncrement = inputQuantity; producerRule.IncrementStatsOnInput.ForEach(s => StatsController.IncrementStardewStats(s, statsIncrement)); } } return(outputConfig); }
internal static bool PerformObjectDropInAction(Object __instance, Item dropInItem, bool probe, Farmer who, ref bool __result) { if (__instance.isTemporarilyInvisible || !(dropInItem is Object)) { return(false); } Object input = (Object)dropInItem; bool failLocationCondition = false; bool failSeasonCondition = false; if (__instance.heldObject.Value != null && !__instance.name.Equals("Crystalarium") || input.bigCraftable.Value) { return(true); } ProducerConfig producerConfig = ProducerController.GetProducerConfig(__instance.Name); GameLocation location = who.currentLocation; if (producerConfig != null) { if (!producerConfig.CheckLocationCondition(location)) { failLocationCondition = true; } if (!producerConfig.CheckSeasonCondition()) { failSeasonCondition = true; } if (producerConfig.NoInputStartMode != null) { return(false); } } if (ProducerController.GetProducerItem(__instance.name, input) is ProducerRule producerRule) { if (ProducerRuleController.IsInputExcluded(producerRule, input)) { return(true); } if (__instance.bigCraftable.Value && !probe && __instance.heldObject.Value == null) { __instance.scale.X = 5f; } try { if (failLocationCondition) { throw new RestrictionException(DataLoader.Helper.Translation.Get("Message.Condition.Location")); } if (failSeasonCondition) { throw new RestrictionException(DataLoader.Helper.Translation.Get("Message.Condition.Season")); } ProducerRuleController.ValidateIfInputStackLessThanRequired(producerRule, input); ProducerRuleController.ValidateIfAnyFuelStackLessThanRequired(producerRule, who); OutputConfig outputConfig = ProducerRuleController.ProduceOutput(producerRule, __instance, (i, q) => who.hasItemInInventory(i, q), who, location, producerConfig, input, probe); if (outputConfig != null) { if (!probe) { foreach (var fuel in producerRule.FuelList) { RemoveItemsFromInventory(who, fuel.Item1, fuel.Item2); } foreach (var fuel in outputConfig.FuelList) { RemoveItemsFromInventory(who, fuel.Item1, fuel.Item2); } input.Stack -= producerRule.InputStack; __result = input.Stack <= 0; } else { __result = true; } } } catch (RestrictionException e) { __result = false; if (e.Message != null && !probe && who.IsLocalPlayer) { Game1.showRedMessage(e.Message); } } return(false); } return(!failLocationCondition && !failSeasonCondition); }
internal static void AddGenericParentName(this SObject obj, OutputConfig outputConfig) { obj.modData[OutputGenericParentNameTranslationKey] = outputConfig.OutputGenericParentNameTranslationKey ?? outputConfig.OutputGenericParentName; }
[HarmonyPriority(801)] //Just before ProducerFrameworkMod. Can't use HarmonyBefore attribute, that wasn't working for some reason internal static bool PerformObjectDropInAction(SObject __instance, Item dropInItem, bool probe, Farmer who, ref bool __result) { if (__instance.isTemporarilyInvisible || !(dropInItem is SObject)) { return(false); } SObject input = dropInItem as SObject; bool failLocationCondition = false; bool failSeasonCondition = false; MPMSettings upgradeSettings = ModEntry.GetSettingsFromItem(input.name); if (upgradeSettings != null) { if (!probe) { //Change the machine's mass producer settings MassProductionMachineDefinition mpm = ModEntry.GetMPMMachine(__instance.name, upgradeSettings.Key); if (mpm == null) { Game1.showRedMessage("This cannot take that upgrade."); } else { string oldProducerKey = __instance.GetMassProducerKey(); if (!string.IsNullOrEmpty(oldProducerKey)) { string upgradeItemName = ModEntry.MPMSettings[oldProducerKey].UpgradeObject; JsonAssets.Api jsonAssets = ModEntry.Instance.Helper.ModRegistry.GetApi("spacechase0.JsonAssets") as JsonAssets.Api; int upgradeItemId = jsonAssets.GetObjectId(upgradeItemName); Game1.createItemDebris(new SObject(upgradeItemId, 1), __instance.TileLocation * Game1.tileSize, 0, who.currentLocation); } __instance.SetMassProducerKey(upgradeSettings.Key); input.Stack -= 1; __result = input.Stack <= 0; return(false); } } } else { //Check if this is a valid input for the machine's use if (string.IsNullOrEmpty(__instance.GetMassProducerKey())) { return(true); } if (__instance.heldObject.Value != null && !__instance.name.Equals("Crystalarium") || input.bigCraftable.Value) { return(true); } MassProductionMachineDefinition mpm = ModEntry.GetMPMMachine(__instance.name, __instance.GetMassProducerKey()); if (mpm == null) { return(true); } if (StaticValues.SUPPORTED_VANILLA_MACHINES.ContainsKey(__instance.name)) { IVanillaOverride vanillaOverride = VanillaOverrideList.GetFor(__instance.name); if (vanillaOverride != null) { bool overrideResult = vanillaOverride.Manual_PerformObjectDropInAction(__instance, input, probe, who, mpm); //End early if a result has been found if (overrideResult) { __result = input.Stack <= 0; return(true); } } } ProducerConfig baseConfig = mpm.GetBaseProducerConfig(); GameLocation location = who.currentLocation; if (baseConfig != null) { //TOREVIEW: maybe have machines that can break these conditions? if (!baseConfig.CheckLocationCondition(location)) { failLocationCondition = true; } if (!baseConfig.CheckSeasonCondition()) { failSeasonCondition = true; } if (baseConfig.NoInputStartMode != null) { return(true); } } if (ProducerController.GetProducerItem(__instance.name, input) is ProducerRule producerRule) { if (PFMCompatability.IsInputExcluded(producerRule, mpm, input)) { return(true); } if (__instance.bigCraftable.Value && !probe && __instance.heldObject.Value == null) { __instance.scale.X = 5f; } try { if (failLocationCondition) { throw new RestrictionException("Machine can't be used in this location."); } if (failSeasonCondition) { throw new RestrictionException("Machine can't be used in this season."); } List <InputInfo> inputAndFuelInfo = InputInfo.ConvertPFMInputs(producerRule, input); PFMCompatability.ValidateIfInputsLessThanRequired(producerRule, mpm.Settings, inputAndFuelInfo, who); Dictionary <int, int> fuelQuantities = new Dictionary <int, int>(); foreach (InputInfo inputInfo in inputAndFuelInfo) { if (inputInfo.IsFuel) { fuelQuantities.Add(inputInfo.ID, mpm.Settings.CalculateInputRequired(inputInfo)); } } Func <int, int, bool> fuelSearch = (i, q) => who.hasItemInInventory(i, fuelQuantities[i]); OutputConfig outputConfig = PFMCompatability.ProduceOutput(producerRule, mpm.Settings, __instance, fuelSearch, who, location, baseConfig, input, mpm.Settings.CalculateInputRequired(inputAndFuelInfo.First()), probe, inputInfo: inputAndFuelInfo); if (outputConfig != null) { if (!probe) { foreach (InputInfo inputInfo in inputAndFuelInfo) { if (inputInfo.IsFuel) { RemoveItemsFromInventory(who, inputInfo.ID, mpm.Settings.CalculateInputRequired(inputInfo)); } } List <InputInfo> outputConfigFuels = InputInfo.ConvertPFMInputs(outputConfig); foreach (InputInfo fuel in outputConfigFuels) { RemoveItemsFromInventory(who, fuel.ID, mpm.Settings.CalculateInputRequired(fuel)); } input.Stack -= mpm.Settings.CalculateInputRequired(inputAndFuelInfo.First()); __result = input.Stack <= 0; } else { __result = true; } } } catch (RestrictionException e) { __result = false; if (e.Message != null && !probe && who.IsLocalPlayer) { Game1.showRedMessage(e.Message); } } return(false); } } return(!failLocationCondition && !failSeasonCondition); }
internal static void AddContentPackUniqueID(this SObject obj, OutputConfig outputConfig) { obj.modData[ContentPackUniqueID] = outputConfig.ModUniqueID; }
private static string getOutputAssemblyFileName(OutputConfig outputConfig) { return (getOutputAssemblyName(outputConfig) + ".exe"); }
/// <summary> /// Create page array from the bitmap. /// </summary> /// <param name="bmp">Source bitmap.</param> /// <param name="cfg">Output configuration.</param> /// <returns>Returns page array depending on output configuration.</returns> public static Byte[] ToPageArray(this Bitmap bmp, OutputConfig cfg) { if (bmp == null) { throw new ArgumentNullException(nameof(bmp)); } if (cfg == null) { throw new ArgumentNullException(nameof(cfg)); } var pages = new List <Byte>(); // for each row for (var row = 0; row < bmp.Height; row++) { // current byte value Byte currentValue = 0, bitsRead = 0; // for each column for (var column = 0; column < bmp.Width; ++column) { // is pixel set? if (bmp.GetPixel(column, row).ToArgb() == Color.Black.ToArgb()) { // set the appropriate bit in the page if (cfg.ByteOrder == ByteOrder.MsbFirst) { currentValue |= (Byte)(1 << (7 - bitsRead)); } else { currentValue |= (Byte)(1 << bitsRead); } } // increment number of bits read ++bitsRead; // have we filled a page? if (bitsRead == 8) { // add byte to page array pages.Add(currentValue); // zero out current value currentValue = 0; // zero out bits read bitsRead = 0; } } // if we have bits left, add it as is if (bitsRead != 0) { pages.Add(currentValue); } } // generate an array of column major pages from row major pages Byte[] TransposePageArray(IReadOnlyList <Byte> rowMajorPages, Int32 w, Int32 h, ByteOrder bOrd) { // column major data has a byte for each column representing 8 rows var rowMajorPagesPerRow = (w + 7) / 8; var colMajorPagesPerRow = w; var colMajorRowCount = (h + 7) / 8; // create an array of pages filled with zeros for the column major data var colMajorPages = new Byte[colMajorPagesPerRow * colMajorRowCount]; // generate the column major data for (var row = 0; row != h; ++row) { for (var col = 0; col != w; ++col) { // get the byte containing the bit we want var srcIdx = row * rowMajorPagesPerRow + col / 8; var page = rowMajorPages[srcIdx]; // return a bitMask to pick out the 'bitIndex'th bit allowing for byteOrder // MsbFirst: bitIndex = 0 = 0x01, bitIndex = 7 = 0x80 // LsbFirst: bitIndex = 0 = 0x80, bitIndex = 7 = 0x01 Int32 GetBitMask(Int32 bitIndex, ByteOrder byteOrder) => byteOrder == ByteOrder.MsbFirst ? 0x01 << bitIndex : 0x80 >> bitIndex; // get the bit mask for the bit we want var bitMask = GetBitMask(7 - col % 8, bOrd); // set the bit in the column major data if ((page & bitMask) == 0) { continue; } var dstIdx = row / 8 * colMajorPagesPerRow + col; var p = colMajorPages[dstIdx]; colMajorPages[dstIdx] = (Byte)(p | GetBitMask(row % 8, bOrd)); } } return(colMajorPages); } // transpose the pages if column major data is requested return(cfg.BitLayout == BitLayout.ColumnMajor ? TransposePageArray(pages, bmp.Width, bmp.Height, cfg.ByteOrder) : pages.ToArray()); }
/// <summary> /// Generates the Raw Data transform that produces our program's output. /// </summary> /// <returns>A transform configuration to be given to the API pipeline.</returns> public OutputConfig GenerateTransforms() { // Clear the previous transforms should they exist. TransformManager.TransformList.Clear(); int channelNumber = 0; // Obtain the number of channels based on our sensors and their mode. for (int i = 0; i < BTPipeline.TrignoBtManager.Components.Count; i++) { if (BTPipeline.TrignoBtManager.Components[i].State == SelectionState.Allocated) { var tmp = BTPipeline.TrignoBtManager.Components[i]; BTCompConfig someconfig = tmp.Configuration as BTCompConfig; if (someconfig.IsComponentAvailable()) { channelNumber += BTPipeline.TrignoBtManager.Components[i].BtChannels.Count; } } } // Create the raw data transform, with an input and output channel for every // channel that exists in our setup. This transform applies the scaling to the raw // data from the sensor. var rawDataTransform = new TransformRawData(channelNumber, channelNumber); TransformManager.AddTransform(rawDataTransform); var fib = new FibonacciTransform(channelNumber, channelNumber); TransformManager.AddTransform(fib); var t0 = TransformManager.TransformList[0]; var fibonacciTransform = TransformManager.TransformList[1]; // The output configuration for the API to use. var outconfig = new OutputConfig(); outconfig.NumChannels = channelNumber; int channelIndex = 0; for (int i = 0; i < BTPipeline.TrignoBtManager.Components.Count; i++) { if (BTPipeline.TrignoBtManager.Components[i].State == SelectionState.Allocated) { BTCompConfig someconfig = BTPipeline.TrignoBtManager.Components[i].Configuration as BTCompConfig; if (someconfig.IsComponentAvailable()) { // For every channel in every sensor, we gather its sampling information (rate, interval, units) and create a // channel transform (an abstract channel used by transforms) from it. We then add the actual component's channel // as an input channel, and the channel transform as an output. // Finally, we map the channel counter and the output channel. This mapping is what determines the channel order in // the CollectionDataReady callback function. for (int k = 0; k < BTPipeline.TrignoBtManager.Components[i].BtChannels.Count; k++) { var chin = BTPipeline.TrignoBtManager.Components[i].BtChannels[k]; var chout = new ChannelTransform(chin.FrameInterval, chin.SamplesPerFrame, BTPipeline.TrignoBtManager.Components[i].BtChannels[k].Unit); TransformManager.AddInputChannel(rawDataTransform, chin); TransformManager.AddOutputChannel(rawDataTransform, chout); // now reroute the raw transform's data into the fibonacci transform var fibChin = chout; var fibChout = new ChannelTransform(fibChin.FrameInterval, fibChin.SamplesPerFrame, Units.VOLTS); TransformManager.AddInputChannel(fibonacciTransform, fibChin); TransformManager.AddOutputChannel(fibonacciTransform, fibChout); outconfig.MapOutputChannel(channelIndex, fibChout); channelIndex++; } } } } return(outconfig); }
internal static bool PerformObjectDropInAction(Object __instance, Item dropInItem, bool probe, Farmer who, ref bool __result) { if (__instance.isTemporarilyInvisible || !(dropInItem is Object)) { return(false); } Object input = (Object)dropInItem; if (ProducerController.GetProducerItem(__instance.name, input) is ProducerRule producerRule) { if (__instance.heldObject.Value != null && !__instance.name.Equals("Crystalarium") || (bool)((NetFieldBase <bool, NetBool>)input.bigCraftable)) { return(true); } if (ProducerRuleController.IsInputExcluded(producerRule, input)) { return(true); } if ((bool)((NetFieldBase <bool, NetBool>)__instance.bigCraftable) && !probe && (__instance.heldObject.Value == null)) { __instance.scale.X = 5f; } bool shouldDisplayMessages = !probe && who.IsLocalPlayer; if (ProducerRuleController.IsInputStackLessThanRequired(producerRule, input, shouldDisplayMessages)) { return(false); } if (ProducerRuleController.IsAnyFuelStackLessThanRequired(producerRule, who, shouldDisplayMessages)) { return(false); } Vector2 tileLocation = __instance.tileLocation.Value; Random random = ProducerRuleController.GetRandomForProducing(tileLocation); OutputConfig outputConfig = OutputConfigController.ChooseOutput(producerRule.OutputConfigs, random); Object output = OutputConfigController.CreateOutput(outputConfig, input, random); __instance.heldObject.Value = output; if (!probe) { OutputConfigController.LoadOutputName(outputConfig, __instance.heldObject.Value, input, who); GameLocation currentLocation = who.currentLocation; PlaySound(producerRule.Sounds, currentLocation); PlayDelayedSound(producerRule.DelayedSounds, currentLocation); __instance.minutesUntilReady.Value = producerRule.MinutesUntilReady; if (ProducerController.GetProducerConfig(__instance.Name) is ProducerConfig producerConfig) { __instance.showNextIndex.Value = producerConfig.AlternateFrameProducing; } if (producerRule.PlacingAnimation.HasValue) { AnimationController.DisplayAnimation(producerRule.PlacingAnimation.Value, producerRule.PlacingAnimationColor, currentLocation, tileLocation, new Vector2(producerRule.PlacingAnimationOffsetX, producerRule.PlacingAnimationOffsetY)); } __instance.initializeLightSource(tileLocation, false); foreach (var fuel in producerRule.FuelList) { RemoveItemsFromInventory(who, fuel.Item1, fuel.Item2); } producerRule.IncrementStatsOnInput.ForEach(s => StatsController.IncrementStardewStats(s, producerRule.InputStack)); input.Stack -= producerRule.InputStack; __result = input.Stack <= 0; } else { __result = true; } return(false); } return(true); }