Refactor font paths

Also include some centerline testing and a common theme
This commit is contained in:
Luke Hubmayer-Werner 2021-01-30 23:20:27 +10:30
parent e47ccca7ee
commit 1503d8eb03
16 changed files with 71 additions and 20 deletions

45
FontTesting.gd Normal file
View File

@ -0,0 +1,45 @@
extends Control
var fonts = []
const path = 'res://assets/fonts/'
const font_size = 32
func _ready() -> void:
var dir = Directory.new()
dir.open(path)
dir.list_dir_begin(true, true)
var filename = dir.get_next()
while filename != '':
var file = load(path+filename)
if file is DynamicFontData:
var font := DynamicFont.new()
font.size = font_size
font.font_data = file
fonts.append(font)
filename = dir.get_next()
dir.list_dir_end()
func _draw() -> void:
var teststr := 'abcdefghijklmnopqrstuvwxyz'
var string = teststr.to_upper() + teststr + '!?#$^²°' + 'らりるれろ(笑)'
var x = 100
var y = 20
for font in fonts:
y += 12
var a = font.get_ascent()
var d = font.get_descent()
var bb = font.get_string_size(string)
assert(a+d == bb.y)
var pos = Vector2(x, y+a)
y += bb.y
draw_rect(Rect2(pos, Vector2(bb.x, -a)), Color.red)
draw_rect(Rect2(pos, Vector2(bb.x, d)), Color.blue)
draw_rect(Rect2(pos, Vector2(-32, -font_size)), Color.green)
draw_line(Vector2(x, y-bb.y/2), Vector2(x+bb.x, y-bb.y/2), Color.green, 2)
# draw_line(Vector2(x, y-d-a/2), Vector2(x+bb.x, y-d-a/2), Color.darkgray, 2)
draw_line(Vector2(x, y-d-font_size/2), Vector2(x+bb.x, y-d-font_size/2), Color.darkgray, 2)
draw_rect(Rect2(pos+Vector2.UP*a, Vector2(-8, bb.y)), Color.gray)
draw_string(font, pos, string)
func _process(delta: float) -> void:
update()

11
FontTesting.tscn Normal file
View File

@ -0,0 +1,11 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://FontTesting.gd" type="Script" id=1]
[node name="Control" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

View File

@ -1,15 +1,8 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=7 format=2]
[ext_resource path="res://assets/NotoSans-Regular.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://assets/fonts/NotoSans-Regular.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://scripts/OptionPanel.gd" type="Script" id=2]
[sub_resource type="DynamicFont" id=1]
outline_size = 1
outline_color = Color( 0, 0, 0, 1 )
font_data = ExtResource( 1 )
[sub_resource type="Theme" id=2]
default_font = SubResource( 1 )
[ext_resource path="res://default.theme" type="Theme" id=3]
[sub_resource type="DynamicFont" id=3]
size = 24
@ -52,7 +45,7 @@ margin_right = 269.0
margin_bottom = 234.0
size_flags_horizontal = 3
size_flags_vertical = 3
theme = SubResource( 2 )
theme = ExtResource( 3 )
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false

View File

@ -1,7 +1,7 @@
[gd_resource type="DynamicFont" load_steps=3 format=2]
[ext_resource path="res://assets/Sniglet-Regular.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://assets/NotoSansJP-Bold.otf" type="DynamicFontData" id=2]
[ext_resource path="res://assets/fonts/Sniglet-Regular.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://assets/fonts/NotoSansJP-Bold.otf" type="DynamicFontData" id=2]
[resource]
size = 36

View File

@ -1,6 +1,6 @@
[gd_resource type="DynamicFont" load_steps=2 format=2]
[ext_resource path="res://assets/Sniglet-Regular.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://assets/fonts/Sniglet-Regular.ttf" type="DynamicFontData" id=1]
[resource]
size = 48

View File

@ -1,7 +1,7 @@
[gd_resource type="DynamicFont" load_steps=3 format=2]
[ext_resource path="res://assets/NotoSans-Regular.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://assets/NotoSansJP-Regular.otf" type="DynamicFontData" id=2]
[ext_resource path="res://assets/fonts/NotoSans-Regular.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://assets/fonts/NotoSansJP-Regular.otf" type="DynamicFontData" id=2]
[resource]
size = 96

View File

@ -1,7 +1,7 @@
[gd_resource type="DynamicFont" load_steps=3 format=2]
[ext_resource path="res://assets/NotoSans-Regular.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://assets/NotoSansJP-Regular.otf" type="DynamicFontData" id=2]
[ext_resource path="res://assets/fonts/NotoSans-Regular.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://assets/fonts/NotoSansJP-Regular.otf" type="DynamicFontData" id=2]
[resource]
size = 32

View File

@ -1,6 +1,6 @@
[gd_resource type="DynamicFont" load_steps=2 format=2]
[ext_resource path="res://assets/NotoSans-Regular.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://assets/fonts/NotoSans-Regular.ttf" type="DynamicFontData" id=1]
[resource]
size = 32

BIN
default.theme Normal file

Binary file not shown.

View File

@ -1,12 +1,14 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=5 format=2]
[ext_resource path="res://RadialGame.tscn" type="PackedScene" id=1]
[ext_resource path="res://scripts/TouchInput.gd" type="Script" id=2]
[ext_resource path="res://default.theme" type="Theme" id=3]
[ext_resource path="res://OptionPanel.tscn" type="PackedScene" id=13]
[node name="main" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
theme = ExtResource( 3 )
__meta__ = {
"_edit_use_anchors_": false
}