## R2: renders the application icon, assets/icons/app/tidewall.svg (written by hand), ## to the PNG sizes desktops ask for: assets/icons/app/tidewall-.png. Deterministic, ## so `make app-icon` after editing the SVG and commit what changes. ## ## tools/godot.sh --script res://tools/app_icon.gd [-- --out=DIR] extends SceneTree const SOURCE: String = "res://assets/icons/app/tidewall.svg" const SIZES: Array[int] = [16, 24, 32, 48, 64, 128, 256, 512] ## The SVG's own width and height. const SVG_SIDE: float = 256.0 func _init() -> void: var out: String = "res://assets/icons/app" for arg: String in OS.get_cmdline_user_args(): if arg.begins_with("--out="): out = arg.get_slice("=", 1) var svg: String = FileAccess.get_file_as_string(SOURCE) if svg.is_empty(): push_error("app_icon: can't read %s" % SOURCE) quit(1) return DirAccess.make_dir_recursive_absolute(out) for side: int in SIZES: var image: Image = render(svg, side) if image == null: quit(1) return var path: String = "%s/tidewall-%d.png" % [out, side] if image.save_png(path) != OK: push_error("app_icon: can't write %s" % path) quit(1) return print("app_icon: %s" % path) quit(0) ## The icon at `side` pixels square, or null. static func render(svg: String, side: int) -> Image: var image: Image = Image.new() if image.load_svg_from_string(svg, side / SVG_SIDE) != OK: push_error("app_icon: the SVG doesn't load") return null if image.get_width() != side or image.get_height() != side: image.resize(side, side, Image.INTERPOLATE_LANCZOS) image.convert(Image.FORMAT_RGBA8) return image