Config.hx 7.3 KB

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