-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: in-game options, flags overhaul #506
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f4cb00c
Added new flags format for the in-game menu system
LennardF1989 2aeccde
feat: change back to options.ini, port older versions
AnthonyFuller 0dfe79c
chore: prettier run
AnthonyFuller fc8650a
Merge branch 'master' into dev/ingame-options
AnthonyFuller 8ebe704
feat: move peacock menu to options, remove old testing
AnthonyFuller 5b2ce82
Fixed enums
LennardF1989 a8f061e
chore: add options.json
AnthonyFuller 1b778f3
feat: add cachebuster version and refresh ui in dev
AnthonyFuller 5e2502e
Merge branch 'master' into dev/ingame-options
RDIL c71e812
Merge branch 'master' into dev/ingame-options
AnthonyFuller 7bd7d63
Moved logic from plugin to core
LennardF1989 0231f12
Forgot to lint...
LennardF1989 61f85d5
chore: bump version to 8.0.0-alpha.2
AnthonyFuller 07b468f
Merge branch 'master' into dev/ingame-options
RDIL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { SyncBailHook } from "./hooksImpl" | ||
import { log, LogLevel } from "./loggingInterop" | ||
import { nilUuid } from "./utils" | ||
|
||
const peacockCommandPrefix = "peacock:" | ||
|
||
// LennardF1989: Do we want to consider string[] because of the use of URLSearchParams? | ||
type CommandArgs = { | ||
[key: string]: string /* | string[] */ | ||
} | ||
|
||
type CommandResponseCache = { | ||
[key: string]: unknown | ||
} | ||
|
||
type CommandStatus = { | ||
CacheBuster: string | ||
Commands: CommandResponseCache | ||
IsConfirmed: boolean | ||
LinkedEmail: string | ||
IOIAccountId: string | ||
IOIAccountBaseUrl: string | ||
} | ||
|
||
export type CommandFunction = ( | ||
lastResponse: unknown | undefined, | ||
args: unknown, | ||
) => unknown | ||
|
||
/* export */ class CommandService { | ||
public handleCommand: SyncBailHook< | ||
[ | ||
/** lastResponse */ unknown, | ||
/** command */ string, | ||
/** args */ unknown, | ||
], | ||
unknown | ||
> | ||
|
||
private commandResponseCache: CommandResponseCache | ||
|
||
constructor() { | ||
this.handleCommand = new SyncBailHook() | ||
this.commandResponseCache = {} | ||
} | ||
|
||
public getCommandStatus(): CommandStatus { | ||
return { | ||
CacheBuster: Date.now().toString(), | ||
Commands: this.commandResponseCache, | ||
IsConfirmed: true, | ||
LinkedEmail: "mail@example.com", | ||
IOIAccountId: nilUuid, | ||
IOIAccountBaseUrl: "https://account.ioi.dk", | ||
} | ||
} | ||
|
||
public submitCommands(email: string): CommandStatus { | ||
if (!email.startsWith(peacockCommandPrefix)) { | ||
return this.getCommandStatus() | ||
} | ||
|
||
try { | ||
const commands = email | ||
.substring(peacockCommandPrefix.length) | ||
.split("|") | ||
|
||
commands.forEach((c) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be a const-of, I somehow missed this or accidentally reverted it... |
||
const commandIndex = c.indexOf("?") | ||
|
||
let command = undefined | ||
let args: CommandArgs | ||
|
||
if (commandIndex < 0) { | ||
command = c | ||
args = {} | ||
} else { | ||
command = c.substring(0, commandIndex) | ||
args = Object.fromEntries( | ||
new URLSearchParams(c.substring(commandIndex + 1)), | ||
) | ||
} | ||
|
||
if (command === "clear") { | ||
const commands = (args.commands as string)?.split(",") | ||
|
||
for (const c of commands) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
this.commandResponseCache[c] = undefined | ||
} | ||
} else { | ||
this.commandResponseCache[command] = | ||
this.handleCommand.call( | ||
this.commandResponseCache[command], | ||
command, | ||
args, | ||
) | ||
} | ||
|
||
// logDebug(command, args, this.commandResponseCache) | ||
}) | ||
} catch (e) { | ||
log(LogLevel.ERROR, `Failed to handle Peacock command: ${e}`) | ||
} | ||
|
||
return this.getCommandStatus() | ||
} | ||
|
||
public handleCommandMap( | ||
name: string, | ||
commandMap: Map<string, CommandFunction>, | ||
) { | ||
this.handleCommand.tap( | ||
name, | ||
( | ||
lastResponse: unknown, | ||
command: string, | ||
args: unknown, | ||
): unknown => { | ||
if (commandMap.has(command)) { | ||
return commandMap.get(command)!(lastResponse, args) | ||
} | ||
|
||
return undefined | ||
}, | ||
) | ||
} | ||
} | ||
|
||
export const commandService = new CommandService() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, no, maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with either, your call