-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
179 lines (174 loc) · 6.98 KB
/
main.ts
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import * as Atom from "https://raw.githubusercontent.com/Lodestone-Team/lodestone-atom-lib/main/mod.ts"
import { EventStream, ProgressionHandler } from "https://raw.githubusercontent.com/Lodestone-Team/lodestone-macro-lib/main/events.ts";
interface RestoreConfig {
name: string;
description: string;
port: number;
}
export default class TestInstance extends Atom.AtomInstance {
uuid!: string;
_state: Atom.InstanceState = "Stopped";
path!: string;
event_stream!: EventStream;
config!: RestoreConfig;
static restoreConfigName = "restore.json";
public async setupManifest(): Promise<Atom.SetupManifest> {
return {
setting_sections: {
"section_id1": {
section_id: "section_id1",
name: "section_name1",
description: "section_description1",
settings: {
"setting_id1": {
setting_id: "setting_id1",
name: "Port",
description: "Port to run the server on",
value: null,
value_type: { type: "UnsignedInteger", min: 0, max: 65535 },
default_value: { type: "UnsignedInteger", value: 6969 },
is_secret: false,
is_required: true,
is_mutable: true,
}
},
}
}
};
}
public async setup(setupValue: Atom.SetupValue, dotLodestoneConfig: Atom.DotLodestoneConfig, progression_handler: ProgressionHandler, path: string): Promise<void> {
this.uuid = dotLodestoneConfig.uuid;
let port: number;
if (setupValue.setting_sections["section_id1"].settings["setting_id1"].value?.type == "UnsignedInteger") {
port = setupValue.setting_sections["section_id1"].settings["setting_id1"].value.value;
} else {
throw new Error("Invalid value type");
}
this.config = {
name: setupValue.name,
description: setupValue.description ?? "",
port: port,
};
// write config to file
await Deno.writeTextFile(path + "/" + TestInstance.restoreConfigName, JSON.stringify(this.config));
this.event_stream = new EventStream(this.uuid, this.config.name);
for (let i = 0; i < 100; i++) {
progression_handler.setProgress(i, `Progress ${i}`);
await new Promise(r => setTimeout(r, 100));
}
return;
}
public async restore(dotLodestoneConfig: Atom.DotLodestoneConfig, path: string): Promise<void> {
this.uuid = dotLodestoneConfig.uuid;
this.config = JSON.parse(await Deno.readTextFile(path + "/" + TestInstance.restoreConfigName)) as RestoreConfig;
this.event_stream = new EventStream(this.uuid, this.config.name);
return;
}
public async start(caused_by: Atom.CausedBy, block: boolean): Promise<void> {
console.log("start");
this.event_stream.emitStateChange("Running");
this._state = "Running";
(async () => {
while (this._state == "Running") {
await new Promise(r => setTimeout(r, 1000));
this.event_stream.emitConsoleOut("Output");
}
})();
return;
}
public async stop(caused_by: Atom.CausedBy, block: boolean): Promise<void> {
console.log("stop");
this._state = "Stopped";
this.event_stream.emitStateChange("Stopped");
return;
}
public restart(caused_by: Atom.CausedBy, block: boolean): Promise<void> {
throw new Error("Method not implemented.");
}
public kill(caused_by: Atom.CausedBy): Promise<void> {
throw new Error("Method not implemented.");
}
public async state(): Promise<Atom.InstanceState> {
return this._state;
}
public async sendCommand(command: string, caused_by: Atom.CausedBy): Promise<void> {
this.event_stream.emitConsoleOut(`Got command: ${command}`);
}
public monitor(): Promise<Atom.PerformanceReport> {
throw new Error("Method not implemented.");
}
public async configurableManifest(): Promise<Atom.ConfigurableManifest> {
return {
auto_start: false,
restart_on_crash: false,
setting_sections: {
"section_id1": {
section_id: "section_id1",
name: "First Section",
description: "This is the first section",
settings: {
"setting_id1": {
setting_id: "setting_id1",
name: "Port",
description: "Port to run the server on",
value: { type: "UnsignedInteger", value: this.config.port },
value_type: { type: "UnsignedInteger", min: 0, max: 65535 },
default_value: { type: "UnsignedInteger", value: 6969 },
is_secret: false,
is_required: true,
is_mutable: true,
}
},
}
}
}
}
public async name(): Promise<string> {
return this.config.name;
}
public version(): Promise<string> {
throw new Error("Method not implemented.");
}
public game(): Promise<Atom.Game> {
throw new Error("Method not implemented.");
}
public async description(): Promise<string> {
return this.config.description;
}
public async port(): Promise<number> {
return this.config.port;
}
public getAutoStart(): Promise<boolean> {
throw new Error("Method not implemented.");
}
public getRestartOnCrash(): Promise<boolean> {
throw new Error("Method not implemented.");
}
public async setName(name: string): Promise<void> {
this.config.name = name;
}
public async setDescription(description: string): Promise<void> {
this.config.description = description;
}
public async setPort(port: number): Promise<void> {
this.config.port = port;
}
public setAutoStart(auto_start: boolean): Promise<void> {
throw new Error("Method not implemented.");
}
public setRestartOnCrash(restart_on_crash: boolean): Promise<void> {
throw new Error("Method not implemented.");
}
public playerCount(): Promise<number> {
throw new Error("Method not implemented.");
}
public maxPlayerCount(): Promise<number> {
throw new Error("Method not implemented.");
}
public playerList(): Promise<Atom.GenericPlayer[]> {
throw new Error("Method not implemented.");
}
public updateConfigurable(section_id: string, setting_id: string, value: Atom.ConfigurableValue): Promise<void> {
throw new Error("Method not implemented.");
}
}