@drincs/pixi-vn
Version:
Pixi'VN is a npm package that provides various features for creating visual novels.
1 lines • 6.01 kB
Source Map (JSON)
{"version":3,"sources":["../../src/functions/TickerUtility.ts"],"names":[],"mappings":";AAWO,SAAS,uBAAsC,CAAA,IAAA,EAAS,YAAuB,EAAA,WAAA,EAAmC,YAA0C,EAAA;AAC/J,EAAI,IAAA,KAAA,GAAQ,gBAAgB,WAAY,CAAA,KAAA,GAAQ,aAAa,WAAY,CAAA,KAAK,IAAI,WAAY,CAAA,KAAA,CAAA;AAC9F,EAAI,IAAA,IAAA,CAAK,YAAY,CAAM,KAAA,KAAA,CAAA,IACpB,CAAC,WACD,IAAA,IAAA,CAAK,YAAY,CAAA,KAAM,KAC5B,EAAA;AACE,IAAA,OAAA;AAAA,GACJ;AACA,EAAA,IAAI,OAAO,IAAA,CAAK,YAAY,CAAA,KAAM,QAAU,EAAA;AACxC,IAAI,IAAA,WAAA,CAAY,SAAS,QAAU,EAAA;AAC/B,MAAC,KAAa,YAAY,CAAA,GAAI,qBAAqB,IAAK,CAAA,YAAY,GAAG,WAAW,CAAA,CAAA;AAAA,KACtF,MAAA,IACS,WAAY,CAAA,IAAA,KAAS,aAAe,EAAA;AACzC,MAAC,KAAa,YAAY,CAAA,GAAI,0BAA0B,IAAK,CAAA,YAAY,GAAG,WAAW,CAAA,CAAA;AAAA,KAC3F;AAAA,GAIA,MAAA,IAAA,IAAA,CAAK,YAAY,CAAA,KAAM,UACvB,OAAO,IAAA,CAAK,YAAY,CAAA,KAAM,QAC7B,IAAA,IAAA,CAAa,YAAY,CAAA,CAAE,gBAAgB,GAAG,CAAA,IAC9C,IAAa,CAAA,YAAY,CAAE,CAAA,eAAA,CAAgB,GAAG,CAAA,IAC/C,OAAQ,IAAa,CAAA,YAAY,CAAE,CAAA,CAAA,KAAM,YACzC,OAAQ,IAAA,CAAa,YAAY,CAAA,CAAE,MAAM,QAC3C,EAAA;AACE,IAAI,IAAA,WAAA,CAAY,SAAS,QAAU,EAAA;AA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EAA2C,YAAkD,EAAA;AAC5I,EAAI,IAAA,KAAA,GAAQ,gBAAgB,WAAY,CAAA,KAAA,GAAQ,aAAa,WAAY,CAAA,KAAK,IAAI,WAAY,CAAA,KAAA,CAAA;AAC9F,EAAA,IAAI,UAAU,KAAW,CAAA,EAAA;AACrB,IAAA,IAAI,MAAS,GAAA,KAAA,IAAS,WAAY,CAAA,UAAA,GAAa,CAAG,EAAA;AAC9C,MAAO,OAAA,KAAA,CAAA;AAAA,KAEF,MAAA,IAAA,MAAA,GAAS,KAAS,IAAA,WAAA,CAAY,aAAa,CAAG,EAAA;AACnD,MAAO,OAAA,KAAA,CAAA;AAAA,KACX;AAAA,GACJ;AACA,EAAO,OAAA,MAAA,GAAS,SAAS,WAAY,CAAA,UAAA,CAAA;AACzC","file":"TickerUtility.mjs","sourcesContent":["import { ITickerProgrationExponential, ITickerProgrationLinear, TickerProgrationType } from \"../interface/TickerProgrationType\";\n\n/**\n * This function updates the progression of the ticker.\n * For example, if the speed of the ticker is 0.1 and the progression is 0.01, then the speed will be 0.11.\n * @param args The arguments that are passed to the ticker\n * @param propertyName The property name that will be updated \n * @param progression The progression of the ticker\n * @param valueConvert The function that converts the amount and limit of progression\n * @returns \n */\nexport function updateTickerProgression<T extends {}>(args: T, propertyName: keyof T, progression: TickerProgrationType, valueConvert?: (value: number) => number) {\n let limit = valueConvert && progression.limit ? valueConvert(progression.limit) : progression.limit\n if (args[propertyName] === undefined\n || !progression\n || args[propertyName] === limit\n ) {\n return\n }\n if (typeof args[propertyName] === \"number\") {\n if (progression.type === \"linear\") {\n (args as any)[propertyName] = getLinearProgression(args[propertyName], progression)\n }\n else if (progression.type === \"exponential\") {\n (args as any)[propertyName] = getExponentialProgression(args[propertyName], progression)\n }\n }\n // args[propertyName] is { x: number, y: number }\n else if (\n args[propertyName] !== undefined &&\n typeof args[propertyName] === \"object\" &&\n (args as any)[propertyName].haveOwnProperty(\"x\") &&\n (args as any)[propertyName].haveOwnProperty(\"y\") &&\n typeof (args as any)[propertyName].x === \"number\" &&\n typeof (args as any)[propertyName].y === \"number\"\n ) {\n if (progression.type === \"linear\") {\n (args as any)[propertyName].x = getLinearProgression((args as any)[propertyName].x, progression);\n (args as any)[propertyName].y = getLinearProgression((args as any)[propertyName].y, progression)\n }\n else if (progression.type === \"exponential\") {\n (args as any)[propertyName].x = getExponentialProgression((args as any)[propertyName].x, progression);\n (args as any)[propertyName].y = getExponentialProgression((args as any)[propertyName].y, progression)\n }\n }\n}\n\nfunction getLinearProgression(number: number, progression: ITickerProgrationLinear, valueConvert?: (value: number) => number): number {\n let limit = valueConvert && progression.limit ? valueConvert(progression.limit) : progression.limit\n let amt = valueConvert ? valueConvert(progression.amt) : progression.amt\n if (limit !== undefined) {\n if (number > limit && amt > 0) {\n return limit\n }\n else if (number < limit && amt < 0) {\n return limit\n }\n }\n return number + amt\n}\n\nfunction getExponentialProgression(number: number, progression: ITickerProgrationExponential, valueConvert?: (value: number) => number): number {\n let limit = valueConvert && progression.limit ? valueConvert(progression.limit) : progression.limit\n if (limit !== undefined) {\n if (number > limit && progression.percentage > 0) {\n return limit\n }\n else if (number < limit && progression.percentage < 0) {\n return limit\n }\n }\n return number + number * progression.percentage\n}\n"]}