repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
UTMStack | github_2023 | utmstack | typescript | ElasticFilterAddComponent.onOperatorChange | onOperatorChange($event) {
this.formFilter.get('value').setValue(null);
this.isMultipleSelectValue();
} | /**
* When change operator set value to null, and set current multiple var
* @param $event Operator
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/components/utm/filters/utm-elastic-filter/elastic-filter-add/elastic-filter-add.component.ts#L213-L216 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | ElasticFilterAddComponent.applySelectFilter | applySelectFilter(): boolean {
const fieldSelected = this.formFilter.get('field').value;
// if field exist
if (this.field) {
if (this.field.type === ElasticDataTypesEnum.TEXT ||
this.field.type === ElasticDataTypesEnum.STRING) {
/* if fields is type string or text determine if field is... | /**
* Return boolean, if show input or select values
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/components/utm/filters/utm-elastic-filter/elastic-filter-add/elastic-filter-add.component.ts#L221-L246 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | ElasticFilterAddComponent.operatorFieldSelectable | operatorFieldSelectable(): boolean {
return this.operator === this.operatorEnum.IS || this.operator === this.operatorEnum.IS_NOT ||
this.operator === this.operatorEnum.IS_ONE_OF || this.operator === this.operatorEnum.IS_NOT_ONE_OF;
} | /**
* Return boolean, using to determine if current operator is selectable or not
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/components/utm/filters/utm-elastic-filter/elastic-filter-add/elastic-filter-add.component.ts#L251-L254 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | ElasticFilterAddComponent.operator | get operator(): ElasticOperatorsEnum {
return this.formFilter.get('operator').value;
} | /**
* Return current operator
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/components/utm/filters/utm-elastic-filter/elastic-filter-add/elastic-filter-add.component.ts#L259-L261 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | ElasticFilterAddComponent.getIndexField | getIndexField(): number {
return this.fields.findIndex(value => value.name === this.formFilter.get('field').value);
} | /**
* Return index of field selected
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/components/utm/filters/utm-elastic-filter/elastic-filter-add/elastic-filter-add.component.ts#L276-L278 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | ElasticFilterAddComponent.field | get field(): ElasticSearchFieldInfoType {
const field = this.formFilter.get('field').value;
const index = this.fields.findIndex(value => value.name === field);
if (index !== -1) {
return this.fields[index];
}
} | /**
* return current field selected
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/components/utm/filters/utm-elastic-filter/elastic-filter-add/elastic-filter-add.component.ts#L283-L289 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | ElasticFilterAddComponent.getOperators | getOperators() {
const index = this.getIndexField();
if (index !== -1) {
const fieldType = this.fields[index].type;
if (fieldType === ElasticDataTypesEnum.TEXT || fieldType === ElasticDataTypesEnum.STRING) {
if (!this.field.name.includes('.keyword')) {
this.operators = FILTER_OPERA... | /**
* Return operators based on field type
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/components/utm/filters/utm-elastic-filter/elastic-filter-add/elastic-filter-add.component.ts#L294-L320 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | ElasticFilterAddComponent.isMultipleSelectValue | isMultipleSelectValue() {
this.multiple = this.formFilter.get('operator').value === ElasticOperatorsEnum.IS_ONE_OF ||
this.formFilter.get('operator').value === ElasticOperatorsEnum.IS_NOT_ONE_OF ||
this.formFilter.get('operator').value === ElasticOperatorsEnum.CONTAIN_ONE_OF ||
this.formFilter.get... | /**
* Determine if a field select value cant choose multiple values or not
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/components/utm/filters/utm-elastic-filter/elastic-filter-add/elastic-filter-add.component.ts#L325-L330 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | ElasticFilterAddComponent.setValueRange | setValueRange() {
this.formFilter.get('value').setValue([this.valueFrom, this.valueTo]);
} | /**
* Set a filter value with a range
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/components/utm/filters/utm-elastic-filter/elastic-filter-add/elastic-filter-add.component.ts#L335-L337 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | UtmDynamicTableComponent.isSortableColumn | isSortableColumn(column: UtmFieldType): boolean {
if (column.type === ElasticDataTypesEnum.TEXT || column.type === ElasticDataTypesEnum.STRING) {
return column.field.includes('.keyword');
} else {
return true;
}
} | /**
* Find in all field if column type text has keyword
* @param column Column to check if column cant be sort
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/components/utm/table/utm-table/dynamic-table/dynamic-table.component.ts#L122-L128 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | UtmScrollTopComponent.scrolled | scrolled(event: any): void {
this.isScrolled = true;
} | // <- Add scroll listener to window | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/components/utm/util/utm-scroll-top/utm-scroll-top.component.ts#L18-L20 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | SafePipe.constructor | constructor(protected _sanitizer: DomSanitizer) {
} | // tslint:disable-next-line | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/pipes/safe.pipe.ts#L18-L19 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | SafePipe.transform | transform(value: string, type: string): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl {
switch (type) {
case 'html':
return this._sanitizer.bypassSecurityTrustHtml(value);
case 'style':
return this._sanitizer.bypassSecurityTrustStyle(value);
case 'script':
r... | /**
* Transform
*
* @param value: string
* @param type: string
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/pipes/safe.pipe.ts#L27-L42 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | ActiveAdModuleActiveService.isADModuleActive | isADModuleActive(): Observable<boolean> {
return new Observable<boolean>(subscriber => {
this.moduleService.isActive(UtmModulesEnum.AD_AUDIT).subscribe(response => {
subscriber.next(response.body);
});
});
} | /**
* Find is ad module is active
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/services/active-modules/active-ad-module.service.ts#L22-L28 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | ActiveAdModuleActiveService.getAdChanges | getAdChanges(): Observable<HttpResponse<any[]>> {
return this.http.get<any[]>(this.resourceUrl + 'ad/utm-ad-trackers/tracking', {observe: 'response'});
} | // GET /api/ad/utm-ad-trackers/tracking | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/services/active-modules/active-ad-module.service.ts#L32-L34 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | UtmConfigSectionService.constructor | constructor(private http: HttpClient) {
} | // GET /api/GET /api/utm-technologies | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/services/config/utm-config-section.service.ts#L15-L16 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | MenuService.create | create(menu: IMenu): Observable<HttpResponse<IMenu>> {
return this.http.post<IMenu>(this.resourceUrl, menu, {observe: 'response'});
} | /**
* Create
* @param menu : Menu to create
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/services/menu/menu.service.ts#L25-L27 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | MenuService.update | update(menu: IMenu): Observable<HttpResponse<IMenu>> {
return this.http.put<IMenu>(this.resourceUrl, menu, {observe: 'response'});
} | /**
* Update
* @param menu : Menu to update
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/services/menu/menu.service.ts#L33-L35 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | MenuService.saveStructure | saveStructure(menus: IMenu[]): Observable<HttpResponse<IMenu>> {
return this.http.post<IMenu>(this.resourceUrl + '/save-menu-structure', menus, {observe: 'response'});
} | // POST /api/menu/save-menu-structure | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/services/menu/menu.service.ts#L38-L40 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | MenuService.find | find(name: string): Observable<HttpResponse<IMenu>> {
return this.http.get<IMenu>(`${this.resourceUrl}/${name}`, {observe: 'response'});
} | /**
* Find menus by name
* @param name : Name to search
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/services/menu/menu.service.ts#L46-L48 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | MenuService.query | query(query?: QueryType): Observable<HttpResponse<IMenu[]>> {
return this.http.get<IMenu[]>(this.resourceUrl.concat(query ? query.toString() : ''), {observe: 'response'});
} | /**
* Find menus by filters
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/services/menu/menu.service.ts#L53-L55 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | MenuService.getMenuStructure | getMenuStructure(includeModulesMenus: boolean): Observable<HttpResponse<IMenu[]>> {
return this.http.get<IMenu[]>(this.resourceUrl + '/all?includeModulesMenus=' + includeModulesMenus, {observe: 'response'});
} | /**
* Find menus by filters
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/services/menu/menu.service.ts#L60-L62 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | MenuService.delete | delete(id: number): Observable<HttpResponse<any>> {
return this.http.delete(`${this.resourceUrl}/${id}`, {observe: 'response'});
} | /**
* Delete menu
* @param id : Menu identifier to delete
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/services/menu/menu.service.ts#L68-L70 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | MenuService.deleteByUrl | deleteByUrl(url: string): Observable<HttpResponse<any>> {
return this.http.delete(this.resourceUrl + '/delete-by-url?url=' + url, {observe: 'response'});
} | /**
* Delete menu by URL
* @param url Menu url
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/services/menu/menu.service.ts#L77-L79 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | QueryType.add | add(field: string, value: any, operator?: Operator): QueryType {
if (field && value !== null && typeof value !== 'undefined') {
if (operator) {
if (!this.query) {
this.query = `?${field}.${operator}=${value}`;
} else {
this.query += `&${field}.${operator}=${value}`;
... | /**
* Build a query based on url parameters
* @param field : Name of the param
* @param value : Value of the param
* @param operator : Operator between param and value
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/types/query-type.ts#L12-L29 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | QueryType.toString | toString(): string {
return this.query ? this.query : '';
} | /**
*
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/types/query-type.ts#L34-L36 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | mixColor | function mixColor(colorOne, colorTwo, weight): string {
function d2h(d) {
return d.toString(16);
} // convert a decimal value to hex
function h2d(h) {
return parseInt(h, 16);
}
weight = (typeof (weight) !== 'undefined') ? weight : 50; // set the weight to 50%, if that argument is omitted
let colo... | /**
* Mixing Two colors
* @param colorOne Color one
* @param colorTwo Color two
* @param weight Weight
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/util/color-mixing.ts#L7-L32 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | InputClassResolve.resolveClassInput | resolveClassInput(control: AbstractControl): string {
if (control.errors && (control.touched || control.dirty)) {
return 'input-field-has-error';
} else {
return 'input-field-has-noerror';
}
} | /**
* Return class to apply to input base on errors
* @param control AbstractControl in form
*/ | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/shared/util/input-class-resolve.ts#L15-L21 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
UTMStack | github_2023 | utmstack | typescript | VsTaskElementViewResolverService.resolveTrendClass | resolveTrendClass(trend: VsTaskTrendEnum): string {
if (trend === VsTaskTrendEnum.UP || trend === VsTaskTrendEnum.MORE) {
return 'badge-danger';
} else if (trend === VsTaskTrendEnum.LESS || trend === VsTaskTrendEnum.DOWN) {
return 'badge-success';
} else {
return 'badge-primary';
}
} | // up|down|more|less|same | https://github.com/utmstack/UTMStack/blob/e00c7c4742b5ce01932668d00f6a87bb5307505d/frontend/src/app/vulnerability-scanner/shared/services/vs-task-element-view-resolver.service.ts#L58-L66 | e00c7c4742b5ce01932668d00f6a87bb5307505d |
Morpheus | github_2023 | MorpheusAIs | typescript | deployOneYearLockFixture | async function deployOneYearLockFixture() {
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
const ONE_GWEI = 1_000_000_000;
const lockedAmount = ONE_GWEI;
const unlockTime = (await time.latest()) + ONE_YEAR_IN_SECS;
// Contracts are deployed using the first signer/account by default
const [owner,... | // We define a fixture to reuse the same setup in every test. | https://github.com/MorpheusAIs/Morpheus/blob/c3012007db93f10d8d345b0f3f935598c12c21f4/contract_library/test/Lock.ts#L10-L24 | c3012007db93f10d8d345b0f3f935598c12c21f4 |
nuxt-auth-sanctum | github_2023 | manchenkoff | typescript | init | async function init() {
if (isIdentityLoaded.value) {
return
}
isIdentityLoaded.value = true
await refreshIdentity()
} | /**
* Initial request of the user identity for plugin initialization.
* Only call this method when `sanctum.client.initialRequest` is false.
*/ | https://github.com/manchenkoff/nuxt-auth-sanctum/blob/a7084fb6c383f9f6229c2b70be3df60b19cf429f/src/runtime/composables/useSanctumAuth.ts#L49-L56 | a7084fb6c383f9f6229c2b70be3df60b19cf429f |
nuxt-auth-sanctum | github_2023 | manchenkoff | typescript | refreshIdentity | async function refreshIdentity() {
user.value = await client<T>(options.endpoints.user!)
} | /**
* Fetches the user object from the API and sets it to the current state
*/ | https://github.com/manchenkoff/nuxt-auth-sanctum/blob/a7084fb6c383f9f6229c2b70be3df60b19cf429f/src/runtime/composables/useSanctumAuth.ts#L61-L63 | a7084fb6c383f9f6229c2b70be3df60b19cf429f |
nuxt-auth-sanctum | github_2023 | manchenkoff | typescript | login | async function login(credentials: Record<string, any>) {
const currentRoute = useRoute()
const currentPath = trimTrailingSlash(currentRoute.path)
if (isAuthenticated.value) {
if (!options.redirectIfAuthenticated) {
throw new Error('User is already authenticated')
}
if (
o... | /**
* Calls the login endpoint and sets the user object to the current state
*
* @param credentials Credentials to pass to the login endpoint
*/ | https://github.com/manchenkoff/nuxt-auth-sanctum/blob/a7084fb6c383f9f6229c2b70be3df60b19cf429f/src/runtime/composables/useSanctumAuth.ts#L70-L141 | a7084fb6c383f9f6229c2b70be3df60b19cf429f |
nuxt-auth-sanctum | github_2023 | manchenkoff | typescript | logout | async function logout() {
if (!isAuthenticated.value) {
throw new Error('User is not authenticated')
}
const currentRoute = useRoute()
const currentPath = trimTrailingSlash(currentRoute.path)
if (options.endpoints.logout === undefined) {
throw new Error('`sanctum.endpoints.logout` is n... | /**
* Calls the logout endpoint and clears the user object
*/ | https://github.com/manchenkoff/nuxt-auth-sanctum/blob/a7084fb6c383f9f6229c2b70be3df60b19cf429f/src/runtime/composables/useSanctumAuth.ts#L146-L184 | a7084fb6c383f9f6229c2b70be3df60b19cf429f |
nuxt-auth-sanctum | github_2023 | manchenkoff | typescript | useServerHeaders | function useServerHeaders(
headers: Headers,
config: ModuleOptions,
logger: ConsolaInstance,
): Headers {
const clientHeaders = useRequestHeaders(['cookie', 'user-agent'])
const origin = config.origin ?? useRequestURL().origin
const headersToAdd = {
Referer: origin,
Origin: origin,
...(clientHe... | /**
* Pass all cookies, headers and referrer from the client to the API
* @param headers Headers collection to extend
* @param config Module configuration
* @param logger Logger instance
* @returns Headers collection to pass to the API
*/ | https://github.com/manchenkoff/nuxt-auth-sanctum/blob/a7084fb6c383f9f6229c2b70be3df60b19cf429f/src/runtime/interceptors/cookie/request.ts#L18-L39 | a7084fb6c383f9f6229c2b70be3df60b19cf429f |
nuxt-auth-sanctum | github_2023 | manchenkoff | typescript | initCsrfCookie | async function initCsrfCookie(
config: ModuleOptions,
logger: ConsolaInstance,
): Promise<void> {
if (config.endpoints.csrf === undefined) {
throw new Error('`sanctum.endpoints.csrf` is not defined')
}
await $fetch(config.endpoints.csrf, {
baseURL: config.baseUrl,
credentials: 'include',
})
... | /**
* Request a new CSRF cookie from the API
* @param config Module configuration
* @param logger Logger instance
* @returns {Promise<void>}
*/ | https://github.com/manchenkoff/nuxt-auth-sanctum/blob/a7084fb6c383f9f6229c2b70be3df60b19cf429f/src/runtime/interceptors/cookie/request.ts#L47-L61 | a7084fb6c383f9f6229c2b70be3df60b19cf429f |
nuxt-auth-sanctum | github_2023 | manchenkoff | typescript | useCsrfHeader | async function useCsrfHeader(
headers: Headers,
config: ModuleOptions,
logger: ConsolaInstance,
): Promise<Headers> {
if (config.csrf.cookie === undefined) {
throw new Error('`sanctum.csrf.cookie` is not defined')
}
if (config.csrf.header === undefined) {
throw new Error('`sanctum.csrf.header` is n... | /**
* Add CSRF token to the headers collection to pass from the client to the API
* @param headers Headers collection to extend
* @param config Module configuration
* @param logger Logger instance
* @returns Headers collection to pass to the API
*/ | https://github.com/manchenkoff/nuxt-auth-sanctum/blob/a7084fb6c383f9f6229c2b70be3df60b19cf429f/src/runtime/interceptors/cookie/request.ts#L70-L100 | a7084fb6c383f9f6229c2b70be3df60b19cf429f |
nuxt-auth-sanctum | github_2023 | manchenkoff | typescript | appendServerResponseHeaders | function appendServerResponseHeaders(
app: NuxtApp,
ctx: FetchContext,
logger: ConsolaInstance,
): void {
const event = useRequestEvent(app)
const serverCookieName = 'set-cookie'
const cookieHeader = ctx.response!.headers.get(serverCookieName)
if (cookieHeader === null || event === undefined) {
logge... | /**
* Append server response headers to the client response
* @param app Nuxt application instance
* @param ctx Fetch context
* @param logger Module logger instance
*/ | https://github.com/manchenkoff/nuxt-auth-sanctum/blob/a7084fb6c383f9f6229c2b70be3df60b19cf429f/src/runtime/interceptors/cookie/response.ts#L12-L40 | a7084fb6c383f9f6229c2b70be3df60b19cf429f |
boardzilla-core | github_2023 | boardzilla | typescript | GameManager.setSettings | setSettings(settings: Record<string, any>) {
this.settings = settings;
} | /**
* configuration functions
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/game-manager.ts#L114-L116 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameManager.start | start() {
if (this.phase === 'started') throw Error('cannot call start once started');
if (!this.players.length) {
throw Error("No players");
}
this.phase = 'started';
this.players.currentPosition = [...this.players].map(p => p.position)
this.flowState = [{stack: [], currentPosition: this.... | // start the game fresh | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/game-manager.ts#L130-L139 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameManager.getState | getState(player?: P): GameState {
return {
players: this.players.map(p => p.toJSON() as PlayerAttributes), // TODO scrub for player
settings: this.settings,
position: this.flowJSON(!!player),
board: this.game.allJSON(player?.position),
sequence: this.sequence,
messages: this.mess... | /**
* state functions
* @internal
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/game-manager.ts#L245-L256 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameManager.getAction | getAction(name: string, player: P) {
if (this.godMode) {
const godModeAction = this.godModeActions()[name];
if (godModeAction) {
godModeAction.name = name;
return godModeAction as Action & {name: string};
}
}
if (!this.actions[name]) {
throw Error(`No action found: "... | /**
* action functions
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/game-manager.ts#L318-L337 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameManager.processMove | processMove({ player, name, args }: Move): string | undefined {
if (this.phase === 'finished') return 'Game is finished';
let result: string | SubflowSignal['data'][] | undefined;
return this.inContextOfPlayer(player, () => {
if (this.godMode && this.godModeActions()[name]) {
const godModeActi... | // moves | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/game-manager.ts#L380-L400 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | Action._getPendingMoves | _getPendingMoves(args: Record<string, Argument>, debug?: ActionDebug): PendingMove[] | undefined {
if (debug) {
debug[this.name!] = { args: {} };
for (const arg of Object.keys(args)) debug[this.name!].args[arg] = 'sel';
}
const moves = this._getPendingMovesInner(args, debug);
// resolve any ... | // TODO memoize | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/action/action.ts#L127-L170 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | Action._nextSelection | _nextSelection(args: Record<string, Argument>): ResolvedSelection | undefined {
let nextSelection: ResolvedSelection | undefined = undefined;
for (const s of this.selections) {
const selection = s.resolve(args);
if (selection.skipIf === true) continue;
if (!(s.name in args)) {
nextSele... | /**
* given a partial arg list, returns a selection object for continuation if one exists.
* @internal
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/action/action.ts#L247-L258 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | Action._process | _process(player: Player, args: Record<string, Argument>): string | undefined {
// truncate invalid args - is this needed?
let error: string | undefined = undefined;
if (!this.isPossible(args as A)) return `${this.name} action not possible`;
for (const selection of this.selections) {
if (args[selec... | /**
* process this action with supplied args. returns error if any
* @internal
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/action/action.ts#L264-L309 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | Action._withDecoratedArgs | _withDecoratedArgs(args: A, fn: (args: A) => any) {
if (args['__placement__']) {
const placementSelection = this.selections.find(s => s.name === '__placement__');
if (placementSelection && args[placementSelection.placePiece!]) {
args = {...args};
// temporarily set piece to place to acce... | // fn must be idempotent | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/action/action.ts#L319-L339 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | Action.do | do(move: (args: A) => any): Action<A> {
this.mutated = true;
this.moves.push(move);
this.order.push('move');
return this;
} | /**
* Add behaviour to this action to alter game state. After adding the choices
* to an action, calling `do` causes Boardzilla to use the player choices to
* actually do something with those choices. Call this method after all the
* methods for player choices so that the choices are properly available to
... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/action/action.ts#L383-L388 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | Action.message | message(text: string, args?: Record<string, Argument> | ((a: A) => Record<string, Argument>)) {
this.messages.push({text, args});
this.order.push('message');
return this;
} | /**
* Add a message to this action that will be broadcast in the chat. Call this
* method after all the methods for player choices so that the choices are
* properly available to the `message` function. However the message should be
* called before or after any `do` behaviour depending on whether you want t... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/action/action.ts#L422-L426 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | Action.messageTo | messageTo(player: (Player | number) | (Player | number)[], text: string, args?: Record<string, Argument> | ((a: A) => Record<string, Argument>)) {
if (!(player instanceof Array)) player = [player];
for (const p of player) {
this.messages.push({position: typeof p === 'number' ? p : p.position, text, args})... | /**
* Add a message to this action that will be broadcast in the chat to the
* specified player(s). Call this method after all the methods for player
* choices so that the choices are properly available to the `message`
* function. However the message should be called before or after any `do`
* behaviour... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/action/action.ts#L463-L470 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | Action.chooseFrom | chooseFrom<N extends string, T extends SingleArgument>(
name: N,
choices: (T & (string | number | boolean))[] | { label: string, choice: T }[] | ((args: A) => (T & (string | number | boolean))[] | { label: string, choice: T }[]),
options?: {
prompt?: string | ((args: A) => string)
confirm?: stri... | /**
* Add a choice to this action from a list of options. These choices will be
* displayed as buttons in the UI.
*
* @param name - The name of this choice. This name will be used in all
* functions that accept the player's choices
*
* @param choices - An array of choices. This may be an array of s... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/action/action.ts#L561-L580 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | Action.enterText | enterText<N extends string>(name: N, options?: {
prompt?: string | ((args: A) => string),
validate?: ((args: A & {[key in N]: string}) => string | boolean | undefined),
regexp?: RegExp,
initial?: string | ((args: A) => string)
}): Action<A & {[key in N]: string}> {
const { prompt, validate, regexp... | /**
* Prompt the user for text entry. Use this in games where players submit
* text, like word-guessing games.
*
* @param name - The name of this text input. This name will be used in all
* functions that accept the player's choices
*
* @param {Object} options
* @param options.initial - Default ... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/action/action.ts#L611-L620 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | Action.chooseNumber | chooseNumber<N extends string>(name: N, options: {
min?: number | ((args: A) => number),
max?: number | ((args: A) => number),
prompt?: string | ((args: A) => string),
confirm?: string | [string, Record<string, Argument> | ((args: A & {[key in N]: number}) => Record<string, Argument>) | undefined]
v... | /**
* Add a numerical choice for this action. This will be presented with a
* number picker.
*
* @param name - The name of this choice. This name will be used in all
* functions that accept the player's choices
*
* @param {Object} options
*
* @param options.prompt - Prompt displayed to the us... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/action/action.ts#L686-L698 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | Action.chooseGroup | chooseGroup<R extends Group>(
choices: R,
options?: {
validate?: (args: ExpandGroup<A, R>) => string | boolean | undefined,
confirm?: string | [string, Record<string, Argument> | ((args: ExpandGroup<A, R>) => Record<string, Argument>) | undefined]
}
): Action<ExpandGroup<A, R>> {
for (cons... | /**
* Create a multi-selection choice. These selections will be presented all at
* once as a form. This is used for form-like choices that have a number of
* choices that are not board choices, i.e. chooseFrom, chooseNumber and
* enterText
*
* @param choices - An object containing the selections. This... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/action/action.ts#L901-L919 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | Action.confirm | confirm(prompt: string | ((args: A) => string)): Action<A> {
this._addSelection(new Selection('__confirm__', {
prompt,
confirm: typeof prompt === 'string' ? prompt : ['{{__message__}}', (args: A) => ({__message__: prompt(args)})],
value: true
}));
return this;
} | /**
* Add a confirmtation step to this action. This can be useful if you want to
* present additional information to the player related to the consequences of
* their choice, like a cost incurred. Or this can simply be used to force the
* user to click an additional button on a particular important choice.
... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/action/action.ts#L945-L952 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | Action.move | move(piece: keyof A | Piece<Game>, into: keyof A | GameElement) {
this.do((args: A) => {
const selectedPiece = piece instanceof Piece ? piece : args[piece] as Piece<Game> | Piece<Game>[];
const selectedInto = into instanceof GameElement ? into : args[into] as GameElement;
if (selectedPiece instanc... | /**
* Perform a move with the selected element(s) into a selected
* Space/Piece. This is almost the equivalent of calling Action#do and adding
* a putInto command, except that the game will also permit the UI to allow a
* mouse drag for the move.
*
* @param piece - A {@link Piece} to move or the name ... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/action/action.ts#L973-L991 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | Action.swap | swap(piece1: keyof A | Piece<Game>, piece2: keyof A | Piece<Game>) {
this.do((args: A) => {
const p1 = piece1 instanceof Piece ? piece1 : args[piece1] as Piece<Game>;
const p2 = piece2 instanceof Piece ? piece2 : args[piece2] as Piece<Game>;
const parent1 = p1._t.parent!;
const parent2 = p2.... | /**
* Swap the location of two Pieces. Each of the two pieces can either be the
* name of a previous `chooseOnBoard`, or a simply provide a piece if it is
* not a player choice. The game will also allow a mouse drag for the swap.
*
* @param piece1 - A {@link Piece} to swap or the name of the piece select... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/action/action.ts#L1010-L1031 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | Action.reorder | reorder(collection: Piece<Game>[], options?: {
prompt?: string | ((args: A) => string),
}) {
const { prompt } = options || {};
if (this.selections.some(s => s.name === '__reorder_from__')) throw Error(`Invalid reorder: only one reorder allowed`);
if (collection.some(c => c._t.parent !== collection[0].... | /**
* Have the player select one of the Pieces in the collection and select a new
* position within the collection while keeping everything else in the same
* order. The game will also permit a mouse drag for the reorder.
*
* @param collection - A collection of {@link Piece}s to reorder
*
* @param ... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/action/action.ts#L1050-L1071 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | Action.placePiece | placePiece<T extends keyof A & string>(piece: T, into: PieceGrid<Game>, options?: {
prompt?: string | ((args: A) => string),
confirm?: string | [string, Record<string, Argument> | ((args: A & {[key in T]: { column: number, row: number }}) => Record<string, Argument>) | undefined]
validate?: ((args: A & {[ke... | /**
* Add a placement selection to this action. This will be presented as a piece
* that players can move into the desired location, snapping to the grid of
* the destination as the player moves.
*
* @param piece - The name of the piece selection in this action from a
* `chooseOnBoard` prior to this
... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/action/action.ts#L1120-L1142 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | Selection.error | error(args: Record<string, Argument>): string | undefined {
const arg = args[this.name];
const s = this.resolve(args);
if (s.validation) {
const error = s.validation(args);
if (error !== undefined && error !== true) return error || 'Invalid selection';
}
if (s.type === 'choices' && s.c... | /**
* check specific selection with a given arg. evaluates within the context of
* previous args, so any selection elements that have previous-arg-function
* forms are here evaluated with the previous args. returns new selection and
* error if any
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/action/selection.ts#L204-L243 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | Selection.options | options(this: ResolvedSelection): Argument[] {
if (this.isUnbounded()) return [];
if (this.type === 'number') return range(this.min ?? 1, this.max!);
const choices = this.choiceValues()
if (this.isMulti()) return combinations(this.boardChoices || choices, this.min ?? 1, this.max ?? Infinity);
if (th... | // All possible valid Arguments to this selection. Have to make some assumptions here to tree shake possible moves | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/action/selection.ts#L246-L254 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ConnectedSpaceMap.isAdjacent | isAdjacent(el1: GameElement, el2: GameElement) {
const n1 = this._positionedParentOf(el1);
const n2 = this._positionedParentOf(el2);
return this._graph.areNeighbors(n1._t.ref, n2._t.ref);
} | /**
* Returns whether 2 elements contained within this space have an adjacency to
* each other. The elements are considered adjacent if they are child Spaces
* that have been connected, or if the provided elements are placed inside
* such connected Spaces.
* @category Adjacency
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/connected-space-map.ts#L41-L45 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ConnectedSpaceMap.connect | connect(space1: Space<G>, space2: Space<G>, distance: number = 1) {
this.connectOneWay(space1, space2, distance);
// assume bidirectional unless directly called in reverse
if (!this._graph.hasDirectedEdge(space2._t.ref, space1._t.ref)) this._graph.addDirectedEdge(space2._t.ref, space1._t.ref, {distance});
... | /**
* Make these two Spaces adjacent. This creates a two-way adjacency
* relationship. If called twice with the Spaces reversed, different distances
* can be created for the adjacency in each direction.
* @category Adjacency
*
* @param space1 - {@link Space} to connect
* @param space2 - {@link Spac... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/connected-space-map.ts#L58-L62 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ConnectedSpaceMap.connectOneWay | connectOneWay(space1: Space<G>, space2: Space<G>, distance: number = 1) {
if (this !== space1._t.parent || this !== space2._t.parent) throw Error("Both spaces must be children of the space to be connected");
if (!this._graph.hasNode(space1._t.ref)) this._graph.addNode(space1._t.ref, {space: space1});
if (!... | // @internal | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/connected-space-map.ts#L65-L72 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ConnectedSpaceMap.distanceBetween | distanceBetween(el1: GameElement, el2: GameElement) {
const n1 = this._positionedParentOf(el1);
const n2 = this._positionedParentOf(el2);
return this._distanceBetweenNodes(String(n1._t.ref), String(n2._t.ref));
} | /**
* Finds the shortest distance between two elements using this space. Elements
* must be connected Spaces of this element or be elements inside such spaces.
* @category Adjacency
*
* @param el1 - {@link GameElement} to measure distance from
* @param el2 - {@link GameElement} to measure distance to
... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/connected-space-map.ts#L84-L88 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ElementCollection.showToAll | showToAll(this: ElementCollection<Piece<BaseGame>>) {
for (const el of this) {
delete(el._visible);
}
} | /**
* Show these elements to all players
* @category Visibility
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element-collection.ts#L280-L284 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ElementCollection.showOnlyTo | showOnlyTo(this: ElementCollection<Piece<BaseGame>>, player: Player | number) {
if (typeof player !== 'number') player = player.position;
for (const el of this) {
el._visible = {
default: false,
except: [player]
};
}
} | /**
* Show these elements only to the given player
* @category Visibility
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element-collection.ts#L290-L298 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ElementCollection.showTo | showTo(this: ElementCollection<Piece<BaseGame>>, ...player: Player[] | number[]) {
if (typeof player[0] !== 'number') player = (player as Player[]).map(p => p.position);
for (const el of this) {
if (el._visible === undefined) continue;
if (el._visible.default) {
if (!el._visible.except) cont... | /**
* Show these elements to the given players without changing it's visibility to
* any other players.
* @category Visibility
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element-collection.ts#L305-L316 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ElementCollection.hideFromAll | hideFromAll(this: ElementCollection<Piece<BaseGame>>) {
for (const el of this) {
el._visible = {default: false};
}
} | /**
* Hide this element from all players
* @category Visibility
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element-collection.ts#L322-L326 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ElementCollection.hideFrom | hideFrom(this: ElementCollection<Piece<BaseGame>>, ...player: Player[] | number[]) {
if (typeof player[0] !== 'number') player = (player as Player[]).map(p => p.position);
for (const el of this) {
if (el._visible?.default === false && !el._visible.except) continue;
if (el._visible === undefined || e... | /**
* Hide these elements from the given players without changing it's visibility to
* any other players.
* @category Visibility
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element-collection.ts#L333-L347 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ElementCollection.sortBy | sortBy<E extends T>(key: Sorter<E> | Sorter<E>[], direction?: "asc" | "desc") {
const rank = (e: E, k: Sorter<E>) => typeof k === 'function' ? k(e) : e[k as keyof E]
const [up, down] = direction === 'desc' ? [-1, 1] : [1, -1];
return this.sort((a, b) => {
const keys = key instanceof Array ? key : [key... | /**
* Sorts this collection by some {@link Sorter}.
* @category Structure
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element-collection.ts#L353-L366 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ElementCollection.sortedBy | sortedBy(key: Sorter<T> | (Sorter<T>)[], direction: "asc" | "desc" = "asc") {
return (this.slice(0, this.length) as this).sortBy(key, direction);
} | /**
* Returns a copy of this collection sorted by some {@link Sorter}.
* @category Structure
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element-collection.ts#L372-L374 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ElementCollection.sum | sum(key: ((e: T) => number) | (keyof {[K in keyof T]: T[K] extends number ? never: K})) {
return this.reduce((sum, n) => sum + (typeof key === 'function' ? key(n) : n[key] as unknown as number), 0);
} | /**
* Returns the sum of all elements in this collection measured by a provided key
* @category Queries
*
* @example
* deck.create(Card, '2', { pips: 2 });
* deck.create(Card, '3', { pips: 3 });
* deck.all(Card).sum('pips'); // => 5
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element-collection.ts#L385-L387 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ElementCollection.withHighest | withHighest(...attributes: Sorter<T>[]): T | undefined {
return this.sortedBy(attributes, 'desc')[0];
} | /**
* Returns the element in this collection with the highest value of the
* provided key(s).
* @category Queries
*
* @param attributes - any number of {@link Sorter | Sorter's} used for
* comparing. If multiple are provided, subsequent ones are used to break ties
* on earlier ones.
*
* @exam... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element-collection.ts#L404-L406 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ElementCollection.withLowest | withLowest(...attributes: Sorter<T>[]): T | undefined {
return this.sortedBy(attributes, 'asc')[0];
} | /**
* Returns the element in this collection with the lowest value of the
* provided key(s).
* @category Queries
*
* @param attributes - any number of {@link Sorter | Sorter's} used for
* comparing. If multiple are provided, subsequent ones are used to break ties
* on earlier ones.
*
* @examp... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element-collection.ts#L423-L425 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ElementCollection.max | max<K extends number | string>(key: {[K2 in keyof T]: T[K2] extends K ? K2 : never}[keyof T] | ((t: T) => K)): K | undefined {
const el = this.sortedBy(key, 'desc')[0];
if (!el) return;
return typeof key === 'function' ? key(el) : el[key] as K;
} | /**
* Returns the highest value of the provided key(s) found on any element in
* this collection.
* @category Queries
*
* @param key - a {@link Sorter | Sorter's} used for comparing and extracting
* the max.
*
* @example
* army.create(Soldier, 'a', { strength: 2, initiative: 3 });
* army.c... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element-collection.ts#L441-L445 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ElementCollection.min | min<K extends number | string>(key: {[K2 in keyof T]: T[K2] extends K ? K2 : never}[keyof T] | ((t: T) => K)): K | undefined {
const el = this.sortedBy(key, 'asc')[0]
if (!el) return;
return typeof key === 'function' ? key(el) : el[key] as K;
} | /**
* Returns the lowest value of the provided key(s) found on any element in
* this collection.
* @category Queries
*
* @param key - a {@link Sorter | Sorter's} used for comparing and extracting
* the minimum.
*
* @example
* army.create(Soldier, 'a', { strength: 2, initiative: 3 });
* arm... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element-collection.ts#L461-L465 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ElementCollection.areAllEqual | areAllEqual(key: keyof T): boolean {
if (this.length === 0) return true;
return this.every(el => el[key] === this[0][key]);
} | /**
* Returns whether all elements in this collection have the same value for key.
* @category Queries
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element-collection.ts#L471-L474 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ElementCollection.remove | remove() {
for (const el of this) {
if ('isSpace' in el) throw Error('cannot move Space');
(el as unknown as Piece<Game>).remove();
}
} | /**
* Remove all elements in this collection from the playing area and place them
* into {@link Game#pile}
* @category Structure
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element-collection.ts#L481-L486 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ElementCollection.putInto | putInto(to: GameElement, options?: {position?: number, fromTop?: number, fromBottom?: number}) {
if (this.some(el => el.hasMoved()) || to.hasMoved()) to.game.addDelay();
for (const el of this) {
if ('isSpace' in el) throw Error('cannot move Space');
(el as unknown as Piece<Game>).putInto(to, options... | /**
* Move all pieces in this collection into another element. See {@link Piece#putInto}.
* @category Structure
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element-collection.ts#L492-L498 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ElementCollection.layout | layout(
applyTo: T['_ui']['layouts'][number]['applyTo'],
attributes: Partial<GameElement['_ui']['layouts'][number]['attributes']>
) {
for (const el of this) el.layout(applyTo, attributes);
} | /**
* Apply a layout to some of the elements directly contained within the elements
* in this collection. See {@link GameElement#layout}
* @category UI
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element-collection.ts#L507-L512 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ElementCollection.configureLayout | configureLayout(
attributes: Partial<GameElement['_ui']['layouts'][number]['attributes']>
) {
for (const el of this) el.configureLayout(attributes);
} | /**
* Configure the layout for all elements contained within this collection. See
* {@link GameElement#configureLayout}
* @category UI
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element-collection.ts#L520-L524 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | ElementCollection.appearance | appearance(appearance: ElementUI<T>['appearance']) {
for (const el of this) el.appearance(appearance);
} | /**
* Define the appearance of the elements in this collection. Any values
* provided override previous ones. See {@link GameElement#appearance}.
* @category UI
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element-collection.ts#L531-L533 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameElement.constructor | constructor(ctx: Partial<ElementContext>) {
this._ctx = ctx as ElementContext;
this._ctx.classRegistry ??= [];
if (!ctx.top) {
this._ctx.top = this as unknown as GameElement;
this._ctx.sequence = 0;
}
if (!this._ctx.namedSpaces) {
this._ctx.uniqueNames = {};
this._ctx.namedSp... | /**
* Do not use the constructor directly. Instead Call {@link
* GameElement#create} or {@link GameElement#createMany} on the element in
* which you want to create a new element.
* @category Structure
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L319-L343 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameElement.toString | toString() {
return this.name || this.constructor.name.replace(/([a-z0-9])([A-Z])/g, "$1 $2");
} | /**
* String used for representng this element in game messages when the object
* is passed directly, e.g. when taking the choice directly from a
* chooseOnBoard choice.
* @category Structure
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L351-L353 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameElement.isAdjacentTo | isAdjacentTo(element: GameElement): boolean {
const graph = this.containerWithProperty('isAdjacent');
if (!graph) return false;
return (graph as AdjacencySpace<G>).isAdjacent(this, element);
} | /**
* If this element is adjacent to some other element, using the nearest
* containing space that has an adjacency map.
* @category Adjacency
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L514-L518 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameElement.distanceTo | distanceTo(element: GameElement): number {
const graph = this.containerWithProperty('distanceBetween');
if (!graph) return Infinity;
return (graph as ConnectedSpaceMap<G>).distanceBetween(this, element);
} | /**
* Finds the shortest distance between two spaces
* @category Adjacency
*
* @param element - {@link element} to measure distance to
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L526-L530 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameElement.setOrder | setOrder(order: typeof this._t.order) {
this._t.order = order;
} | /**
* Set this class to use a different ordering style.
* @category Structure
* @param order - ordering style
* - "normal": Elements placed into this element are put at the end of the
* list (default)
* - "stacking": Used primarily for stacks of cards. Elements placed into this
* element are pu... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L573-L575 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameElement.container | container<T extends GameElement>(className?: ElementClass<T>): T | undefined {
if (!className) return this._t.parent as T;
if (this._t.parent) return this._t.parent instanceof className ?
this._t.parent as T:
this._t.parent.container(className);
} | /**
* Returns this elements parent.
* @category Queries
* @param className - If provided, searches up the parent tree to find the first
* matching element. E.g. if a Token is placed on a Card in a players
* Tableau. calling `token.container(Tableau)` can be used to find the
* grandparent.
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L585-L590 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameElement.containerWithProperty | containerWithProperty(property: string, value?: any): GameElement | undefined {
const parent = this._t.parent;
if (parent) return property in parent && (value === undefined || parent[property as keyof typeof parent] === value) ?
parent:
parent.containerWithProperty(property, value);
} | /**
* Returns this elements containing element that also has a given property.
* @category Queries
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L596-L601 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameElement.isEmpty | isEmpty() {
return !this._t.children.length;
} | /**
* Returns whether this element has no elements placed within it.
* @category Structure
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L607-L609 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameElement.sortBy | sortBy(key: GenericSorter | GenericSorter[], direction?: "asc" | "desc"): ElementCollection<GameElement<G, P>> {
return this._t.children.sortBy(key as Sorter<GameElement> | Sorter<GameElement>[], direction) as ElementCollection<GameElement<G, P>>
} | /**
* Sorts the elements directly contained within this element by some {@link Sorter}.
* @category Structure
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L615-L617 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameElement.shuffle | shuffle() {
const refs = this.childRefsIfObscured();
shuffleArray(this._t.children, this._ctx.gameManager?.random || Math.random);
if (refs) this.assignChildRefs(refs);
} | /**
* re-orders the elements directly contained within this element randomly.
* @category Structure
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L623-L627 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameElement.owner | get owner(): P | undefined {
return this.player !== undefined ? this.player as P : this._t.parent?.owner as P;
} | /**
* The player that owns this element, or the first element that contains this
* element searching up through the parent hierarchy. This is related to, but
* different than {@link player}. E.g. if a standard playing card is in a
* player's hand, typically the `hand.player` will be assigned to that player
... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L638-L640 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameElement.mine | get mine() {
if (!this._ctx.player) return false; // throw?
return this.owner === this._ctx.player;
} | /**
* Whether this element belongs to the player viewing the game. A player is
* considered to be currently viewing the game if this is called in the
* context of an action taken by a given player (during an action taken by a
* player or while the game is viewed by a given player.) It is an error to
* ca... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L653-L656 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameElement.create | create<T extends GameElement>(className: ElementClass<T>, name: string, attributes?: ElementAttributes<T>): T {
if (this._ctx.gameManager?.phase === 'started') throw Error('Game elements cannot be created once game has started.');
const el = this.createElement(className, name, attributes);
el._t.parent = th... | /**
* Create an element inside this element. This can only be called during the
* game setup (see {@link createGame}. Any game elements that are required
* must be created before the game starts. Elements that only appear later in
* the game can be created inside the {@link Game#pile} or made invisible.
... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L674-L702 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameElement.createMany | createMany<T extends GameElement>(n: number, className: ElementClass<T>, name: string, attributes?: ElementAttributes<T> | ((n: number) => ElementAttributes<T>)): ElementCollection<T> {
return new ElementCollection<T>(...times(n, i => this.create(className, name, typeof attributes === 'function' ? attributes(i) : a... | /**
* Create n elements inside this element of the same class. This can only be
* called during the game setup (see {@link createGame}. Any game elements
* that are required must be created before the game starts. Elements that
* only appear later in the game can be created inside the {@link Game#pile}
*... | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L721-L723 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameElement.createElement | createElement<T extends GameElement>(className: ElementClass<T>, name: string, attrs?: ElementAttributes<T>): T {
if (!this._ctx.classRegistry.includes(className)) {
this._ctx.classRegistry.push(className);
}
const el = new className(this._ctx);
el.game = this.game;
el.name = name;
Object.... | /**
* Base element creation method
* @internal
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L729-L739 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameElement.destroy | destroy() {
if (this._ctx.gameManager?.phase === 'started') throw Error('Game elements cannot be destroy once game has started.');
const position = this.position();
this._t.parent?._t.children.splice(position, 1);
} | /**
* Permanently remove an element. This can only be done while defining the
* game, and is usually only useful when creating groups of elements, such as
* {@link createMany} or {@link createGrid} where some of the created elements
* are not needed.
* @category Structure
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L748-L752 | d701cb628e876cbe59171e837862ee09c925d6c9 |
boardzilla-core | github_2023 | boardzilla | typescript | GameElement.rotation | get rotation() {
if (this._rotation === undefined) return 0;
return (this._rotation % 360 + 360) % 360;
} | /**
* Rotation of element if set, normalized to 0-359 degrees
* @category Structure
*/ | https://github.com/boardzilla/boardzilla-core/blob/d701cb628e876cbe59171e837862ee09c925d6c9/src/board/element.ts#L758-L761 | d701cb628e876cbe59171e837862ee09c925d6c9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.