|
| 1 | +extends Node |
| 2 | + |
| 3 | +enum LEVEL { |
| 4 | + TRACE = 10, |
| 5 | + DEBUG = 20, |
| 6 | + INFO = 30, |
| 7 | + WARN = 40, |
| 8 | + ERROR = 50, |
| 9 | + FATAL = 60, |
| 10 | +}; |
| 11 | + |
| 12 | +var _js_available := OS.has_feature("JavaScript") |
| 13 | +var GDQUEST: JavaScriptObject |
| 14 | + |
| 15 | +func write(level: int, properties: Dictionary, message: String) -> void: |
| 16 | + if not _js_available: |
| 17 | + prints({ "properties": properties, "message": message }) |
| 18 | + return |
| 19 | + var props = JavaScript.create_object("Object", {}) |
| 20 | + for key in properties: |
| 21 | + props[key] = properties[key] |
| 22 | + match(level): |
| 23 | + LEVEL.FATAL: |
| 24 | + # warning-ignore:unsafe_property_access |
| 25 | + GDQUEST.log.fatal(props, message) |
| 26 | + LEVEL.ERROR: |
| 27 | + # warning-ignore:unsafe_property_access |
| 28 | + GDQUEST.log.error(props, message) |
| 29 | + LEVEL.WARN: |
| 30 | + # warning-ignore:unsafe_property_access |
| 31 | + GDQUEST.log.warn(props, message) |
| 32 | + LEVEL.INFO: |
| 33 | + # warning-ignore:unsafe_property_access |
| 34 | + GDQUEST.log.info(props, message) |
| 35 | + LEVEL.DEBUG: |
| 36 | + # warning-ignore:unsafe_property_access |
| 37 | + GDQUEST.log.debug(props, message) |
| 38 | + _: |
| 39 | + # warning-ignore:unsafe_property_access |
| 40 | + GDQUEST.log.trace(props, message) |
| 41 | + |
| 42 | + |
| 43 | +func _init() -> void: |
| 44 | + if not _js_available: |
| 45 | + return |
| 46 | + GDQUEST = JavaScript.get_interface("GDQUEST") |
| 47 | + |
| 48 | + |
| 49 | +func trace(properties: Dictionary, message: String) -> void: |
| 50 | + write(LEVEL.TRACE, properties, message) |
| 51 | + |
| 52 | +func debug(properties: Dictionary, message: String) -> void: |
| 53 | + write(LEVEL.DEBUG, properties, message) |
| 54 | + |
| 55 | +func info(properties: Dictionary, message: String) -> void: |
| 56 | + write(LEVEL.INFO, properties, message) |
| 57 | + |
| 58 | +func warn(properties: Dictionary, message: String) -> void: |
| 59 | + write(LEVEL.WARN, properties, message) |
| 60 | + |
| 61 | +func error(properties: Dictionary, message: String) -> void: |
| 62 | + write(LEVEL.ERROR, properties, message) |
| 63 | + |
| 64 | +func fatal(properties: Dictionary, message: String) -> void: |
| 65 | + write(LEVEL.FATAL, properties, message) |
0 commit comments