summaryrefslogtreecommitdiff
path: root/NET/worlds/console/SnapTool.java
blob: 0a6af6b9ddba89e64e51cbc6b939d3c3da5f800f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package NET.worlds.console;

import NET.worlds.core.IniFile;
import NET.worlds.scape.Point2;
import NET.worlds.scape.Point3Temp;

public class SnapTool {
   private static SnapTool theSnapTool = null;
   private int snapX = 1;
   private int snapY = 1;
   private int snapZ = 1;
   private boolean useSnap = false;

   public static SnapTool snapTool() {
      if (theSnapTool == null) {
         theSnapTool = new SnapTool();
      }

      return theSnapTool;
   }

   private SnapTool() {
      this.snapX = IniFile.gamma().getIniInt("Shaper.snapX", 100);
      this.snapY = IniFile.gamma().getIniInt("Shaper.snapY", 100);
      this.snapZ = IniFile.gamma().getIniInt("Shaper.snapZ", 1);
      this.useSnap = IniFile.gamma().getIniInt("Shaper.useSnapTool", 0) != 0;
   }

   public Point3Temp snapTo(Point3Temp inVal) {
      if (!this.useSnap) {
         return inVal;
      } else {
         float newX = this.snapTo(inVal.x, this.snapX);
         float newY = this.snapTo(inVal.y, this.snapY);
         float newZ = this.snapTo(inVal.z, this.snapZ);
         return Point3Temp.make(newX, newY, newZ);
      }
   }

   public Point2 snapTo(Point2 inVal) {
      if (!this.useSnap) {
         return inVal;
      } else {
         float newX = this.snapTo(inVal.x, this.snapX);
         float newY = this.snapTo(inVal.y, this.snapY);
         return new Point2(newX, newY);
      }
   }

   public float snapTo(float oldVal, int snapIncrement) {
      if (!this.useSnap) {
         return oldVal;
      } else {
         int multiple = Math.round(oldVal / snapIncrement);
         return multiple * snapIncrement;
      }
   }

   public int getSnapX() {
      return this.snapX;
   }

   public void setSnapX(int newVal) {
      if (newVal > 0) {
         this.snapX = newVal;
         IniFile.gamma().setIniInt("Shaper.snapX", newVal);
      }
   }

   public int getSnapY() {
      return this.snapY;
   }

   public void setSnapY(int newVal) {
      if (newVal > 0) {
         this.snapY = newVal;
         IniFile.gamma().setIniInt("Shaper.snapY", newVal);
      }
   }

   public int getSnapZ() {
      return this.snapZ;
   }

   public void setSnapZ(int newVal) {
      if (newVal > 0) {
         this.snapZ = newVal;
         IniFile.gamma().setIniInt("Shaper.snapZ", newVal);
      }
   }

   public boolean useSnap() {
      return this.useSnap;
   }

   public void setSnap(boolean use) {
      this.useSnap = use;
      IniFile.gamma().setIniInt("Shaper.useSnapTool", use ? 1 : 0);
   }

   public void print() {
      System.out.println("SnapTool " + (this.useSnap ? "ON" : "OFF"));
      System.out.println("SnapTool Settings: X=" + this.snapX + " Y=" + this.snapY + " Z=" + this.snapZ);
   }

   public void test() {
      this.setSnapX(150);
      this.setSnapY(200);
      this.setSnapY(-100);
      this.setSnapY(0);
      this.setSnapZ(5);
      this.print();
   }
}