Skip to content

Commit

Permalink
move the type definitions for Localize Me out of cc-ru's source tree
Browse files Browse the repository at this point in the history
dmitmel committed Feb 1, 2022
1 parent 3020c34 commit 445f69e
Showing 4 changed files with 93 additions and 1 deletion.
1 change: 1 addition & 0 deletions crosscode.d.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
/// <reference types="jquery" />
/// <reference lib="DOM" />

import './type-utils';
import './impact-class-system-correct';
import './impact-core';
import './crosscode-external-scripts';
88 changes: 88 additions & 0 deletions mods/Localize-me.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* eslint-disable @typescript-eslint/naming-convention */

export {};

declare global {
namespace LocalizeMe {
type Resource<T> = T | (() => MaybePromise<T>);
interface TranslationResult {
orig: string;
text: string;
}
type TranslationPack = Record<string, TranslationResult>;

type MapFileFunction = (
url_to_patch: string,
) => string | (() => MaybePromise<TranslationPack | TranslationPackFunction>) | null;
type TranslationPackFunction = (dict_path: string) => TranslationResult;

interface Rectangle {
x: number;
y: number;
width: number;
height: number;
}

interface FontPatchingContextCommon {
char_height: number;
size_index: number;
base_image: ig.Image.Data;
}

interface PrePatchFontContext extends FontPatchingContextCommon {
set_base_image(img: ig.Image.Data): void;
}

interface PatchFontContext extends FontPatchingContextCommon {
patched_base_image: ig.Image.Data;
color: string;
get_char_pos(c: string): Rectangle;
set_char_pos(c: string, pos: Rectangle): void;
recolor_from_base_image(canvas: HTMLCanvasElement): HTMLCanvasElement;
}

interface PatchBaseFontContext extends PatchFontContext {
reserve_char(canvas: HTMLCanvasElement, width: number): Rectangle;
import_from_font(
canvas: HTMLCanvasElement,
ig_font: ig.Font,
start_char: string,
): HTMLCanvasElement;
}
}

namespace ig {
interface LangOptions {
localizeme_global_index?: number;

from_locale?: string;
map_file?: string | (() => MaybePromise<LocalizeMe.MapFileFunction>);
url_prefix?: string;
missing_cb?: (lang_label_or_string: ig.LangLabel.Data | string, dict_path: string) => string;
language?: ig.LangLabel.Data;
text_filter?: (text: string, translation_result: LocalizeMe.TranslationResult) => string;
patch_base_font: (
canvas: HTMLCanvasElement,
context: LocalizeMe.PatchBaseFontContext,
) => ig.Image.Data;
pre_patch_font: (context: LocalizeMe.PrePatchFontContext) => MaybePromise<void>;
number_locale?: string;
format_number?: (
number: number,
precision: number,
suffix: string,
template: string,
) => string;
misc_time_function?: () => string;
flag?: LocalizeMe.Resource<ig.Image.Data | string>;
}
}

interface LocalizeMe {
add_locale(this: this, name: string, options: NullablePartial<ig.LangOptions>): void;

register_locale_chosen(this: this, func: () => void): void;
}

var localizeMe: LocalizeMe;
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": ["*.d.ts", "modules", "modloader", "file-types", "modloader-stdlib"],
"include": ["*.d.ts", "modules", "modloader", "file-types", "modloader-stdlib", "mods"],
"compilerOptions": {
"lib": ["ES6"],
"noEmit": true,
3 changes: 3 additions & 0 deletions type-utils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type MaybePromise<T> = T | Promise<T>;
type NullablePartial<T> = { [P in keyof T]?: T[P] | null };
type Writable<T> = { -readonly [P in keyof T]: T[P] };

0 comments on commit 445f69e

Please sign in to comment.