package org.drools.games.wumpus.server.view

import org.drools.games.wumpus.Cell
import org.drools.games.wumpus.Direction
import org.drools.games.wumpus.Hero
import org.drools.games.wumpus.Gold
import org.drools.games.wumpus.Pit
import org.drools.games.wumpus.Wumpus
import org.drools.games.wumpus.Thing
import org.drools.games.wumpus.FeelBreeze
import org.drools.games.wumpus.SeeGlitter
import org.drools.games.wumpus.FeelBump
import org.drools.games.wumpus.SmellStench
import org.drools.games.wumpus.HearScream
import org.drools.games.wumpus.view.GameView
import org.drools.games.wumpus.view.GameUI

import javax.imageio.ImageIO
import java.awt.image.BufferedImage

import java.awt.Color;
import java.awt.Graphics

import javax.swing.JPanel;

function void paintSensorCell(String image, int x, int y,  GameUI gui, Graphics sensorG) {     
     sensorG.setColor( Color.WHITE ); // background
     sensorG.fillRect( x, y,  100, 100);
     sensorG.drawImage( ImageIO.read( GameView.class.getResource( image ) ), x, y,100,100, gui.getSensorPanel() );
}

function void clearSensorCell(int x, int y,  Graphics sensorG) {     
     sensorG.setColor( Color.WHITE ); // background
     sensorG.fillRect( x, y,  100, 100);
}

dialect "mvel"


rule "Base Sensor" when
    $gui : GameUI( )
then
end    

rule "Feel Breeze" extends "Base Sensor" agenda-group "PaintSensor" when
    FeelBreeze()
then
    paintSensorCell("breeze.png", 0, 0, $gui, $gui.sensorPanel.sensorG );
end

rule "Breeze Gone" extends "Base Sensor" agenda-group "PaintSensor" when
    not FeelBreeze()
then
    clearSensorCell( 0, 0, $gui.sensorPanel.sensorG );
end

rule "Smell Stench" extends "Base Sensor" agenda-group "PaintSensor"when
    SmellStench()
then
    paintSensorCell("stench.png", 103, 0, $gui, $gui.sensorPanel.sensorG );
end

rule "Stench Gone" extends "Base Sensor" agenda-group "PaintSensor"when
    not SmellStench()
then
    clearSensorCell( 103, 0, $gui.sensorPanel.sensorG );
end

rule "See Glitter" extends "Base Sensor" agenda-group "PaintSensor"when
    SeeGlitter()
then
    paintSensorCell("glitter.png", 206, 0, $gui, $gui.sensorPanel.sensorG );
end

rule "Glitter Gone" extends "Base Sensor"  agenda-group "PaintSensor" when
    not SeeGlitter()
then
    clearSensorCell( 206, 0, $gui.sensorPanel.sensorG );
end

rule "Feel Bump" extends "Base Sensor" agenda-group "PaintSensor"when
    FeelBump()
then
    paintSensorCell("bump.png", 309, 0, $gui, $gui.sensorPanel.sensorG );
end

rule "Bump Gone"  extends "Base Sensor" agenda-group "PaintSensor" when
    not FeelBump()
then
    clearSensorCell( 309, 0, $gui.sensorPanel.sensorG );
end

rule "Hear Scream"  extends "Base Sensor" agenda-group "PaintSensor" when
    HearScream()
then
    paintSensorCell("scream.png", 412, 0, $gui, $gui.sensorPanel.sensorG );
end

rule "Scream Gone"  extends "Base Sensor" agenda-group "PaintSensor" when
    not HearScream()
then
    clearSensorCell( 412, 0, $gui.sensorPanel.sensorG );
end

/*
rule "Redraw Sensors" no-loop salience -100 when
   $gui : GameUI() 
   $sd : SensorDirty( dirty == true )
then
   $gui.updateSensors();
   modify( $sd ) { dirty = false };
end
*/