summaryrefslogtreecommitdiff
path: root/src/config/configSchema.ts
blob: 9b6fc41936e6ffcf8f7d9f5d6a9048d1d1cbfaad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
 * Centralized configuration schema for lsfg-vk frontend.
 * 
 * This mirrors the Python configuration schema to ensure consistency
 * between frontend and backend configuration handling.
 */

// Configuration field type enum
export enum ConfigFieldType {
  BOOLEAN = "boolean",
  INTEGER = "integer",
  FLOAT = "float",
  STRING = "string"
}

// Configuration field definition
export interface ConfigField {
  name: string;
  fieldType: ConfigFieldType;
  default: boolean | number | string;
  description: string;
}

// Configuration schema - must match Python CONFIG_SCHEMA
export const CONFIG_SCHEMA: Record<string, ConfigField> = {
  enable: {
    name: "enable",
    fieldType: ConfigFieldType.BOOLEAN,
    default: true,
    description: "enable/disable lsfg on every game"
  },
  
  dll: {
    name: "dll",
    fieldType: ConfigFieldType.STRING,
    default: "/games/Lossless Scaling/Lossless.dll",
    description: "specify where Lossless.dll is stored"
  },
  
  multiplier: {
    name: "multiplier",
    fieldType: ConfigFieldType.INTEGER,
    default: 2,
    description: "change the fps multiplier"
  },
  
  flow_scale: {
    name: "flow_scale",
    fieldType: ConfigFieldType.FLOAT,
    default: 0.8,
    description: "change the flow scale"
  },
  
  performance_mode: {
    name: "performance_mode",
    fieldType: ConfigFieldType.BOOLEAN,
    default: true,
    description: "toggle performance mode"
  },
  
  hdr_mode: {
    name: "hdr_mode",
    fieldType: ConfigFieldType.BOOLEAN,
    default: false,
    description: "enable hdr in games that support it"
  },
  
  experimental_present_mode: {
    name: "experimental_present_mode",
    fieldType: ConfigFieldType.STRING,
    default: "",
    description: "experimental: override vulkan present mode (empty/fifo/vsync/mailbox/immediate)"
  },
  
  experimental_fps_limit: {
    name: "experimental_fps_limit",
    fieldType: ConfigFieldType.INTEGER,
    default: 0,
    description: "experimental: base framerate cap for dxvk games, before frame multiplier (0 = disabled)"
  }
};

// Type-safe configuration data structure
export interface ConfigurationData {
  enable: boolean;
  dll: string;
  multiplier: number;
  flow_scale: number;
  performance_mode: boolean;
  hdr_mode: boolean;
  experimental_present_mode: string;
  experimental_fps_limit: number;
}

// Centralized configuration manager
export class ConfigurationManager {
  /**
   * Get default configuration values
   */
  static getDefaults(): ConfigurationData {
    const defaults = {} as ConfigurationData;
    Object.values(CONFIG_SCHEMA).forEach(field => {
      (defaults as any)[field.name] = field.default;
    });
    return defaults;
  }

  /**
   * Get ordered list of configuration field names
   */
  static getFieldNames(): string[] {
    return Object.keys(CONFIG_SCHEMA);
  }

  /**
   * Get field type mapping
   */
  static getFieldTypes(): Record<string, ConfigFieldType> {
    return Object.values(CONFIG_SCHEMA).reduce((acc, field) => {
      acc[field.name] = field.fieldType;
      return acc;
    }, {} as Record<string, ConfigFieldType>);
  }

  /**
   * Create ordered arguments array from configuration object
   */
  static createArgsFromConfig(config: ConfigurationData): (boolean | number | string)[] {
    return this.getFieldNames().map(fieldName => 
      config[fieldName as keyof ConfigurationData]
    );
  }

  /**
   * Validate configuration object against schema
   */
  static validateConfig(config: Partial<ConfigurationData>): ConfigurationData {
    const defaults = this.getDefaults();
    const validated = { ...defaults };

    Object.entries(CONFIG_SCHEMA).forEach(([fieldName, fieldDef]) => {
      const value = config[fieldName as keyof ConfigurationData];
      if (value !== undefined) {
        // Type validation
        if (fieldDef.fieldType === ConfigFieldType.BOOLEAN) {
          (validated as any)[fieldName] = Boolean(value);
        } else if (fieldDef.fieldType === ConfigFieldType.INTEGER) {
          (validated as any)[fieldName] = parseInt(String(value), 10);
        } else if (fieldDef.fieldType === ConfigFieldType.FLOAT) {
          (validated as any)[fieldName] = parseFloat(String(value));
        } else if (fieldDef.fieldType === ConfigFieldType.STRING) {
          (validated as any)[fieldName] = String(value);
        }
      }
    });

    return validated;
  }

  /**
   * Get configuration field definition
   */
  static getFieldDef(fieldName: string): ConfigField | undefined {
    return CONFIG_SCHEMA[fieldName];
  }

  /**
   * Get all field definitions
   */
  static getAllFieldDefs(): ConfigField[] {
    return Object.values(CONFIG_SCHEMA);
  }
}