• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Adjustor mod plugin for VS


Commit MetaInfo

Revisionb07f611646d72b52d8c2ab2c03f3b0df55f4c3f6 (tree)
Zeit2019-06-01 07:39:50
Autormelchior <melchior@user...>
Commitermelchior

Log Message

Fixed up Rotations from Variants
Tool mode text entries added

Ändern Zusammenfassung

Diff

--- a/AdjustorMod/ItemAdjustor.cs
+++ b/AdjustorMod/ItemAdjustor.cs
@@ -4,7 +4,7 @@ using System.Collections;
44 using System.Collections.Generic;
55 using System.Collections.ObjectModel;
66 using System.Linq;
7-//using System.Text.RegularExpressions;
7+using System.Text.RegularExpressions;
88
99 using Vintagestory.API.Common;
1010 using Vintagestory.API.Datastructures;
@@ -60,6 +60,19 @@ namespace Adjustor
6060 @"GenericTypedContainer",
6161 };
6262
63+ private static string[] _verticalVariantKeys = new string[]
64+ {
65+ "verticalorientation",
66+ "rot",
67+ };
68+
69+ private static string[] _horizontalVariantKeys = new string[]
70+ {
71+ "horizontalorientation",
72+ "rot",
73+ "side"
74+ };
75+
6376 public ItemAdjustor( ) : base( )
6477 {
6578
@@ -96,15 +109,7 @@ namespace Adjustor
96109 /// <param name="entitySel">Entity sel.</param>
97110 /// <param name="handHandling">Hand handling.</param>
98111 public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
99- {
100- /*
101- if ( entitySel != null ) {
102- #if DEBUG
103- ClientApi.ShowChatMessage( string.Format("Got an Entity Selection: {0} - {1}", entitySel.Entity.Code.ToShortString(), entitySel.Face.Code ) );
104- #endif
105- }
106- */
107-
112+ {
108113 if (blockSel == null) {
109114 return;
110115 }
@@ -153,7 +158,7 @@ namespace Adjustor
153158 BlockPos position = blockSel.Position;
154159 Block thatBlock = byEntity.World.BlockAccessor.GetBlock(position);
155160 IPlayer thePlayer = null;
156- bool rotateHorizontal = false;
161+
157162
158163 if (byEntity is EntityPlayer) {
159164 thePlayer = ServerApi.World.PlayerByUid((( EntityPlayer )byEntity).PlayerUID);
@@ -170,88 +175,12 @@ namespace Adjustor
170175 return false;
171176 }
172177
173- AssetLocation renamedAsset = null;
174-
175- switch (blockSel.Face.Axis) {
176- case EnumAxis.X:
177- case EnumAxis.Z:
178- rotateHorizontal = !byEntity.Controls.Sneak;
179- break;
180-
181- case EnumAxis.Y:
182- rotateHorizontal = byEntity.Controls.Sneak;
183- break;
184- }
185-
186- if (rotateHorizontal) {
187-#if DEBUG
188- ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup, "Angle N/E/W/S.", EnumChatType.Notification);
189-#endif
190-
191- //So many HORIZONTAL Special Cases...
192- renamedAsset = thatBlock.GetRotatedBlockCode(90);//Except Fences
193-
194- if (IsSlabUD(thatBlock)) renamedAsset = SpecialSlabHorizontalFlipCase(thatBlock);
195-
196- if (IsWoodLog(thatBlock)) renamedAsset = WoodOmniFlip(thatBlock, blockSel.Face.Axis, rotateHorizontal); //Wood logs also special
197-
198-
199- if (renamedAsset != thatBlock.Code) {
200-#if DEBUG
201- Logger.VerboseDebug("{0} Becomes {1}", thatBlock.Code, renamedAsset);
202-#endif
203-
204- var rotatedBlock = ServerApi.World.GetBlock(renamedAsset);
205- if (rotatedBlock != null) {
206- ServerApi.World.BlockAccessor.ExchangeBlock(rotatedBlock.BlockId, position);
207- } else {
208- Logger.VerboseDebug("{0} CAN'T EXCHANGE {1}", thatBlock.Code, renamedAsset);
209- }
210- }
178+ if (this.CurrentRotationMode(slot) == RotationModes.Free) {
179+ FreeRotation(blockSel, byEntity, thePlayer, thatBlock, position);
211180 } else {
212-#if DEBUG
213- ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup, "Angle U/D.", EnumChatType.Notification);
214-#endif
215-
216- renamedAsset = thatBlock.GetVerticallyFlippedBlockCode( );
217-
218- //Special Case for Slabs in N/E/S/W mode when trying to rotate them back 'up'
219- if (IsSlabNEWS(thatBlock)) renamedAsset = SpecialSlabVerticalFlipCase(thatBlock);
220-
221- if (IsWoodLog(thatBlock)) renamedAsset = WoodOmniFlip(thatBlock, blockSel.Face.Axis, rotateHorizontal); //Wood logs also special
222-
223- if (renamedAsset != thatBlock.Code) {
224-
225-#if DEBUG
226- Logger.VerboseDebug("{0} Becomes {1}", thatBlock.Code, renamedAsset);
227-#endif
228-
229- var rotatedBlock = ServerApi.World.GetBlock(renamedAsset);
230- if (rotatedBlock != null) {
231- ServerApi.World.BlockAccessor.ExchangeBlock(rotatedBlock.BlockId, position);
232- } else {
233- Logger.VerboseDebug("{0} CAN'T EXCHANGE {1}", thatBlock.Code, renamedAsset);
234- }
235- }
181+ FixedRotation(this.CurrentRotationMode(slot),blockSel, byEntity, thePlayer, thatBlock, position);
236182 }
237183
238- //System.Diagnostics.Debugger.Break( );
239-#if SPAM
240- string firstName = thatBlock.Code.Path.Split( "-".ToCharArray( ) ).First( );
241-
242- var variants = ServerApi.WorldManager.SearchBlockTypes(firstName, thatBlock.Code.Domain );
243-
244- if ( variants != null && variants.Length > 0 ) {
245-
246- ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup, string.Format( "Block has {0} variants;", variants.Length ), EnumChatType.Notification );
247-
248- foreach(var variant in variants) {
249- ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup,variant.Code.ToShortString(), EnumChatType.Notification );
250- Logger.VerboseDebug("{0} has Variant: {1}", firstName, variant.Code );
251- }
252- }
253-#endif
254- //secondsUsed += 0.5;
255184
256185 DamageItem(ServerApi.World, byEntity, slot);
257186
@@ -304,31 +233,31 @@ namespace Adjustor
304233
305234 switch (rotateMode) {
306235 case RotationModes.Free:
307- DrawTextGlyph(cr, x, y, width, height, color, "FREE");
236+ DrawTextGlyph(cr, x, y, width, height, color, Lang.GetMatching("adjustor:rotation-free").ToUpperInvariant( ));
308237 break;
309238
310239 case RotationModes.Up:
311- DrawTextGlyph(cr, x, y, width, height, color, "UP");
240+ DrawTextGlyph(cr, x, y, width, height, color, Lang.GetMatching("adjustor:rotation-up").ToUpperInvariant( ));
312241 break;
313242
314243 case RotationModes.Down:
315- DrawTextGlyph(cr, x, y, width, height, color, "DOWN");
244+ DrawTextGlyph(cr, x, y, width, height, color, Lang.GetMatching("adjustor:rotation-down").ToUpperInvariant( ));
316245 break;
317246
318247 case RotationModes.North:
319- DrawTextGlyph(cr, x, y, width, height, color, "NORTH");
248+ DrawTextGlyph(cr, x, y, width, height, color, Lang.GetMatching("facing-north" ).ToUpperInvariant() );
320249 break;
321250
322251 case RotationModes.East:
323- DrawTextGlyph(cr, x, y, width, height, color, "EAST");
252+ DrawTextGlyph(cr, x, y, width, height, color, Lang.GetMatching("facing-east").ToUpperInvariant( ) );
324253 break;
325254
326255 case RotationModes.West:
327- DrawTextGlyph(cr, x, y, width, height, color, "WEST");
256+ DrawTextGlyph(cr, x, y, width, height, color,Lang.GetMatching("facing-west").ToUpperInvariant( ) );
328257 break;
329258
330259 case RotationModes.South:
331- DrawTextGlyph(cr, x, y, width, height, color, "SOUTH");
260+ DrawTextGlyph(cr, x, y, width, height, color, Lang.GetMatching("facing-south").ToUpperInvariant( ) );
332261 break;
333262
334263 default:
@@ -558,6 +487,174 @@ namespace Adjustor
558487 return thatBlock.Code.FirstPathPart(0).StartsWith(@"log", StringComparison.Ordinal);
559488 }
560489
490+
491+
492+
493+ /// <summary>
494+ /// Rotation by any 'free' axis available to block
495+ /// </summary>
496+ /// <param name="blockSel">Block sel.</param>
497+ /// <param name="byEntity">By entity.</param>
498+ /// <param name="thePlayer">The player.</param>
499+ private void FreeRotation(BlockSelection blockSel, EntityAgent byEntity, IPlayer thePlayer, Block thatBlock, BlockPos position)
500+ {
501+ bool rotateHorizontal = false;
502+ AssetLocation renamedAsset = null;
503+
504+ switch (blockSel.Face.Axis) {
505+ case EnumAxis.X:
506+ case EnumAxis.Z:
507+ rotateHorizontal = !byEntity.Controls.Sneak;
508+ break;
509+
510+ case EnumAxis.Y:
511+ rotateHorizontal = byEntity.Controls.Sneak;
512+ break;
513+ }
514+
515+ if (rotateHorizontal) {
516+#if DEBUG
517+ ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup, "Angle N/E/W/S.", EnumChatType.Notification);
518+#endif
519+
520+ //So many HORIZONTAL Special Cases...
521+ renamedAsset = thatBlock.GetRotatedBlockCode(90);//Except Fences
522+
523+ if (IsSlabUD(thatBlock)) renamedAsset = SpecialSlabHorizontalFlipCase(thatBlock);
524+
525+ if (IsWoodLog(thatBlock)) renamedAsset = WoodOmniFlip(thatBlock, blockSel.Face.Axis, rotateHorizontal); //Wood logs also special
526+
527+
528+ if (renamedAsset != thatBlock.Code) {
529+#if DEBUG
530+ Logger.VerboseDebug("{0} Becomes {1}", thatBlock.Code, renamedAsset);
531+#endif
532+
533+ var rotatedBlock = ServerApi.World.GetBlock(renamedAsset);
534+ if (rotatedBlock != null) {
535+ ServerApi.World.BlockAccessor.ExchangeBlock(rotatedBlock.BlockId, position);
536+ } else {
537+ Logger.VerboseDebug("{0} CAN'T EXCHANGE {1}", thatBlock.Code, renamedAsset);
538+ }
539+ }
540+ } else {
541+#if DEBUG
542+ ServerApi.SendMessage(thePlayer, GlobalConstants.CurrentChatGroup, "Angle U/D.", EnumChatType.Notification);
543+#endif
544+
545+ renamedAsset = thatBlock.GetVerticallyFlippedBlockCode( );
546+
547+ //Special Case for Slabs in N/E/S/W mode when trying to rotate them back 'up'
548+ if (IsSlabNEWS(thatBlock)) renamedAsset = SpecialSlabVerticalFlipCase(thatBlock);
549+
550+ if (IsWoodLog(thatBlock)) renamedAsset = WoodOmniFlip(thatBlock, blockSel.Face.Axis, rotateHorizontal); //Wood logs also special
551+
552+ if (renamedAsset != thatBlock.Code) {
553+
554+#if DEBUG
555+ Logger.VerboseDebug("{0} Becomes {1}", thatBlock.Code, renamedAsset);
556+#endif
557+
558+ var rotatedBlock = ServerApi.World.GetBlock(renamedAsset);
559+ if (rotatedBlock != null) {
560+ ServerApi.World.BlockAccessor.ExchangeBlock(rotatedBlock.BlockId, position);
561+ } else {
562+ Logger.VerboseDebug("{0} CAN'T EXCHANGE {1}", thatBlock.Code, renamedAsset);
563+ }
564+ }
565+ }
566+
567+
568+ }
569+
570+ /// <summary>
571+ /// Fixed by type - force to that rotation; 'state'
572+ /// </summary>
573+ /// <param name="rotationModes">Rotation modes.</param>
574+ /// <param name="blockSel">Block sel.</param>
575+ /// <param name="byEntity">By entity.</param>
576+ /// <param name="thePlayer">The player.</param>
577+ /// <param name="thatBlock">That block.</param>
578+ /// <param name="position">Position.</param>
579+ private void FixedRotation(RotationModes rotationMode, BlockSelection blockSel, EntityAgent byEntity, IPlayer thePlayer, Block thatBlock, BlockPos position)
580+ {
581+ AssetLocation renamedAsset = RenameBlockFace(thatBlock, rotationMode);
582+
583+ if (renamedAsset != null) {
584+
585+ if (renamedAsset.Equals(thatBlock.Code) == false) {
586+ #if DEBUG
587+ Logger.VerboseDebug("{0} Forcing: {1}", thatBlock.Code, renamedAsset);
588+ #endif
589+
590+ var rotatedBlock = ServerApi.World.GetBlock(renamedAsset);
591+ if (rotatedBlock != null) {
592+ ServerApi.World.BlockAccessor.ExchangeBlock(rotatedBlock.BlockId, position);
593+ } else {
594+ Logger.VerboseDebug("{0} CAN'T EXCHANGE {1}", thatBlock.Code, renamedAsset);
595+ }
596+ } else {
597+ Logger.VerboseDebug("{0} IDENTICAL!? {1}", thatBlock.Code, renamedAsset);
598+ }
599+ }
600+ }
601+
602+ private AssetLocation RenameBlockFace(Block thatBlock, RotationModes rotationMode)
603+ {
604+ string renamedLocationPath = null;
605+ string rotationKey = null;
606+
607+ switch (rotationMode) {
608+
609+ case RotationModes.Up:
610+ case RotationModes.Down:
611+
612+ rotationKey = thatBlock.Variant.Keys.FirstOrDefault(_verticalVariantKeys.Contains);//There better be only 1 axies here!
613+ if (!string.IsNullOrEmpty(rotationKey))
614+ {
615+ string roatableValue = thatBlock.Variant[rotationKey];
616+
617+ renamedLocationPath = thatBlock.Code.Path.Replace(roatableValue, rotationMode.ToString().ToLowerInvariant() );
618+
619+ #if DEBUG
620+ Logger.VerboseDebug("Variant vertical rotation {0}={1} to: {2}", rotationKey, roatableValue, renamedLocationPath);
621+ #endif
622+
623+ }
624+
625+ break;
626+
627+ case RotationModes.North:
628+ case RotationModes.East:
629+ case RotationModes.West:
630+ case RotationModes.South:
631+
632+ rotationKey = thatBlock.Variant.Keys.FirstOrDefault(_horizontalVariantKeys.Contains);//There better be only 1 axies here!
633+ if (!string.IsNullOrEmpty(rotationKey)) {
634+ string roatableValue = thatBlock.Variant[rotationKey];
635+
636+ renamedLocationPath = thatBlock.Code.Path.Replace(roatableValue, rotationMode.ToString( ).ToLowerInvariant( ));
637+
638+ #if DEBUG
639+ Logger.VerboseDebug("Variant horizontal rotation {0}={1} to: {2}", rotationKey, roatableValue, renamedLocationPath);
640+ #endif
641+
642+ }
643+ break;
644+
645+ default:
646+ throw new InvalidOperationException("Rotation Mode not Permissible!" );
647+ }
648+
649+
650+ if (!string.IsNullOrEmpty(renamedLocationPath)) {
651+
652+ return new AssetLocation(thatBlock.Code.Domain, renamedLocationPath);
653+ }
654+
655+ return null;
656+ }
657+
561658 #endregion
562659
563660 #region SVG TOOL ICONS
@@ -575,27 +672,29 @@ namespace Adjustor
575672 Matrix matrix = cr.Matrix;
576673
577674 cr.Save( );
675+ /*
578676 float local_width = 220;
579677 float local_height = 182;
580678 float scale = Math.Min(width / local_width, height / local_height);
581679 matrix.Translate(x + Math.Max(0, (width - local_width * scale) / 2), y + Math.Max(0, (height - local_height * scale) / 2));
582680 matrix.Scale(scale, scale);
583681 cr.Matrix = matrix;
682+ */
584683
585684 cr.Operator = Operator.Over;
586685 pattern = new SolidPattern(ToCarioColor(color));
587686 cr.SetSource(pattern);
588687
589688 cr.NewPath( );
590- cr.MoveTo(32, 16);
689+ //cr.MoveTo(0, 16);
591690 cr.Tolerance = 0.1;
592691 cr.Antialias = Antialias.Default;
593692 cr.FillRule = FillRule.Winding;
594693
595- stampy.DrawTextLine(cr, CairoFont.WhiteMediumText( ).WithFontSize(96), text, 32D, 16);
596- cr.LineWidth = 3D;
597- cr.MoveTo(64, 16);
598- cr.RelLineTo(0D, 248D);
694+ stampy.DrawTextLine(cr, CairoFont.WhiteMediumText( ).WithFontSize(96F).WithWeight(FontWeight.Bold), text, 8D, 16D);
695+ //cr.LineWidth = 3D;
696+ //cr.MoveTo(64, 16);
697+ //cr.RelLineTo(0D, 248D);
599698
600699 cr.FillPreserve( );
601700 }
--- a/AdjustorMod/assets/Adjustor/lang/en.json
+++ b/AdjustorMod/assets/Adjustor/lang/en.json
@@ -9,4 +9,8 @@
99 "adjustor:item-adjustmenttool_crude": "Crude Adjustment Tool",
1010 "adjustor:itemdesc-adjustmenttool-*": "Manipulate adjustable block types, without breaking them.",
1111 "adjustor:itemdesc-adjustmenttool_crude": "Crudely manipulate adjustable block types, without breaking them.",
12+ "adjustor:rotation-up":"UP",
13+ "adjustor:rotation-down":"DOWN",
14+ "adjustor:rotation-free":"FREE",
15+ "adjustor:rotation-fixed":"FIXED",
1216 }