Skip to content
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

An option to limit pricelist rewrite #1681

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/classes/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ export const DEFAULTS: JsonOptions = {
},
priceAge: {
maxInSeconds: 28800
},
rewriteFile: {
count: 1
}
},

Expand Down Expand Up @@ -1284,6 +1287,7 @@ interface Pricelist {
autoAddInvalidUnusual?: OnlyEnable;
autoAddPaintedItems?: OnlyEnable;
priceAge?: PriceAge;
rewriteFile?: RewriteFile;
}

interface PartialPriceUpdate extends OnlyEnable {
Expand All @@ -1295,6 +1299,10 @@ interface PriceAge {
maxInSeconds?: number;
}

interface RewriteFile {
count: number;
}

// ------------ Bypass ------------

interface Bypass {
Expand Down
10 changes: 9 additions & 1 deletion src/classes/Pricelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ export default class Pricelist extends EventEmitter {

autoResetPartialPriceBulk: string[] = [];

private priceChangeCounter = 0;

assetidInPricelist: AssetidInPricelist = {};

checkAssetidInPricelistInterval: NodeJS.Timeout;
Expand Down Expand Up @@ -1337,7 +1339,13 @@ export default class Pricelist extends EventEmitter {

private priceChanged(priceKey: string | number, entry: Entry): void {
this.emit('price', priceKey, entry);
this.emit('pricelist', this.prices);

if (++this.priceChangeCounter % this.options.pricelist.rewriteFile.count === 0) {
// reference: https://github.com/Hhanuska/tf2autobot/commit/54c408936cc923d56d525f01726c042a84e1ec75
this.emit('pricelist', this.prices);

this.priceChangeCounter = 0;
}
}

private get getOld(): PricesObject {
Expand Down
14 changes: 13 additions & 1 deletion src/schemas/options-json/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,17 @@ export const optionsSchema: jsonschema.Schema = {
},
required: ['maxInSeconds'],
additionalProperties: false
},
rewriteFile: {
type: 'object',
properties: {
count: {
type: 'integer',
minimum: 1
}
},
required: ['count'],
additionalProperties: false
}
},
required: [
Expand All @@ -703,7 +714,8 @@ export const optionsSchema: jsonschema.Schema = {
'autoAddInvalidItems',
'autoAddInvalidUnusual',
'autoAddPaintedItems',
'priceAge'
'priceAge',
'rewriteFile'
],
additionalProperties: false
},
Expand Down