Skip to content

Commit e102832

Browse files
committed
chore: add some interesting local files
1 parent 84cd372 commit e102832

File tree

12 files changed

+205
-0
lines changed

12 files changed

+205
-0
lines changed

src/base/plugin/enabled.local.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import wrap from '../../utils/2.pokemon';
2+
import { registerModule } from '../../utils/plugin';
3+
import * as settings from '../../utils/settings';
4+
5+
const enable = ['Enable with toast', 'Enable silently'];
6+
7+
const setting = settings.register({
8+
name: 'New plugin behavior',
9+
key: 'enable.plugins',
10+
category: 'Plugins',
11+
data: [...enable, 'Disable with toast', 'Disable silently'],
12+
type: 'select',
13+
});
14+
15+
wrap(() => {
16+
const name = 'enabled';
17+
18+
function mod(plugin) {
19+
// if (!plugin.version) return;
20+
const enabled = plugin.settings().add({ key: 'Enabled', default: enable.includes(setting.value()) });
21+
22+
Object.defineProperty(plugin, name, {
23+
get: () => !!enabled.value(), // TODO: Why does it not default to false?
24+
});
25+
26+
const registered = plugin.settings().add({ key: 'registered', hidden: true });
27+
if (!registered.value()) {
28+
const val = enable.includes(setting.value());
29+
if (setting.value().includes('toast')) {
30+
// TODO: Show toast to toggle setting from default
31+
} else {
32+
registered.set(true);
33+
}
34+
// Set initial value
35+
enabled.set(val);
36+
}
37+
}
38+
39+
registerModule(name, mod, ['settings']);
40+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import * as settings from '../../../utils/settings';
2+
3+
const page = document.createElement('div');
4+
5+
page.innerHTML = `
6+
<fieldset>
7+
<div class="flex-start">
8+
<button id="underscriptExportButton" class="btn btn-default">Export</button>
9+
</div>
10+
</fieldset>
11+
<fieldset>
12+
<div class="flex-start">
13+
Import
14+
</div>
15+
</fieldset>
16+
`;
17+
18+
settings.getScreen().addTab('Advanced', page).setEnd(true);
19+
20+
page.querySelector('#underscriptExportButton').addEventListener('click', () => save());
21+
22+
function save(data = settings.exportSettings()) {
23+
if (!data) return;
24+
const t = new Blob([data], { type: 'text/plain' });
25+
26+
const a = document.createElement('a');
27+
a.download = 'underscript.settings.txt';
28+
a.href = URL.createObjectURL(t);
29+
a.click();
30+
}

src/structures.local/base.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default class Base {
2+
constructor(data) {
3+
this.id = data.id;
4+
}
5+
6+
update(data) {}
7+
}

src/structures.local/board.js

Whitespace-only changes.

src/structures.local/card.js

Whitespace-only changes.

src/structures.local/channel.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import Collection from '../utils/collection';
2+
import Base from './base';
3+
import Message from './message';
4+
5+
export default class Channel extends Base {
6+
constructor(data, owner) {
7+
super(data);
8+
this.owner = owner;
9+
this.name = data.name;
10+
this.messages = new Collection(Message, 50);
11+
this.update(data);
12+
}
13+
14+
update(data) {
15+
switch (data.action) {
16+
default: break;
17+
case 'getMessage':
18+
case 'getPrivateMessage':
19+
// TODO: Add new message
20+
break;
21+
}
22+
}
23+
24+
sendMessage(message) {
25+
return this.owner.sendMessage(message, this);
26+
}
27+
}

src/structures.local/chat.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Collection from '../utils/collection';
2+
import Channel from './channel';
3+
4+
export default class Chat {
5+
constructor(data) {
6+
this.channels = new Collection(Channel);
7+
this.update(data);
8+
}
9+
10+
update(data) {
11+
}
12+
13+
get isConnected() {
14+
return false;
15+
}
16+
17+
get socket() {
18+
return undefined;
19+
}
20+
21+
sendMessage(message, channel) {
22+
// TODO
23+
}
24+
}

src/structures.local/game.js

Whitespace-only changes.

src/structures.local/message.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import Base from './base';
2+
import User from './user';
3+
4+
export default class Message extends Base {
5+
constructor(data, channel) {
6+
super(data);
7+
this.user = new User(data.user);
8+
this.room = channel;
9+
this.deleted = false;
10+
this.isAction = data.me === true;
11+
this.isRainbow = data.rainbow === true;
12+
this.message = data.message;
13+
this.update(data);
14+
}
15+
16+
update(data) {
17+
if (data.deleted !== undefined) this.deleted = data.deleted === true;
18+
}
19+
20+
get channel() {
21+
return this.room;
22+
}
23+
24+
get text() {
25+
return this.message;
26+
}
27+
28+
get action() {
29+
return this.isAction;
30+
}
31+
32+
get sender() {
33+
return this.user;
34+
}
35+
36+
get deleted() {
37+
return this.isDeleted;
38+
}
39+
40+
get rainbow() {
41+
return this.isRainbow;
42+
}
43+
}

src/structures.local/player.js

Whitespace-only changes.

0 commit comments

Comments
 (0)