Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesetup/Chat/ChatInputAutocomplete.js
- This file was moved from binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/Panels/Chat/ChatInputAutocomplete.js.
class ChatInputAutocomplete | class ChatInputAutocomplete | ||||
{ | { | ||||
constructor(gameSettingControlManager, gameSettingsController, playerAssignmentsController) | constructor() | ||||
{ | { | ||||
this.gameSettingControlManager = gameSettingControlManager; | |||||
this.entries = undefined; | this.entries = undefined; | ||||
} | |||||
playerAssignmentsController.registerPlayerAssignmentsChangeHandler(this.onAutocompleteChange.bind(this)); | setAutocompleteGetter(getter) | ||||
gameSettingsController.registerSettingsChangeHandler(this.onAutocompleteChange.bind(this)); | { | ||||
this.entryGetter = getter; | |||||
} | } | ||||
onAutocompleteChange() | onAutocompleteChange() | ||||
{ | { | ||||
this.entries = undefined; | this.entries = undefined; | ||||
} | } | ||||
// Collects all strings that can be autocompleted and | // Collects all strings that can be autocompleted and | ||||
// sorts them by priority (so that playernames are always autocompleted first). | // sorts them by priority (so that playernames are always autocompleted first). | ||||
getAutocompleteEntries() | getAutocompleteEntries() | ||||
{ | { | ||||
if (this.entries) | if (this.entries) | ||||
return this.entries; | return this.entries; | ||||
// Maps from priority to autocompletable strings | // Maps from priority to autocompletable strings | ||||
let entries = { "0": [] }; | let entries = { "0": [] }; | ||||
this.gameSettingControlManager.addAutocompleteEntries(entries); | if (!this.entryGetter) | ||||
return entries; | |||||
this.entryGetter(this.entries); | |||||
let allEntries = Object.keys(entries).sort((a, b) => +b - +a).reduce( | let allEntries = Object.keys(entries).sort((a, b) => +b - +a).reduce( | ||||
(all, priority) => all.concat(entries[priority]), | (all, priority) => all.concat(entries[priority]), | ||||
[]); | []); | ||||
this.entries = Array.from(new Set(allEntries)); | this.entries = Array.from(new Set(allEntries)); | ||||
return this.entries; | return this.entries; | ||||
} | } | ||||
} | } |
Wildfire Games · Phabricator