class_name ScaleFields extends RefCounted ## Small shared pieces for scale values (Scales) in the inspector: a value's ## steps, a dropdown of steps, and a step written as a rule literal. ## The steps of board value `v` ("@climate") when a scale card declares it, ## else []. static func steps_of(main: Main, v: String) -> Array[String]: var card := BuilderScales.card_for(v, main.data if main else null) return card.steps if card else ([] as Array[String]) ## A dropdown of `steps` with `current` selected (matched without caring about ## capitals). A `current` that isn't one of the steps is listed last, marked, ## so nothing is lost. `on_pick` gets the chosen step's name. static func step_dropdown(steps: Array, current: String, on_pick: Callable) -> OptionButton: var items: Array = steps.duplicate() var at := Scales.position_of(steps, current) - 1 if current != "" else -1 if at < 0 and current != "": items.append("%s (not a step)" % current) at = items.size() - 1 var dd := InspectorKit.dropdown(items, at) dd.tooltip_text = "Pick a step" dd.item_selected.connect(func(k: int) -> void: if k < steps.size(): on_pick.call(str(steps[k])) ) return dd ## The steps a new scale card gets (RollTable.create's). static func default_steps() -> Array[String]: return RollTable.create(RollTable.KIND_VARIABLE, "", "", RollTable.VAR_SCALE).steps ## A step as a starting value: the name as it is when it reads as plain words, ## else quoted ("Semi-arid" has a dash, so it is "\"Semi-arid\""). static func initial_text(step: String) -> String: return step if RollTable._looks_literal(step) else Builder.quote(step)