Skip to content

Commit

Permalink
New API
Browse files Browse the repository at this point in the history
  • Loading branch information
Vorlias committed Dec 24, 2021
1 parent 57714b6 commit d974e85
Show file tree
Hide file tree
Showing 13 changed files with 540 additions and 401 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<div align="center">
<img src="https://i.imgur.com/YgpbX7G.png"/>
<div>
<img src="https://i.imgur.com/YgpbX7G.png" align="left" width="128"/>
<h1>Zircon (Beta)</h1>
<h2>A clean, sleek, runtime debugging console for Roblox</h2>
<p>
</p>
</div>

<img src="./assets/Example2.jpg"/>
Expand Down Expand Up @@ -66,7 +69,7 @@ ZirconServer.Registry.RegisterFunction(
message,
context.GetExecutor()
)),
[ZirconServer.Registry.User]
[ZirconServer.Registry.GetGroups("User")]
)
```

Expand Down
139 changes: 60 additions & 79 deletions example/server/index.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Log, { Logger } from "@rbxts/log";
import { Workspace } from "@rbxts/services";
import Zircon, { ZirconServer } from "@zircon";
import Zircon, { ZirconConfigurationBuilder, ZirconServer } from "@zircon";
import ZirconPrint from "BuiltIn/Print";
import { ZirconEnumBuilder } from "Class/ZirconEnumBuilder";
import { ZirconFunctionBuilder } from "Class/ZirconFunctionBuilder";
Expand All @@ -14,21 +14,12 @@ Log.SetLogger(
.Create(),
);

enum ExistingEnumType {
EnumA,
EnumB,
}

const TestEnum = ZirconServer.Registry.RegisterEnumFromArray(
"TestEnum",
["Value1", "Value2"],
[ZirconServer.Registry.User],
ZirconServer.Registry.GetGroups("User"),
);

const ExistingEnum = ZirconServer.Registry.RegisterEnum(new ZirconEnumBuilder("test").FromEnum(ExistingEnumType), [
ZirconServer.Registry.User,
]);

ZirconServer.Registry.RegisterFunction(
new ZirconFunctionBuilder("kill")
.AddArgument("player?")
Expand All @@ -38,67 +29,7 @@ ZirconServer.Registry.RegisterFunction(
target.Character?.BreakJoints();
Log.Info("Killed {target}", target);
}),
[ZirconServer.Registry.User],
);

ZirconServer.Registry.RegisterFunction(
new ZirconFunctionBuilder("test_enum").AddArgument(TestEnum).Bind((context, value) => {
value.Match({
Value2: () => {
Log.Info("Got given enum item 2 (member)");
},
Value1: () => {
Log.Info("Got given enum item 1 (member)");
},
});
TestEnum.Match(value, {
Value1: () => {
Log.Info("Got given enum item 1 (parent)");
},
Value2: () => {
Log.Info("Got given enum item 2 (parent)");
},
});
}),
[ZirconServer.Registry.User],
);

ZirconServer.Registry.RegisterFunction(
new ZirconFunctionBuilder("test_enum2").AddArgument(ExistingEnum.GetMemberType()).Bind((context, value) => {
Log.Info("Got {NumberValue} ({StringValue})", ExistingEnumType[value.GetName()], value.GetName());
}),
[ZirconServer.Registry.User],
);

ZirconServer.Registry.RegisterFunction(
new ZirconFunctionBuilder("print_message")
.AddArgument("string")
.Bind((context, message) => Log.Info("Zircon says {Message} from {Player}", message, context.GetExecutor())),
[ZirconServer.Registry.User],
);

ZirconServer.Registry.RegisterNamespace(
new ZirconNamespaceBuilder("example")
.AddFunction(
new ZirconFunctionBuilder("print").Bind((context, ...args) => {
Log.Info("[Example print] " + args.map((a) => tostring(a)).join(" "));
}),
)
.AddFunction(
new ZirconFunctionBuilder("test").Bind((context) => {
Log.Info("Test!");
}),
)
.AddFunction(ZirconPrint)
.Build(),
[ZirconServer.Registry.User],
);

ZirconServer.Registry.RegisterFunction(
new ZirconFunctionBuilder("print").Bind((context, ...args) => {
Log.Info(args.map((a) => tostring(a)).join(" "));
}),
[ZirconServer.Registry.User],
ZirconServer.Registry.GetGroups("User"),
);

class Example {
Expand Down Expand Up @@ -129,10 +60,60 @@ Promise.delay(5).then(() => {
Log.Fatal("Fatal message here");
});

// game.GetService("Players").PlayerAdded.Connect((player) => {
// ZirconServer.Registry.AddPlayerToGroups(player, ["creator"]);
// });

// for (const player of game.GetService("Players").GetPlayers()) {
// Zircon.Server.Registry.AddPlayerToGroups(player, ["creator"]);
// }
ZirconServer.Registry.Init(
new ZirconConfigurationBuilder()
.CreateDefaultCreatorGroup()
.CreateDefaultUserGroup()
.AddFunction(
new ZirconFunctionBuilder("print").Bind((context, ...args) => {
Log.Info(args.map((a) => tostring(a)).join(" "));
}),
["User"],
)
.AddNamespace(
new ZirconNamespaceBuilder("example")
.AddFunction(
new ZirconFunctionBuilder("print").Bind((context, ...args) => {
Log.Info("[Example print] " + args.map((a) => tostring(a)).join(" "));
}),
)
.AddFunction(
new ZirconFunctionBuilder("test").Bind((context) => {
Log.Info("Test!");
}),
)
.AddFunction(ZirconPrint)
.Build(),
["User"],
)
.AddFunction(
new ZirconFunctionBuilder("print_message")
.AddArgument("string")
.Bind((context, message) =>
Log.Info("Zircon says {Message} from {Player}", message, context.GetExecutor()),
),
["User"],
)
.AddFunction(
new ZirconFunctionBuilder("test_enum").AddArgument(TestEnum).Bind((context, value) => {
value.Match({
Value2: () => {
Log.Info("Got given enum item 2 (member)");
},
Value1: () => {
Log.Info("Got given enum item 1 (member)");
},
});
TestEnum.Match(value, {
Value1: () => {
Log.Info("Got given enum item 1 (parent)");
},
Value2: () => {
Log.Info("Got given enum item 2 (parent)");
},
});
}),
["User"],
)
.Build(),
);
Loading

0 comments on commit d974e85

Please sign in to comment.