1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: deprecate short struct init (#10842)

This commit is contained in:
Daniel Däschle
2021-07-20 10:17:08 +02:00
committed by GitHub
parent dc045806f9
commit ad3835b598
85 changed files with 234 additions and 238 deletions

View File

@@ -127,8 +127,8 @@ struct Perf {
mut:
frame int
frame_old int
frame_sw time.StopWatch = time.new_stopwatch({})
second_sw time.StopWatch = time.new_stopwatch({})
frame_sw time.StopWatch = time.new_stopwatch()
second_sw time.StopWatch = time.new_stopwatch()
}
struct Pos {
@@ -450,7 +450,7 @@ fn (p Prediction) str() string {
fn (mut app App) ai_move() {
mut predictions := [4]Prediction{}
mut is_valid := false
think_watch := time.new_stopwatch({})
think_watch := time.new_stopwatch()
for move in possible_moves {
move_idx := int(move)
predictions[move_idx].move = move
@@ -499,21 +499,21 @@ fn (mut app App) ai_move() {
fn (app &App) label_format(kind LabelKind) gx.TextCfg {
match kind {
.points {
return {
return gx.TextCfg{
color: if app.state in [.over, .victory] { gx.white } else { app.theme.text_color }
align: .left
size: app.ui.font_size / 2
}
}
.moves {
return {
return gx.TextCfg{
color: if app.state in [.over, .victory] { gx.white } else { app.theme.text_color }
align: .right
size: app.ui.font_size / 2
}
}
.tile {
return {
return gx.TextCfg{
color: app.theme.text_color
align: .center
vertical_align: .middle
@@ -521,7 +521,7 @@ fn (app &App) label_format(kind LabelKind) gx.TextCfg {
}
}
.victory {
return {
return gx.TextCfg{
color: app.theme.victory_color
align: .center
vertical_align: .middle
@@ -529,7 +529,7 @@ fn (app &App) label_format(kind LabelKind) gx.TextCfg {
}
}
.game_over {
return {
return gx.TextCfg{
color: app.theme.game_over_color
align: .center
vertical_align: .middle
@@ -537,7 +537,7 @@ fn (app &App) label_format(kind LabelKind) gx.TextCfg {
}
}
.score_end {
return {
return gx.TextCfg{
color: gx.white
align: .center
vertical_align: .middle
@@ -823,8 +823,8 @@ fn on_event(e &gg.Event, mut app App) {
.touches_began {
if e.num_touches > 0 {
t := e.touches[0]
app.touch.start = {
pos: {
app.touch.start = Touch{
pos: Pos{
x: int(t.pos_x / app.ui.dpi_scale)
y: int(t.pos_y / app.ui.dpi_scale)
}
@@ -835,8 +835,8 @@ fn on_event(e &gg.Event, mut app App) {
.touches_ended {
if e.num_touches > 0 {
t := e.touches[0]
app.touch.end = {
pos: {
app.touch.end = Touch{
pos: Pos{
x: int(t.pos_x / app.ui.dpi_scale)
y: int(t.pos_y / app.ui.dpi_scale)
}
@@ -846,8 +846,8 @@ fn on_event(e &gg.Event, mut app App) {
}
}
.mouse_down {
app.touch.start = {
pos: {
app.touch.start = Touch{
pos: Pos{
x: int(e.mouse_x / app.ui.dpi_scale)
y: int(e.mouse_y / app.ui.dpi_scale)
}
@@ -855,8 +855,8 @@ fn on_event(e &gg.Event, mut app App) {
}
}
.mouse_up {
app.touch.end = {
pos: {
app.touch.end = Touch{
pos: Pos{
x: int(e.mouse_x / app.ui.dpi_scale)
y: int(e.mouse_y / app.ui.dpi_scale)
}

View File

@@ -32,5 +32,5 @@ pub fn (mut particle Particle) tick(mut rocket Rocket, mut ctx gg.Context) {
particle.pos += particle.vel
particle.draw(mut ctx)
particle.accel = {}
particle.accel = Vector{}
}

View File

@@ -39,7 +39,7 @@ pub fn (mut rocket Rocket) tick(mut ctx gg.Context) {
rocket.pos += rocket.vel
rocket.draw(mut ctx)
rocket.accel = {}
rocket.accel = Vector{}
}
for mut particle in rocket.particles {
@@ -50,10 +50,10 @@ pub fn (mut rocket Rocket) tick(mut ctx gg.Context) {
pub fn new_rocket() Rocket {
return Rocket{
color: random_color()
pos: {
pos: Vector{
x: rand.f32_in_range(50, get_params().width - 50)
}
vel: {
vel: Vector{
x: rand.f32_in_range(-1.5, 1.5)
y: rand.f32_in_range(5, 7)
}

View File

@@ -21,7 +21,7 @@ pub fn random_vector_in_circle() Vector {
theta := rand.f32n(2 * math.pi)
y := rand.f32()
return {
return Vector{
x: f32(y * math.sin(theta))
y: f32(y * math.cos(theta))
}

View File

@@ -48,7 +48,7 @@ fn init(mut app App) {
// worker simulates a workload. This should be run in a separate thread.
fn worker(mut app App) {
stopwatch := time.new_stopwatch({})
stopwatch := time.new_stopwatch()
mut elapsed := stopwatch.elapsed()
// Do heavy operations here - like invoking a path finding algorithm, load an image or similar.
for {

View File

@@ -3,7 +3,7 @@ import math
import sokol.audio
const (
sw = time.new_stopwatch({})
sw = time.new_stopwatch()
sw_start_ms = sw.elapsed().milliseconds()
)

View File

@@ -20,7 +20,7 @@ mut:
}
fn random_color() tui.Color {
return {
return tui.Color{
r: byte(rand.intn(256))
g: byte(rand.intn(256))
b: byte(rand.intn(256))
@@ -32,7 +32,7 @@ fn event(e &tui.Event, x voidptr) {
match e.typ {
.mouse_down {
app.is_drag = true
app.cur_rect = {
app.cur_rect = Rect{
c: random_color()
x: e.x
y: e.y

View File

@@ -156,20 +156,20 @@ fn event(event &ui.Event, x voidptr) {
app.is_dragging = false
}
.mouse_drag {
app.mouse_pos = {
app.mouse_pos = Point{
x: event.x
y: event.y
}
app.paint(event)
}
.mouse_move {
app.mouse_pos = {
app.mouse_pos = Point{
x: event.x
y: event.y
}
}
.mouse_scroll {
app.mouse_pos = {
app.mouse_pos = Point{
x: event.x
y: event.y
}

View File

@@ -147,9 +147,9 @@ fn (b Buffer) view(from int, to int) View {
}
}
raw := lines.join('\n')
return {
return View{
raw: raw.replace('\t', strings.repeat(` `, b.tab_width))
cursor: {
cursor: Cursor{
pos_x: x
pos_y: b.cursor.pos_y
}

View File

@@ -60,7 +60,7 @@ fn (mut v Vec) randomize(min_x int, min_y int, max_x int, max_y int) {
// part of snake's body representation
struct BodyPart {
mut:
pos Vec = {
pos Vec = Vec{
x: block_size
y: block_size
}
@@ -241,7 +241,7 @@ fn (s Snake) draw() {
// rat representation
struct Rat {
mut:
pos Vec = {
pos Vec = Vec{
x: block_size
y: block_size
}

View File

@@ -119,8 +119,8 @@ mut:
// frame/time counters:
frame int
frame_old int
frame_sw time.StopWatch = time.new_stopwatch({})
second_sw time.StopWatch = time.new_stopwatch({})
frame_sw time.StopWatch = time.new_stopwatch()
second_sw time.StopWatch = time.new_stopwatch()
}
fn remap(v f32, min f32, max f32, new_min f32, new_max f32) f32 {