Skip to content

Commit 52cf029

Browse files
GamerFileJaylyDev
andauthored
Update In protoform (#345)
* Create README.md * Update README.md * Add files via upload * Update index.js * Update index.js * Update test.js * Update index.js * pass format checks * rename ProtoForm to protoform * Update README.md * Update index.js * Update tests.js * Update index.d.ts * Update index.d.ts * Update index.d.ts --------- Co-authored-by: Jayly <65847850+JaylyDev@users.noreply.github.com>
1 parent 563a8be commit 52cf029

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

scripts/protoform/README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ProtoForm
22

3-
**ProtoForm** is a versatile library for creating and managing various types of forms in your Minecraft server plugins. It simplifies the process of generating modal, message, and action forms, providing a clean and structured way to handle user input.
3+
**ProtoForm** simplifies the creation and management of Minecraft forms and responses. With a single class, it provides an efficient and easy way to generate various forms. This can save you time compared to the original approach, as minimal code is required. The form type is determined based on the keys/properties provided in the object, resulting in clean and concise code with reduced storage needs.
44

55
## Features
66

@@ -23,14 +23,16 @@ import { ProtoForm } from "./index.js";
2323
```
2424
### ModalForm
2525

26+
- **fields** key determines that it's a **ModalForm**
27+
2628
```js
2729
const modalForm = new ProtoForm({
2830
title: "Example Modal Form",
2931
fields: [
30-
["text", ["Label", "Placeholder", "Default"]],
31-
["slider",["Label",2/* Min */,10/* Max */,2/*Step*/,6/*Default*/]],
32-
["dropdown",["Label",["Option 1","Option 2", "Option 3"]/* Options */,1 /*Default*/]],
33-
["toggle",["Label",true /*default*/]]
32+
["text", "Label", "Placeholder", "Default"],
33+
["slider","Label",2/* Min */,10/* Max */,2/*Step*/,6/*Default*/],
34+
["dropdown","Label",["Option 1","Option 2", "Option 3"]/* Options */,1 /*Default*/],
35+
["toggle","Label",true /*default*/]
3436
],
3537
response: (data) => {
3638
// Handle form submission
@@ -40,6 +42,8 @@ const modalForm = new ProtoForm({
4042
```
4143
### MessageForm
4244

45+
- **btn1** and **btn2** determines that it's a **MessageForm**
46+
4347
```js
4448
const messageForm = new ProtoForm({
4549
title: "Example Message Form",
@@ -54,12 +58,17 @@ const messageForm = new ProtoForm({
5458
```
5559
### ActionForm
5660

61+
- **btns** key determine that it's an **ActionForm**
62+
5763
```js
5864
const actionForm = new ProtoForm({
5965
title: "Example Action Form",
66+
body: "Example Action Form Body",
6067
btns: [
6168
["Button 1", "path/to/btn1_texture"],
6269
["Button 2", "path/to/btn2_texture"],
70+
"Button 3",
71+
["Button 4"],
6372
// Add more buttons as needed
6473
],
6574
response: (data) => {
@@ -68,6 +77,7 @@ const actionForm = new ProtoForm({
6877
}
6978
});
7079
```
80+
7181
### Showing Forms To Player
7282

7383
```js
@@ -76,5 +86,19 @@ modalForm.show(player);
7686
messageForm.show(player);
7787
actionForm.show(player);
7888
```
89+
90+
### Case Errors
91+
92+
- When **fields** and **btn1** or **btn2** keys are used togethor, it throws error.
93+
94+
- When **fields** and **btns** keys are used togethor, it throws error.
95+
96+
- When **btns** and **btn1** or **btn2** keys are used togethor, it throws error.
97+
98+
- When **title** is missing, it throws error.
99+
100+
- When **body** is missing with **btns** or **btn1** and **btn2**, it throws error. => When **body** is missing in **MessageForm** or **ActionForm**, it throws error.
101+
102+
79103
## Author
80104
These Scripts Are Written By **GamerFile**

scripts/protoform/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ declare class ProtoForm {
1111
body?: string;
1212
btn1?: string;
1313
btn2?: string;
14-
btns?: [string, string | undefined][];
14+
btns?: (string | [string] | [string, string | undefined])[];
1515
response?: (result: FormResponse) => void;
1616
});
1717

scripts/protoform/index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,8 @@ export class ProtoForm {
6868
if (!body) throw new Error("Body is essential in ActionFormData.");
6969
this.form.title(title);
7070
this.form.body(body);
71-
btns.forEach(([text, texture]) => {
72-
this.form?.button(
73-
text,
74-
texture ?? undefined
75-
);
71+
btns.forEach((btn) => {
72+
typeof btn == "string"? this.form?.button(btn): this.form?.button(btn[0],btn[1] ?? undefined)
7673
});
7774
}
7875
} else if (fields) {
@@ -83,7 +80,7 @@ export class ProtoForm {
8380
if (this.form instanceof ModalFormData) {
8481
this.form.title(title);
8582

86-
fields.forEach(([type, details]) => {
83+
fields.forEach(([type, ...details]) => {
8784
switch (type) {
8885
case "text":
8986
this.form?.textField(

scripts/protoform/tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ProtoForm } from "index.js";
55
const actionform = new ProtoForm({
66
title: "Test ActionForm",
77
body: "Body...",
8-
btns: [["Hey","Texture Path"],["Btn2","Path2"]],
8+
btns: [["Hey","Texture Path"],["Btn2","Path2"],"btn3","btn4",["btn5"]],
99
response: ({selection:s}) => {
1010
console.warn("selected no" + s)
1111
}

0 commit comments

Comments
 (0)