You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a directory for your project, something like `countPortals`, and move into it.
3
+
Start by creating a new project directory (for example, `countPortals`) and navigate into it.
4
4
5
5
## Install the Plugin Kit
6
6
7
-
open a terminal window and run:
7
+
Open a terminal and run:
8
8
9
9
```yarn add iitcpluginkit```
10
10
11
-
This will install all required software (inside a `node_modules` directory) and might take a little bit.
12
-
You can ignore the warnings about deprecated dependencies.
13
-
If you got an error it's most likely about an incompatible node version.
11
+
This installs all required dependencies into a `node_modules` directory and may take a few moments. Deprecated dependency warnings can be safely ignored. If you encounter errors, check that your Node.js version is compatible.
14
12
15
13
## Create the initial layout
16
14
17
-
- let IITCPluginKit create a default plugin layout for you:
18
-
`yarn ipk`
15
+
Generate a default plugin structure:
19
16
20
-
- Enter `CountPortals` (case-sensitive!) for the plugin name and leave the rest default.
17
+
```
18
+
yarn ipk
19
+
```
20
+
21
+
When prompted, enter `CountPortals` (case-sensitive) as the plugin name and use the default settings for all other options.
21
22
22
23
## Add some code
23
24
24
-
- Open `/src/Main.ts` and replace the _**// FILL ME**_ with `alert("Hello World");`
25
+
1. Open `/src/Main.ts` and replace the `// FILL ME` comment with `alert("Hello World");`
25
26
26
-
- save and run:
27
-
`yarn autobuild`
27
+
2. Save the file and run:
28
28
29
-
This will start building your code everytime you save your changes. Additionally, it provides a small fileserver to ease installation.
30
-
Wait a little moment until you see the compilation is finished.
31
-
Something like:
29
+
```
30
+
yarn autobuild
31
+
```
32
+
33
+
This command automatically rebuilds your code whenever you make changes and provides a local file server for easy installation. Wait for the build to complete—you'll see output like this:
32
34
33
35
```shell
34
36
[0] Built at: 2020-07-11 22:35:01
@@ -38,21 +40,25 @@ Something like:
38
40
39
41
## Installation
40
42
41
-
- Open [http://localhost:8100](http://localhost:8100)and install your freshly created Plugin.
43
+
1. Navigate to [http://localhost:8100](http://localhost:8100)in your browser to install your new plugin.
42
44
43
45

44
46
45
-
- Open or reload your iitc browser window.
46
-
47
-
You should see the good old "Hello World" message.
47
+
2. Open or refresh your IITC window.
48
48
49
-
Congratulation for your first IITC-Plugin! :tada:
49
+
You should now see the "Hello World" alert message. Congratulations on creating your first IITC plugin! 🎉
50
50
51
51
## Updating
52
-
You won't need that now but sooner or later you'll need to update the IITCPluginKit.
53
-
`yarn outdated` will show you if you're still up to date
54
-
`yarn upgrade` will do all minor version upgrades
55
52
56
-
Sometimes the upgrade may break your code (like renamed function,...).
57
-
Run `yarn add iitcpluginkit` to do the bigger step and see if your code still compiles well.
58
-
Maybe you should look at the [changelog](https://github.com/McBen/IITCPluginKit/blob/master/changelog.txt)
53
+
Eventually, someday, you may need to update IITCPluginKit:
54
+
55
+
-`yarn outdated` — Check for available updates
56
+
-`yarn upgrade` — Apply minor version updates
57
+
58
+
Major updates may require code changes. For these, run:
59
+
60
+
```
61
+
yarn add iitcpluginkit
62
+
```
63
+
64
+
Then verify your code compiles. Check the [changelog](https://github.com/McBen/IITCPluginKit/blob/master/changelog.txt) for details on breaking changes.
Copy file name to clipboardExpand all lines: docs/2-starting-buttons.md
+17-19Lines changed: 17 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,8 @@ Expect the unexpected: the function `init()` is called on startup.
4
4
So put there all the stuff you want to run on start.
5
5
6
6
## Toolbutton
7
-
Having the alert text popping up on every start is really annoying. Let's hide it behind a toolbox button - a link below the portal-detail view. Where most plugins will add a link:
7
+
8
+
Showing the alert on every startup is annoying. Instead, let's hide it behind a toolbox button—a link below the portal detail view:
8
9
9
10
:::code-group
10
11
```typescript {7-12,15-17} [src/Main.ts]
@@ -29,19 +30,19 @@ class CountPortals implements Plugin.Class {
29
30
```
30
31
:::
31
32
32
-
The `$`is JQuery. JQuery is a good old google framework helping us doing html stuff. Modern developers will tell you not to use it. And yes, they are right and wrong. Anyway, it's already included in IITC so let's make use of it to ease HTML creations.
33
+
The `$`symbol represents jQuery, a popular library for HTML manipulation. While modern developers often prefer alternatives, jQuery is already included in IITC, so we use it here to simplify HTML creation.
33
34
34
-
Here we create an `<a>` tag and add a "click" handler. This will call our new function which will hold our old `alert`.
35
+
This code creates an `<a>` tag with a click handler that calls our new `doCount()` function.
35
36
36
37

37
38
38
39
## Toolbar Button
39
-
Some people prefer a quick access button on the left side of the map. Please think twice before adding it. Only use it for stuff that a user will use daily.
40
-
But hey, this is a tutorial: let's do it
41
40
42
-
- First we need an icon. Download and place it in your /src/ directory -> ...
43
-
Here we use SVG because it's simple and small, but you're free to use any web-format you like.
44
-
- Import it at the top of your Main.ts:
41
+
Some users prefer a quick access button on the left side of the map. Use this sparingly—only for features that users will access daily. For this tutorial, let's add one:
42
+
43
+
1. First, create an icon. Download an icon and place it in your `/src/` directory. We'll use SVG for simplicity and small file size, but any web format works.
44
+
45
+
2. Import it at the top of `Main.ts`:
45
46
46
47
```typescript {3}
47
48
import*asPluginfrom"iitcpluginkit";
@@ -53,7 +54,7 @@ class CountPortals implements Plugin.Class {
53
54
}
54
55
```
55
56
56
-
- Then create the toolbar button.
57
+
3. Then create the toolbar button:
57
58
58
59
```typescript {14-24}
59
60
classCountPortalsimplementsPlugin.Class {
@@ -84,14 +85,13 @@ class CountPortals implements Plugin.Class {
84
85
}
85
86
```
86
87
87
-
We created a `<div>` for a new toolbar group and a `<a>` for a button with the image.
88
-
Finally attached them to the global map container.
88
+
This code creates a toolbar group `<div>` and a button `<a>` with your icon, then attaches them to the map container.
89
89
90
-
Make sure your "autobuild" command is still running. Open _**localhost:8100**_, update your script and reload iitc.
91
-
As you see you'll need these often. It's a good thing to keep localhost and iitc open in different tabs.
90
+
Ensure your "autobuild" command is still running. Navigate to [http://localhost:8100](http://localhost:8100), update your script, and reload IITC. It's helpful to keep localhost and IITC open in separate tabs.
92
91
93
92
## CSS
94
-
Let's keep our code clean and move the styles into another file. We already have one which is still empty: `styles.css`
93
+
94
+
Let's keep our code clean by moving styles into the CSS file. You already have `styles.css`—let's use it:
You will see an error message in your terminal window because the icon import is no longer required in `Main.ts`.
118
-
So remove this import line.
117
+
You'll see an error message in your terminal because the icon import is no longer needed in `Main.ts`. Remove this import line:
119
118
120
119
:::code-group
121
120
```typescript [Main.ts]
@@ -131,7 +130,7 @@ class CountPortals implements Plugin.Class {
131
130
132
131
## Refactoring
133
132
134
-
Last but not least let's do a little cleanup and move our stuff to an extra function to keep the `init()` function easy to read:
133
+
Let's clean up the code and move button creation to a separate function to keep `init()` easy to read:
135
134
136
135
:::code-group
137
136
```typescript {7,10-28} [Main.ts]
@@ -167,5 +166,4 @@ class CountPortals implements Plugin.Class {
167
166
```
168
167
:::
169
168
170
-
The `private` will let the compiler know no one else will use this function. You can mark most of your functions private.
171
-
It won't help in final javascript but will help you track down obsolete functions.
169
+
The `private` keyword tells the compiler that this function is only used internally. Mark most of your functions as `private`—it won't affect the final JavaScript but helps identify unused code.
window.portals is the object IITC stores all portals. IITC.Portal is a helper type defintion IITCPluginKit provides you.
42
-
Maybe you want to take a look at all type definitions resikit included? see: ./node_modules/iitcpluginkit/src/types/iitc
43
-
It's still incomplete but should cover most function and types you need for a plugin.
44
-
".distanceTo" is a Leaflet function and will calculate the distance between points in meters.
39
+
`window.portals` is where IITC stores all portal data. `IITC.Portal` is a type definition provided by IITCPluginKit. If you like you can explore all available type definitions in `./node_modules/iitcpluginkit/src/types/iitc` or most IDEs will give you a tooltip hint.
40
+
The `.distanceTo()` method is a Leaflet function that calculates the distance between points in meters.
45
41
46
-
Another step deeper: Loop through all drawed polylines.
42
+
Going deeper, we loop through all drawn polylines:
"drawnItems" is the layer DrawTools puts all it's stuff. The `<L.LayerGroup<any>>` tells Typescript what type it is.
77
-
It's not only removing a warning. It's also helps with code completion.
78
-
Long story short: We loop through all drawn items. Pick every item which is a GeodesicPolyline. Get all positions of the line.
79
-
Then loop through the positions to find the nearest point on the line to the portal position
72
+
`drawnItems` is the layer where DrawTools stores all its content. The `<L.LayerGroup<any>>` syntax tells TypeScript the variable's type, which helps with code completion and eliminates warnings.
80
73
81
-
And finally some math stuff:
74
+
In summary: we iterate through all drawn items, find those that are GeodesicPolylines, get their positions, and find the nearest point on each line to our portal position.
To make things easy we assume that these geolines are straight lines. This is not correct and may lead to some error for long polylines.
107
-
But it saves a bunch of calculation stuff and most people won't hardly ever recognize it.
108
-
"closedPoint" calculates the point on the line a to b which is closest to x.
109
-
"distance2" returns the squared 2d-distance between two points.
101
+
For simplicity, we treat these (Geodesic) Curved lines as straight lines. This isn't technically correct and may introduce small errors for very long polylines, but it saves computation and is imperceptible to most users.
102
+
103
+
`closedPoint()` calculates the closest point on line segment a-b to point x. `distance2()` returns the squared 2D distance between two points.
110
104
111
-
One last thing: lets replace the constant "40" in findHackablePortals with a more descripting word.
105
+
Finally, let's replace the hard-coded value `40` in `findHackablePortals()` with a named constant:
112
106
113
107
```typescript
114
108
if (closestPoint&&position.distanceTo(closestPoint) <=HACK_RANGE)
Copy file name to clipboardExpand all lines: docs/4-the-dialog.md
+20-23Lines changed: 20 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# 4. The Dialog
2
2
3
-
A simple `alert` dialog is fine for a quick message. If we want to provide better user experience we should use a better approach: a real dialog
3
+
A simple `alert()` dialog works for quick messages, but a proper dialog provides a better user experience:
4
4
5
5
```typescript {10-29}
6
6
doCount(): void {
@@ -35,18 +35,19 @@ doCount(): void {
35
35
}
36
36
```
37
37
38
-
We created a table with more details of the found portals.
38
+
We've created a table displaying detailed information about the found portals.
39
39
40
-
### Portal-Data - side story
41
-
Many plugins use portal data, and so we should take a deeper look.
40
+
### Portal Data—A Closer Look
42
41
43
-
All portals are stored in the window.portals object with the GUID as key. It includes all visible portals plus some outside of your view.
42
+
Since many plugins work with portal data, it's worth understanding the structure in detail.
44
43
45
-
These portal uses the IITC.Portals format. In fact these are Leaflet markers with more data stored in `options`. And to increase confusions this has another sub-structure `data` which hold more detail information about the portal.
44
+
All portals are stored in the `window.portals` object, keyed by GUID. This includes visible portals plus some outside your current view.
46
45
47
-
There is even another data-structure `ent` but this one we shouldn't touch. IITC has already processed this raw-data.
46
+
These portals use the `IITC.Portal` format, which are Leaflet markers with additional data stored in `options`. There's also a nested `data` structure containing more detailed information.
48
47
49
-
Without the leaflet stuff:
48
+
There is another data structure called `ent`, but it should not be modified—IITC has already processed this raw data.
49
+
50
+
Simplified structure:
50
51
```typescript
51
52
interfaceIITC.Portal {
52
53
options: {
@@ -74,20 +75,18 @@ Without the leaflet stuff:
74
75
}
75
76
```
76
77
77
-
This is the data you'll get for all portals on the map. Portal-Detail data are handled separately.
78
+
This is the data structure for all portals on the map. Portal-Detail data is handled separately.
78
79
79
-
Be aware that Portals in 'Link-Zoom' have no data. They not even exists. IITC creates dummy-portals at the end of links. They only contain Position, GUID and Faction. So before processing check if data is available - like check if name is present.
80
+
Be aware that portals in 'Link-Zoom' are dummy portals created by IITC at link endpoints. They contain only position, GUID, and faction information. Always check if data is available (e.g., verify the name exists) before processing portal details.
80
81
81
82
82
-
### Back to our dialog
83
-
First we count portals by each faction (portal.options.team). Then count these by level 8 to 1 (portal.options.data.level).
83
+
### Back to Our Dialog
84
84
85
-
All the <> stuff is for creating a html-table stored as HTML-String in `contents`.
85
+
We count portals by faction using `portal.options.team`, then count them by level (8 to 1) using `portal.options.data.level`.
86
86
87
-
At last, we have to create the dialog by using IITC dialog helper. It's a IITC-wrapper for JQuery Dialogs.
88
-
This is the function you'll use a lot for your dialogs.
87
+
The HTML string in `contents` builds a table. Finally, we create the dialog using IITC's dialog helper, which wraps jQuery dialogs. This is a function you'll use frequently for dialogs.
89
88
90
-
Because we gave it an ID IITC will make sure that only one of our dialog is open at the same time.
89
+
By providing an ID, IITC ensures only one instance of our dialog is open at a time.
91
90
92
91
The table itself looks really boring. Let's add some CSS styling:
93
92
@@ -131,13 +130,11 @@ contents += "</table>"
131
130
```
132
131
:::
133
132
134
-
The CSS file we use here is processed by [postCSS](https://postcss.org/). This allows us to add some more elegant handling in our CSS like nested rules.
135
-
VS-code won't know that our CSS uses the postCSS format. For better syntax highlighting install a postCSS extension (like: postcss-sugarss-language) and switch file type from css to postcss in the lower right corner of the editor.
133
+
The CSS file is processed by [PostCSS](https://postcss.org/), which allows more elegant syntax like nested rules. VS Code won't recognize PostCSS by default. For better syntax highlighting, install a PostCSS extension (such as postcss-sugarss-language) and switch the file type from CSS to PostCSS in the editor's bottom right corner.
136
134
137
135
What we did here:
138
-
-our table uses the class "countTable"
139
-
-evey odd row uses a different background color
140
-
-added a special row (class "sep") as a separator
136
+
-Applied the class `countTable` to our table
137
+
-Alternated background colors on odd rows
138
+
-Added a separator row with the `sep` class
141
139
142
-
Instead of constructing this in an HTML-String we could have use JQuery of plain 'createElement's.
143
-
I usually start with a quick HTML-String and then rewrite these in JQuery to ease event handling. But that's up to you.
140
+
Instead of building the HTML as a string, you could use jQuery or `createElement()`. I typically start with quick HTML strings and refactor to jQuery for better event handling, but that's your preference.
0 commit comments