This commit is contained in:
2024-10-26 09:15:56 +01:00
parent dc34172691
commit f11dfe53db
5 changed files with 96 additions and 136 deletions
-45
View File
@@ -2,11 +2,8 @@ module Dodge.Render.ShapePicture (
worldSPic,
) where
import qualified Data.Map.Strict as M
import Control.Lens
import Control.Monad (guard)
import Data.Foldable
import Data.Maybe
import Data.Strict.Tuple
import Dodge.Base
import Dodge.Creature.Picture
@@ -20,7 +17,6 @@ import Geometry
import qualified IntMapHelp as IM
import NewInt
import Picture
import qualified SDL
import Shape
import ShapePicture
@@ -36,49 +32,12 @@ worldSPic cfig u =
<> foldup floorItemSPic (filtOn _flItPos (_unNIntMap . _floorItems))
<> foldup btSPic (filtOn _btPos _buttons)
<> foldup mcSPic (filtOn _mcPos _machines)
<> aimDelaySweep w
<> drawMouseSelection w
where
w = _uvWorld u
foldup = foldMap'
filtOn f g = IM.filter (pointIsClose . f) (g (_lWorld (_cWorld w)))
pointIsClose = cullPoint cfig w
drawMouseSelection :: World -> SPic
drawMouseSelection w = fromMaybe mempty $ do
guard (SDL.ButtonLeft `M.member` (w ^. input . mouseButtons)
&& not (SDL.ButtonRight `M.member` (w ^. input . mouseButtons))
)
p <- w ^? input . clickPos . ix SDL.ButtonLeft
return $ noShape $ color (withAlpha 0.5 white)
$ setLayer FixedCoordLayer $ polygon $ reverse $ rectVV p (w ^. input . mousePos)
aimDelaySweep :: World -> SPic
aimDelaySweep w = fromMaybe mempty $ do
cr <- w ^? cWorld . lWorld . creatures . ix 0
aimstatus <- cr ^? crStance . posture
guard (aimstatus == Aiming)
return $ noShape $ drawSweep cr w
drawSweep :: Creature -> World -> Picture
drawSweep cr w = fromMaybe mempty $ do
a <- safeArgV (mwp -.- p)
let a'
| a - cdir > pi = cdir + 2 * pi
| a - cdir < - pi = cdir - 2 * pi
| otherwise = cdir
return $
setLayer FixedCoordLayer $
uncurryV translate (worldPosToScreen campos p) $
arcFull (a - rot) 10 white (a' - rot) 1 white (5 + dist mwp p * campos ^. camZoom) white
where
cdir = _crDir cr
rot = campos ^. camRot
p = _crPos cr
campos = w ^. wCam
theinput = w ^. input
mwp = mouseWorldPos theinput campos
drawCreature :: Creature -> SPic
drawCreature cr = case _crType cr of
Humanoid{} -> basicCrPict cr
@@ -138,7 +97,6 @@ extraPics cfig u =
<> foldMap drawBlip (_radarBlips lw)
<> _flares lw
<> foldMap (dbArg (drawLightSource . _lsPict)) (_lightSources lw)
<> testPic cfig w
<> foldMap ppDraw (_pressPlates lw)
<> viewClipBounds cfig w
<> debugDraw cfig w
@@ -156,9 +114,6 @@ extraPics cfig u =
w = u ^. uvWorld
lw = w ^. cWorld . lWorld
testPic :: Configuration -> World -> Picture
testPic _ _ = mempty
ppDraw :: PressPlate -> Picture
ppDraw c = uncurryV translate (_ppPos c) $ rotate (_ppRot c) (_ppPict c)