Skip to content

Commit

Permalink
Refactor SetValue use
Browse files Browse the repository at this point in the history
  • Loading branch information
m110 committed Nov 6, 2022
1 parent bcda8f0 commit bcc14a7
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 43 deletions.
8 changes: 4 additions & 4 deletions archetype/airbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ func NewAirbaseAirplane(w donburi.World, position math.Vec2, faction component.P
t.LocalPosition = position
t.LocalRotation = originalRotation

donburi.SetValue(airplane, component.Sprite, component.SpriteData{
component.Sprite.SetValue(airplane, component.SpriteData{
Image: AirplaneImageByFaction(faction, 0),
Layer: component.SpriteLayerAirUnits,
Pivot: component.SpritePivotCenter,
OriginalRotation: originalRotation,
})

donburi.SetValue(airplane, component.PlayerSelect, component.PlayerSelectData{
component.PlayerSelect.SetValue(airplane, component.PlayerSelectData{
Index: index,
Faction: faction,
})
Expand All @@ -56,7 +56,7 @@ func NewCrosshair(w donburi.World, parent *donburi.Entry) {

transform.AppendChild(parent, crosshair, false)

donburi.SetValue(crosshair, component.Sprite, component.SpriteData{
component.Sprite.SetValue(crosshair, component.SpriteData{
Image: assets.Crosshair,
Layer: component.SpriteLayerGroundUnits,
Pivot: component.SpritePivotCenter,
Expand All @@ -70,7 +70,7 @@ func NewCrosshair(w donburi.World, parent *donburi.Entry) {
),
)

donburi.SetValue(label, component.Label, component.LabelData{
component.Label.SetValue(label, component.LabelData{
Text: "",
Hidden: true,
})
Expand Down
12 changes: 6 additions & 6 deletions archetype/bullet.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ func newPlayerBullet(w donburi.World, position math.Vec2, localRotation float64)
t.LocalPosition = position
t.LocalRotation = originalRotation + localRotation

donburi.SetValue(bullet, component.Velocity, component.VelocityData{
component.Velocity.SetValue(bullet, component.VelocityData{
Velocity: transform.Right(bullet).MulScalar(playerBulletSpeed),
})

donburi.SetValue(bullet, component.Sprite, component.SpriteData{
component.Sprite.SetValue(bullet, component.SpriteData{
Image: image,
Layer: component.SpriteLayerAirUnits,
Pivot: component.SpritePivotCenter,
Expand All @@ -95,7 +95,7 @@ func newPlayerBullet(w donburi.World, position math.Vec2, localRotation float64)

width, height := image.Size()

donburi.SetValue(bullet, component.Collider, component.ColliderData{
component.Collider.SetValue(bullet, component.ColliderData{
Width: float64(width),
Height: float64(height),
Layer: component.CollisionLayerPlayerBullets,
Expand All @@ -119,11 +119,11 @@ func NewEnemyBullet(w donburi.World, position math.Vec2, rotation float64) {
t.LocalPosition = position
t.LocalRotation = rotation

donburi.SetValue(bullet, component.Velocity, component.VelocityData{
component.Velocity.SetValue(bullet, component.VelocityData{
Velocity: transform.Right(bullet).MulScalar(enemyBulletSpeed),
})

donburi.SetValue(bullet, component.Sprite, component.SpriteData{
component.Sprite.SetValue(bullet, component.SpriteData{
Image: image,
Layer: component.SpriteLayerAirUnits,
Pivot: component.SpritePivotCenter,
Expand All @@ -132,7 +132,7 @@ func NewEnemyBullet(w donburi.World, position math.Vec2, rotation float64) {

width, height := image.Size()

donburi.SetValue(bullet, component.Collider, component.ColliderData{
component.Collider.SetValue(bullet, component.ColliderData{
Width: float64(width),
Height: float64(height),
Layer: component.CollisionLayerEnemyBullets,
Expand Down
6 changes: 3 additions & 3 deletions archetype/collectible.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ func NewRandomCollectible(w donburi.World, position math.Vec2) {

transform.Transform.Get(collectible).LocalPosition = position

donburi.SetValue(collectible, component.Sprite, component.SpriteData{
component.Sprite.SetValue(collectible, component.SpriteData{
Image: image,
Layer: component.SpriteLayerCollectibles,
Pivot: component.SpritePivotCenter,
})

width, height := image.Size()
donburi.SetValue(collectible, component.Collider, component.ColliderData{
component.Collider.SetValue(collectible, component.ColliderData{
Width: float64(width),
Height: float64(height),
Layer: component.CollisionLayerCollectibles,
})

donburi.SetValue(collectible, component.Collectible, component.CollectibleData{
component.Collectible.SetValue(collectible, component.CollectibleData{
Type: collectibleType,
})
}
28 changes: 14 additions & 14 deletions archetype/enemy.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewEnemyAirplane(
t.LocalRotation = originalRotation + rotation

image := assets.AirplaneGraySmall
donburi.SetValue(airplane, component.Sprite, component.SpriteData{
component.Sprite.SetValue(airplane, component.SpriteData{
Image: image,
Layer: component.SpriteLayerAirUnits,
Pivot: component.SpritePivotCenter,
Expand All @@ -63,27 +63,27 @@ func NewEnemyAirplane(

width, height := image.Size()

donburi.SetValue(airplane, component.Collider, component.ColliderData{
component.Collider.SetValue(airplane, component.ColliderData{
Width: float64(width),
Height: float64(height),
Layer: component.CollisionLayerAirEnemies,
})

if len(path.Points) > 0 {
donburi.SetValue(airplane, component.AI, component.AIData{
component.AI.SetValue(airplane, component.AIData{
Type: component.AITypeFollowPath,
Speed: speed,
Path: path.Points,
PathLoops: path.Loops,
})
} else {
donburi.SetValue(airplane, component.AI, component.AIData{
component.AI.SetValue(airplane, component.AIData{
Type: component.AITypeConstantVelocity,
Speed: speed,
})
}

donburi.SetValue(airplane, component.Health, component.HealthData{
component.Health.SetValue(airplane, component.HealthData{
Health: 3,
DamageIndicatorTimer: engine.NewTimer(time.Millisecond * 100),
DamageIndicator: newDamageIndicator(w, airplane),
Expand Down Expand Up @@ -117,7 +117,7 @@ func NewEnemyTank(
t.LocalRotation = rotation

image := assets.TankBase
donburi.SetValue(tank, component.Sprite, component.SpriteData{
component.Sprite.SetValue(tank, component.SpriteData{
Image: image,
Layer: component.SpriteLayerGroundUnits,
Pivot: component.SpritePivotCenter,
Expand All @@ -126,27 +126,27 @@ func NewEnemyTank(

width, height := image.Size()

donburi.SetValue(tank, component.Collider, component.ColliderData{
component.Collider.SetValue(tank, component.ColliderData{
Width: float64(width),
Height: float64(height),
Layer: component.CollisionLayerGroundEnemies,
})

if len(path.Points) > 0 {
donburi.SetValue(tank, component.AI, component.AIData{
component.AI.SetValue(tank, component.AIData{
Type: component.AITypeFollowPath,
Speed: speed,
Path: path.Points,
PathLoops: path.Loops,
})
} else {
donburi.SetValue(tank, component.AI, component.AIData{
component.AI.SetValue(tank, component.AIData{
Type: component.AITypeConstantVelocity,
Speed: speed,
})
}

donburi.SetValue(tank, component.Health, component.HealthData{
component.Health.SetValue(tank, component.HealthData{
Health: 5,
DamageIndicatorTimer: engine.NewTimer(time.Millisecond * 100),
DamageIndicator: newDamageIndicator(w, tank),
Expand All @@ -168,18 +168,18 @@ func NewEnemyTank(
gunT.LocalPosition = position
gunT.LocalRotation = originalRotation + rotation

donburi.SetValue(gun, component.Sprite, component.SpriteData{
component.Sprite.SetValue(gun, component.SpriteData{
Image: assets.TankGun,
Layer: component.SpriteLayerGroundGuns,
Pivot: component.SpritePivotCenter,
OriginalRotation: originalRotation,
})

donburi.SetValue(gun, component.Observer, component.ObserverData{
component.Observer.SetValue(gun, component.ObserverData{
LookFor: query.NewQuery(filter.Contains(component.PlayerAirplane)),
})

donburi.SetValue(gun, component.Shooter, component.ShooterData{
component.Shooter.SetValue(gun, component.ShooterData{
Type: component.ShooterTypeRocket,
ShootTimer: engine.NewTimer(time.Millisecond * 2500),
})
Expand All @@ -202,7 +202,7 @@ func newDamageIndicator(w donburi.World, parent *donburi.Entry) *component.Sprit
op.ColorM.Translate(1, 1, 1, 0)
image.DrawImage(parentSprite.Image, op)

donburi.SetValue(indicator, component.Sprite, component.SpriteData{
component.Sprite.SetValue(indicator, component.SpriteData{
Image: image,
Layer: component.SpriteLayerIndicators,
Pivot: parentSprite.Pivot,
Expand Down
16 changes: 8 additions & 8 deletions archetype/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func NewPlayer(w donburi.World, playerNumber int, faction component.PlayerFactio

func NewPlayerFromPlayerData(w donburi.World, playerData component.PlayerData) *donburi.Entry {
player := w.Entry(w.Create(component.Player))
donburi.SetValue(player, component.Player, playerData)
component.Player.SetValue(player, playerData)
return player
}

Expand Down Expand Up @@ -137,14 +137,14 @@ func NewPlayerAirplane(w donburi.World, player component.PlayerData, faction com
),
)

donburi.SetValue(shield, component.Sprite, component.SpriteData{
component.Sprite.SetValue(shield, component.SpriteData{
Image: assets.AirplaneShield,
Layer: component.SpriteLayerIndicators,
Pivot: component.SpritePivotCenter,
OriginalRotation: -90.0,
})

donburi.SetValue(airplane, component.PlayerAirplane, component.PlayerAirplaneData{
component.PlayerAirplane.SetValue(airplane, component.PlayerAirplaneData{
PlayerNumber: player.PlayerNumber,
Faction: faction,
InvulnerableTimer: engine.NewTimer(time.Second * 3),
Expand All @@ -164,22 +164,22 @@ func NewPlayerAirplane(w donburi.World, player component.PlayerData, faction com

image := AirplaneImageByFaction(faction, evolutionLevel)

donburi.SetValue(airplane, component.Sprite, component.SpriteData{
component.Sprite.SetValue(airplane, component.SpriteData{
Image: image,
Layer: component.SpriteLayerAirUnits,
Pivot: component.SpritePivotCenter,
OriginalRotation: originalRotation,
})

width, height := image.Size()
donburi.SetValue(airplane, component.Collider, component.ColliderData{
component.Collider.SetValue(airplane, component.ColliderData{
Width: float64(width),
Height: float64(height),
Layer: component.CollisionLayerPlayers,
})

inputs := settings.Inputs
donburi.SetValue(airplane, component.Input, component.InputData{
component.Input.SetValue(airplane, component.InputData{
MoveUpKey: inputs.Up,
MoveRightKey: inputs.Right,
MoveDownKey: inputs.Down,
Expand All @@ -188,7 +188,7 @@ func NewPlayerAirplane(w donburi.World, player component.PlayerData, faction com
ShootKey: inputs.Shoot,
})

donburi.SetValue(airplane, component.Evolution, component.EvolutionData{
component.Evolution.SetValue(airplane, component.EvolutionData{
Level: evolutionLevel,
GrowTimer: engine.NewTimer(time.Second * 1),
ShrinkTimer: engine.NewTimer(time.Second * 1),
Expand Down Expand Up @@ -218,7 +218,7 @@ func NewPlayerAirplane(w donburi.World, player component.PlayerData, faction com

transform.AppendChild(airplane, e, false)

donburi.SetValue(e, component.Sprite, component.SpriteData{
component.Sprite.SetValue(e, component.SpriteData{
Image: ebiten.NewImageFromImage(image),
Layer: component.SpriteLayerAirUnits,
Pivot: component.SpritePivotCenter,
Expand Down
2 changes: 1 addition & 1 deletion archetype/shadow.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewShadow(w donburi.World, parent *donburi.Entry) *donburi.Entry {
OriginalRotation: parentSprite.OriginalRotation,
}

donburi.SetValue(shadow, component.Sprite, spriteData)
component.Sprite.SetValue(shadow, spriteData)

return shadow
}
Expand Down
6 changes: 3 additions & 3 deletions archetype/wreck.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func NewAirplaneWreck(w donburi.World, parent *donburi.Entry, sprite *component.

transform.Transform.Get(wreck).LocalPosition = pos

donburi.SetValue(wreck, component.Sprite, component.SpriteData{
component.Sprite.SetValue(wreck, component.SpriteData{
Image: img,
Layer: component.SpriteLayerFallingWrecks,
Pivot: sprite.Pivot,
Expand All @@ -89,12 +89,12 @@ func NewAirplaneWreck(w donburi.World, parent *donburi.Entry, sprite *component.
velocity.X *= engine.RandomRange(0.5, 0.8)
velocity.Y *= engine.RandomRange(0.5, 0.8)

donburi.SetValue(wreck, component.Velocity, component.VelocityData{
component.Velocity.SetValue(wreck, component.VelocityData{
Velocity: velocity,
RotationVelocity: engine.RandomRange(-2, 2),
})

donburi.SetValue(wreck, component.Altitude, component.AltitudeData{
component.Altitude.SetValue(wreck, component.AltitudeData{
Altitude: 1.0,
Velocity: -0.01,
Falling: true,
Expand Down
2 changes: 1 addition & 1 deletion scene/airbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (a *Airbase) createWorld() {
a.world.Create(transform.Transform, component.Sprite),
)

donburi.SetValue(levelEntry, component.Sprite, component.SpriteData{
component.Sprite.SetValue(levelEntry, component.SpriteData{
Image: levelAsset.Background,
Layer: component.SpriteLayerBackground,
Pivot: component.SpritePivotTopLeft,
Expand Down
6 changes: 3 additions & 3 deletions scene/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (g *Game) createWorld(levelIndex int) donburi.World {
levelEntry := world.Entry(
world.Create(transform.Transform, component.Sprite),
)
donburi.SetValue(levelEntry, component.Sprite, component.SpriteData{
component.Sprite.SetValue(levelEntry, component.SpriteData{
Image: levelAsset.Background,
Layer: component.SpriteLayerBackground,
Pivot: component.SpritePivotTopLeft,
Expand Down Expand Up @@ -151,7 +151,7 @@ func (g *Game) createWorld(levelIndex int) donburi.World {

if g.world == nil {
game := world.Entry(world.Create(component.Game))
donburi.SetValue(game, component.Game, component.GameData{
component.Game.SetValue(game, component.GameData{
Score: 0,
Settings: component.Settings{
ScreenWidth: g.screenWidth,
Expand All @@ -168,7 +168,7 @@ func (g *Game) createWorld(levelIndex int) donburi.World {
// Keep the same game data across levels
gameData := component.MustFindGame(g.world)
newGameData := world.Entry(world.Create(component.Game))
donburi.Set(newGameData, component.Game, gameData)
component.Game.Set(newGameData, gameData)

// Transfer existing players from the previous level
query.NewQuery(filter.Contains(component.Player)).EachEntity(g.world, func(entry *donburi.Entry) {
Expand Down

0 comments on commit bcc14a7

Please sign in to comment.