summaryrefslogtreecommitdiff
path: root/src/config/configSchema.ts
blob: 6956030c824fb8792971952aef7ed7688810f7d1 (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
174
175
176
177
178
179
180
181
182
183
184
185
186
/**
 * 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"
}

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

// Configuration schema - must match Python CONFIG_SCHEMA
export const CONFIG_SCHEMA: Record<string, ConfigField> = {
  enable_lsfg: {
    name: "enable_lsfg",
    fieldType: ConfigFieldType.BOOLEAN,
    default: true,
    description: "Enables the frame generation layer",
    scriptTemplate: "export ENABLE_LSFG={value}",
    scriptComment: "# export ENABLE_LSFG=1"
  },
  
  multiplier: {
    name: "multiplier",
    fieldType: ConfigFieldType.INTEGER,
    default: 2,
    description: "Traditional FPS multiplier value",
    scriptTemplate: "export LSFG_MULTIPLIER={value}"
  },
  
  flow_scale: {
    name: "flow_scale",
    fieldType: ConfigFieldType.FLOAT,
    default: 0.8,
    description: "Lowers the internal motion estimation resolution",
    scriptTemplate: "export LSFG_FLOW_SCALE={value}"
  },
  
  hdr: {
    name: "hdr",
    fieldType: ConfigFieldType.BOOLEAN,
    default: false,
    description: "Enable HDR mode (only if Game supports HDR)",
    scriptTemplate: "export LSFG_HDR={value}",
    scriptComment: "# export LSFG_HDR=1"
  },
  
  perf_mode: {
    name: "perf_mode",
    fieldType: ConfigFieldType.BOOLEAN,
    default: true,
    description: "Use lighter model for FG",
    scriptTemplate: "export LSFG_PERF_MODE={value}",
    scriptComment: "# export LSFG_PERF_MODE=1"
  },
  
  immediate_mode: {
    name: "immediate_mode",
    fieldType: ConfigFieldType.BOOLEAN,
    default: false,
    description: "Reduce input lag (Experimental, will cause issues in many games)",
    scriptTemplate: "export MESA_VK_WSI_PRESENT_MODE=immediate # - disable vsync",
    scriptComment: "# export MESA_VK_WSI_PRESENT_MODE=immediate # - disable vsync"
  },
  
  disable_vkbasalt: {
    name: "disable_vkbasalt",
    fieldType: ConfigFieldType.BOOLEAN,
    default: true,
    description: "Some plugins add vkbasalt layer, which can break lsfg. Toggling on fixes this",
    scriptTemplate: "export DISABLE_VKBASALT={value}",
    scriptComment: "# export DISABLE_VKBASALT=1"
  },
  
  frame_cap: {
    name: "frame_cap",
    fieldType: ConfigFieldType.INTEGER,
    default: 0,
    description: "Limit base game FPS (0 = disabled)",
    scriptTemplate: "export DXVK_FRAME_RATE={value}",
    scriptComment: "# export DXVK_FRAME_RATE=60"
  }
};

// Type-safe configuration data structure
export interface ConfigurationData {
  enable_lsfg: boolean;
  multiplier: number;
  flow_scale: number;
  hdr: boolean;
  perf_mode: boolean;
  immediate_mode: boolean;
  disable_vkbasalt: boolean;
  frame_cap: 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)[] {
    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));
        }
      }
    });

    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);
  }
}