Config.hx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. package arm;
  2. import haxe.Json;
  3. import haxe.io.Bytes;
  4. import iron.data.Data;
  5. import arm.ui.UITrait;
  6. import arm.render.Inc;
  7. class Config {
  8. public static var raw:TConfig = null;
  9. public static var keymap:Dynamic; // raw.Keymap
  10. public static var configLoaded = false;
  11. public static function load(done:Void->Void) {
  12. try {
  13. Data.getBlob('config.arm', function(blob:kha.Blob) {
  14. configLoaded = true;
  15. raw = Json.parse(blob.toString());
  16. done();
  17. });
  18. }
  19. catch(e:Dynamic) { done(); }
  20. }
  21. public static function save() {
  22. var path = Data.dataPath + 'config.arm';
  23. var bytes = Bytes.ofString(Json.stringify(raw));
  24. #if kha_krom
  25. Krom.fileSaveBytes(path, bytes.getData());
  26. #end
  27. }
  28. // public static function reset() {}
  29. public static function init():TConfig {
  30. if (!configLoaded) {
  31. raw.rp_bloom = true;
  32. raw.rp_gi = false;
  33. raw.rp_motionblur = false;
  34. raw.rp_shadowmap_cube = 0;
  35. raw.rp_shadowmap_cascade = 0;
  36. raw.rp_ssgi = true;
  37. raw.rp_ssr = false;
  38. raw.rp_supersample = 1.0;
  39. }
  40. if (raw.ui_layout == null) raw.ui_layout = 0;
  41. if (raw.undo_steps == null) raw.undo_steps = 4; // Max steps to keep
  42. if (raw.keymap == null) {
  43. raw.keymap = {};
  44. raw.keymap.action_paint = "left";
  45. raw.keymap.action_rotate = "alt+left";
  46. raw.keymap.action_pan = "alt+middle";
  47. raw.keymap.action_zoom = "alt+right";
  48. raw.keymap.action_rotate_light = "shift+middle";
  49. raw.keymap.select_material = "shift+number";
  50. raw.keymap.cycle_layers = "ctrl+tab";
  51. raw.keymap.brush_radius = "f";
  52. raw.keymap.brush_opacity = "shift+f";
  53. raw.keymap.brush_ruler = "shift";
  54. raw.keymap.file_new = "ctrl+n";
  55. raw.keymap.file_open = "ctrl+o";
  56. raw.keymap.file_save = "ctrl+s";
  57. raw.keymap.file_save_as = "ctrl+shift+s";
  58. raw.keymap.edit_undo = "ctrl+z";
  59. raw.keymap.edit_redo = "ctrl+shift+z";
  60. raw.keymap.view_reset = "0";
  61. raw.keymap.view_front = "1";
  62. raw.keymap.view_back = "ctrl+1";
  63. raw.keymap.view_right = "3";
  64. raw.keymap.view_left = "ctrl+3";
  65. raw.keymap.view_top = "7";
  66. raw.keymap.view_bottom = "ctrl+7";
  67. raw.keymap.view_camera_type = "5";
  68. raw.keymap.view_orbit_left = "4";
  69. raw.keymap.view_orbit_right = "6";
  70. raw.keymap.view_orbit_top = "8";
  71. raw.keymap.view_orbit_bottom = "2";
  72. raw.keymap.view_orbit_opposite = "9";
  73. raw.keymap.view_distract_free = "f11";
  74. raw.keymap.tool_brush = "b";
  75. raw.keymap.tool_eraser = "e";
  76. raw.keymap.tool_fill = "g";
  77. raw.keymap.tool_decal = "d";
  78. raw.keymap.tool_text = "t";
  79. raw.keymap.tool_clone = "l";
  80. raw.keymap.tool_blur = "u";
  81. raw.keymap.tool_particle = "p";
  82. raw.keymap.tool_bake = "k";
  83. raw.keymap.tool_colorid = "c";
  84. raw.keymap.tool_picker = "v";
  85. raw.keymap.toggle_2d_view = "shift+tab";
  86. raw.keymap.toggle_node_editor = "tab";
  87. raw.keymap.import_assets = "ctrl+shift+i";
  88. raw.keymap.export_textures = "ctrl+shift+e";
  89. raw.keymap.node_search = "space";
  90. }
  91. keymap = raw.keymap;
  92. return raw;
  93. }
  94. public static function applyConfig() {
  95. var C = Config.raw;
  96. C.rp_ssgi = UITrait.inst.hssgi.selected;
  97. C.rp_ssr = UITrait.inst.hssr.selected;
  98. C.rp_bloom = UITrait.inst.hbloom.selected;
  99. C.rp_gi = UITrait.inst.hvxao.selected;
  100. C.rp_supersample = getSuperSampleSize(UITrait.inst.hsupersample.position);
  101. iron.object.Uniforms.defaultFilter = C.rp_supersample < 1.0 ? kha.graphics4.TextureFilter.PointFilter : kha.graphics4.TextureFilter.LinearFilter;
  102. var current = @:privateAccess kha.graphics4.Graphics2.current;
  103. if (current != null) current.end();
  104. save();
  105. Inc.applyConfig();
  106. if (current != null) current.begin(false);
  107. Context.ddirty = 2;
  108. }
  109. public static inline function getSuperSampleQuality(f:Float):Int {
  110. return f == 0.25 ? 0 :
  111. f == 0.5 ? 1 :
  112. f == 1.0 ? 2 :
  113. f == 1.5 ? 3 :
  114. f == 2.0 ? 4 : 5;
  115. }
  116. public static inline function getSuperSampleSize(i:Int):Float {
  117. return i == 0 ? 0.25 :
  118. i == 1 ? 0.5 :
  119. i == 2 ? 1.0 :
  120. i == 3 ? 1.5 :
  121. i == 4 ? 2.0 : 4.0;
  122. }
  123. public static function getTextureRes():Int {
  124. var resHandle = UITrait.inst.resHandle;
  125. if (resHandle.position == 0) return 128;
  126. if (resHandle.position == 1) return 256;
  127. if (resHandle.position == 2) return 512;
  128. if (resHandle.position == 3) return 1024;
  129. if (resHandle.position == 4) return 2048;
  130. if (resHandle.position == 5) return 4096;
  131. if (resHandle.position == 6) return 8192;
  132. if (resHandle.position == 7) return 16384;
  133. return 0;
  134. }
  135. public static function getTextureResBias():Float {
  136. var resHandle = UITrait.inst.resHandle;
  137. if (resHandle.position == 0) return 16.0;
  138. if (resHandle.position == 1) return 8.0;
  139. if (resHandle.position == 2) return 4.0;
  140. if (resHandle.position == 3) return 2.0;
  141. if (resHandle.position == 4) return 1.5;
  142. if (resHandle.position == 5) return 1.0;
  143. if (resHandle.position == 6) return 0.5;
  144. if (resHandle.position == 7) return 0.25;
  145. return 1.0;
  146. }
  147. public static function getTextureResPos(i:Int):Int {
  148. if (i == 128) return 0;
  149. if (i == 256) return 1;
  150. if (i == 512) return 2;
  151. if (i == 1024) return 3;
  152. if (i == 2048) return 4;
  153. if (i == 4096) return 5;
  154. if (i == 8192) return 6;
  155. if (i == 16384) return 7;
  156. return 0;
  157. }
  158. }
  159. typedef TConfig = {
  160. @:optional var debug_console:Null<Bool>;
  161. @:optional var window_mode:Null<Int>; // window, fullscreen
  162. @:optional var window_w:Null<Int>;
  163. @:optional var window_h:Null<Int>;
  164. @:optional var window_resizable:Null<Bool>;
  165. @:optional var window_maximizable:Null<Bool>;
  166. @:optional var window_minimizable:Null<Bool>;
  167. @:optional var window_vsync:Null<Bool>;
  168. @:optional var window_msaa:Null<Int>;
  169. @:optional var window_scale:Null<Float>;
  170. @:optional var rp_supersample:Null<Float>;
  171. @:optional var rp_shadowmap_cube:Null<Int>; // size
  172. @:optional var rp_shadowmap_cascade:Null<Int>; // size for single cascade
  173. @:optional var rp_ssgi:Null<Bool>;
  174. @:optional var rp_ssr:Null<Bool>;
  175. @:optional var rp_bloom:Null<Bool>;
  176. @:optional var rp_motionblur:Null<Bool>;
  177. @:optional var rp_gi:Null<Bool>;
  178. // Ext
  179. @:optional var version:Null<Int>;
  180. @:optional var plugins:Array<String>;
  181. @:optional var ui_layout:Null<Int>;
  182. @:optional var undo_steps:Null<Int>;
  183. @:optional var keymap:Dynamic; // Map<String, String>
  184. }