Skip to content

Commit 0bc5108

Browse files
authored
Merge pull request #19 from McBen/docs_rephrase
Docs rewrite
2 parents ab9b1eb + 25a392e commit 0bc5108

9 files changed

Lines changed: 153 additions & 199 deletions

docs/1-creating-the-plugin.md

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
# 1. Creating the Plugin
22

3-
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.
44

55
## Install the Plugin Kit
66

7-
open a terminal window and run:
7+
Open a terminal and run:
88

99
```yarn add iitcpluginkit```
1010

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.
1412

1513
## Create the initial layout
1614

17-
- let IITCPluginKit create a default plugin layout for you:
18-
`yarn ipk`
15+
Generate a default plugin structure:
1916

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.
2122

2223
## Add some code
2324

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");`
2526

26-
- save and run:
27-
`yarn autobuild`
27+
2. Save the file and run:
2828

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:
3234

3335
```shell
3436
[0] Built at: 2020-07-11 22:35:01
@@ -38,21 +40,25 @@ Something like:
3840

3941
## Installation
4042

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.
4244

4345
![Browser window](/images/tut-1.png)
4446

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.
4848

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! 🎉
5050

5151
## 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
5552

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.

docs/2-starting-buttons.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Expect the unexpected: the function `init()` is called on startup.
44
So put there all the stuff you want to run on start.
55

66
## 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:
89

910
:::code-group
1011
```typescript {7-12,15-17} [src/Main.ts]
@@ -29,19 +30,19 @@ class CountPortals implements Plugin.Class {
2930
```
3031
:::
3132

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.
3334

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.
3536

3637
![Hello world!](/images/tut-2.png)
3738

3839
## 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
4140

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`:
4546

4647
```typescript {3}
4748
import * as Plugin from "iitcpluginkit";
@@ -53,7 +54,7 @@ class CountPortals implements Plugin.Class {
5354
}
5455
```
5556

56-
- Then create the toolbar button.
57+
3. Then create the toolbar button:
5758

5859
```typescript {14-24}
5960
class CountPortals implements Plugin.Class {
@@ -84,14 +85,13 @@ class CountPortals implements Plugin.Class {
8485
}
8586
```
8687

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.
8989

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.
9291

9392
## 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:
9595

9696
:::code-group
9797
```css [styles.css]
@@ -114,8 +114,7 @@ const toolbarGroup = $("<div>", { class: "leaflet-bar leaflet-control" })
114114
```
115115
:::
116116

117-
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:
119118

120119
:::code-group
121120
```typescript [Main.ts]
@@ -131,7 +130,7 @@ class CountPortals implements Plugin.Class {
131130

132131
## Refactoring
133132

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:
135134

136135
:::code-group
137136
```typescript {7,10-28} [Main.ts]
@@ -167,5 +166,4 @@ class CountPortals implements Plugin.Class {
167166
```
168167
:::
169168

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.

docs/3-the-calculation.md

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# 3. The Calculation
22

3-
Let's fill the plugin with the real magic.
4-
I prefer to solve things top-down. So we start with the expected result:
3+
Let's implement the core functionality. We'll work top-down, starting with the expected result:
54
```typescript
65
doCount(): void {
76

@@ -14,10 +13,9 @@ doCount(): void {
1413
alert(`Portals in Hack range: ${portals.length}`)
1514
}
1615
```
17-
We check if the drawtool-plugin is installed. Then we need something that will give us a list of portals.
18-
And last-but-not-least print the result to the user.
16+
We check if the DrawTools plugin is installed, then retrieve a list of hackable portals, and finally display the result to the user.
1917

20-
One step deeper: Loop through all portals and check if they are in range:
18+
One level deeper, we loop through all portals and check if they're within range:
2119
```typescript
2220
private findHackablePortals(): IITC.Portal[] {
2321

@@ -38,12 +36,10 @@ private findHackablePortals(): IITC.Portal[] {
3836
}
3937
```
4038

41-
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.
4541

46-
Another step deeper: Loop through all drawed polylines.
42+
Going deeper, we loop through all drawn polylines:
4743

4844
```typescript
4945
private findNearestPoint(pos: L.LatLng): L.LatLng | undefined {
@@ -73,12 +69,11 @@ private findNearestPoint(pos: L.LatLng): L.LatLng | undefined {
7369
}
7470
```
7571

76-
"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.
8073

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.
75+
76+
Finally, some mathematical utilities:
8277

8378
```typescript
8479
private closedPoint(a: L.LatLng, b: L.LatLng, x: L.LatLng): L.LatLng {
@@ -103,12 +98,11 @@ private distance2(a: L.LatLng, b: L.LatLng): number {
10398
}
10499
```
105100

106-
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.
110104

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:
112106

113107
```typescript
114108
if (closestPoint && position.distanceTo(closestPoint) <= HACK_RANGE)

docs/4-the-dialog.md

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 4. The Dialog
22

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:
44

55
```typescript {10-29}
66
doCount(): void {
@@ -35,18 +35,19 @@ doCount(): void {
3535
}
3636
```
3737

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.
3939

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
4241

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.
4443

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.
4645

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.
4847

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:
5051
```typescript
5152
interface IITC.Portal {
5253
options: {
@@ -74,20 +75,18 @@ Without the leaflet stuff:
7475
}
7576
```
7677

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.
7879

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.
8081

8182

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
8484

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`.
8686

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.
8988

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.
9190

9291
The table itself looks really boring. Let's add some CSS styling:
9392

@@ -131,13 +130,11 @@ contents += "</table>"
131130
```
132131
:::
133132

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.
136134

137135
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
141139

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

Comments
 (0)