examples: clean file path usage in the examples, move all the fonts in the common assets folder (#12736)

pull/12743/head
penguindark 2021-12-06 08:53:46 +01:00 committed by GitHub
parent 6f5d952d8f
commit 89eb5425cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 19 additions and 11 deletions

View File

@ -910,7 +910,7 @@ fn (mut app App) showfps() {
fn main() { fn main() {
mut app := &App{} mut app := &App{}
app.new_game() app.new_game()
mut font_path := os.resource_abs_path(os.join_path('../assets/fonts/', 'RobotoMono-Regular.ttf')) mut font_path := os.resource_abs_path(os.join_path('..', 'assets', 'fonts', 'RobotoMono-Regular.ttf'))
$if android { $if android {
font_path = 'fonts/RobotoMono-Regular.ttf' font_path = 'fonts/RobotoMono-Regular.ttf'
} }

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -152,7 +152,7 @@ fn on_init(mut app App) {
[console] [console]
fn main() { fn main() {
println("Press 'q' to quit.") println("Press 'q' to quit.")
mut font_path := os.resource_abs_path(os.join_path('../assets/fonts/', 'RobotoMono-Regular.ttf')) mut font_path := os.resource_abs_path(os.join_path('..', 'assets', 'fonts', 'RobotoMono-Regular.ttf'))
$if android { $if android {
font_path = 'fonts/RobotoMono-Regular.ttf' font_path = 'fonts/RobotoMono-Regular.ttf'
} }

View File

@ -96,7 +96,7 @@ fn (mut app App) resize() {
// is needed for easier diagnostics on windows // is needed for easier diagnostics on windows
[console] [console]
fn main() { fn main() {
mut font_path := os.resource_abs_path(os.join_path('../assets/fonts/', 'RobotoMono-Regular.ttf')) mut font_path := os.resource_abs_path(os.join_path('..', 'assets', 'fonts', 'RobotoMono-Regular.ttf'))
$if android { $if android {
font_path = 'fonts/RobotoMono-Regular.ttf' font_path = 'fonts/RobotoMono-Regular.ttf'
} }

View File

@ -177,7 +177,7 @@ fn main() {
mut app := &App{ mut app := &App{
gg: 0 gg: 0
} }
mut font_path := os.resource_abs_path(os.join_path('../assets/fonts/', 'RobotoMono-Regular.ttf')) mut font_path := os.resource_abs_path(os.join_path('..', 'assets', 'fonts', 'RobotoMono-Regular.ttf'))
$if android { $if android {
font_path = 'fonts/RobotoMono-Regular.ttf' font_path = 'fonts/RobotoMono-Regular.ttf'
} }

View File

@ -18,7 +18,7 @@ mut:
} }
fn main() { fn main() {
mut font_path := os.resource_abs_path(os.join_path('../assets/fonts/', 'RobotoMono-Regular.ttf')) mut font_path := os.resource_abs_path(os.join_path('..', 'assets', 'fonts', 'RobotoMono-Regular.ttf'))
mut app := &App{ mut app := &App{
gg: 0 gg: 0
} }

View File

@ -29,7 +29,8 @@ fn main() {
user_data: app user_data: app
init_fn: init_images init_fn: init_images
) )
app.image = app.gg.create_image(os.resource_abs_path('logo.png')) mut logo_path := os.resource_abs_path(os.join_path('..', 'assets', 'logo.png'))
app.image = app.gg.create_image(logo_path)
app.gg.run() app.gg.run()
} }

View File

@ -81,7 +81,8 @@ fn main() {
} }
fn init_images(mut app App) { fn init_images(mut app App) {
app.image = app.gg.create_image(os.resource_abs_path('logo.png')) mut logo_path := os.resource_abs_path(os.join_path('..', 'assets', 'logo.png'))
app.image = app.gg.create_image(logo_path)
} }
fn frame(mut app App) { fn frame(mut app App) {

View File

@ -12,6 +12,7 @@ mut:
font_normal int font_normal int
} }
[console]
fn main() { fn main() {
mut color_action := C.sg_color_attachment_action{ mut color_action := C.sg_color_attachment_action{
action: gfx.Action(C.SG_ACTION_CLEAR) action: gfx.Action(C.SG_ACTION_CLEAR)
@ -46,7 +47,9 @@ fn init(mut state AppState) {
C.sgl_setup(s) C.sgl_setup(s)
state.fons = sfons.create(512, 512, 1) state.fons = sfons.create(512, 512, 1)
// or use DroidSerif-Regular.ttf // or use DroidSerif-Regular.ttf
if bytes := os.read_bytes(os.resource_abs_path('../assets/fonts/RobotoMono-Regular.ttf')) { if bytes := os.read_bytes(os.resource_abs_path(os.join_path('..', 'assets', 'fonts',
'RobotoMono-Regular.ttf')))
{
println('loaded font: $bytes.len') println('loaded font: $bytes.len')
state.font_normal = C.fonsAddFontMem(state.fons, c'sans', bytes.data, bytes.len, state.font_normal = C.fonsAddFontMem(state.fons, c'sans', bytes.data, bytes.len,
false) false)

View File

@ -61,6 +61,7 @@ mut:
inited bool inited bool
} }
[console]
fn main() { fn main() {
mut color_action := C.sg_color_attachment_action{ mut color_action := C.sg_color_attachment_action{
action: gfx.Action(C.SG_ACTION_CLEAR) action: gfx.Action(C.SG_ACTION_CLEAR)
@ -99,7 +100,9 @@ fn init(user_data voidptr) {
C.sgl_setup(s) C.sgl_setup(s)
state.fons = sfons.create(512, 512, 1) state.fons = sfons.create(512, 512, 1)
// or use DroidSerif-Regular.ttf // or use DroidSerif-Regular.ttf
if bytes := os.read_bytes(os.resource_abs_path('../assets/fonts/RobotoMono-Regular.ttf')) { if bytes := os.read_bytes(os.resource_abs_path(os.join_path('..', 'assets', 'fonts',
'RobotoMono-Regular.ttf')))
{
println('loaded font: $bytes.len') println('loaded font: $bytes.len')
state.font_normal = C.fonsAddFontMem(state.fons, c'sans', bytes.data, bytes.len, state.font_normal = C.fonsAddFontMem(state.fons, c'sans', bytes.data, bytes.len,
false) false)

View File

@ -11,8 +11,8 @@ const (
win_height = 700 win_height = 700
bg_color = gx.white bg_color = gx.white
font_paths = [ font_paths = [
os.resource_abs_path('Imprima-Regular.ttf'), os.resource_abs_path(os.join_path('..', 'assets', 'fonts', 'Imprima-Regular.ttf')),
os.resource_abs_path('Graduate-Regular.ttf'), os.resource_abs_path(os.join_path('..', 'assets', 'fonts', 'Graduate-Regular.ttf')),
] ]
) )