<commit_before>/*******************************************************************************
 * This file is part of TERMINAL RECALL
 * Copyright (c) 2015 <NAME>
 * Part of the jTRFP.org project
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     chuck - initial API and implementation
 ******************************************************************************/
package org.jtrfp.trcl.miss;

import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.lang.ref.WeakReference;

import org.jtrfp.trcl.core.Feature;
import org.jtrfp.trcl.core.FeatureFactory;
import org.jtrfp.trcl.core.Features;
import org.jtrfp.trcl.core.TRFactory;
import org.jtrfp.trcl.core.TRFactory.TR;
import org.jtrfp.trcl.ctl.ControllerInput;
import org.jtrfp.trcl.ctl.ControllerInputsFactory.ControllerInputs;
import org.jtrfp.trcl.ctl.ControllerMapperFactory.ControllerMapper;
import org.jtrfp.trcl.game.TVF3Game;
import org.jtrfp.trcl.gui.MenuSystem;
import org.springframework.stereotype.Component;

@Component
public class GamePauseFactory implements FeatureFactory<Mission>  {
    public static final String PAUSE = "Pause";
    public static final String [] PAUSE_MENU_PATH = new String[] {"Game","Pause"}; 
    public interface PauseDisabledState{}
    
    public GamePauseFactory(){
    }//end constructor
    
    public class GamePause implements Feature<Mission>{
	private boolean paused = false;
	private final ControllerListener    controllerListener       = new ControllerListener();
	private final MenuSelectionListener menuSelectionListener    = new MenuSelectionListener();
	private final RunStateListener      runStateListener         = new RunStateListener();
	private WeakReference<Mission>      mission;
	private final PropertyChangeSupport pcs                      = new PropertyChangeSupport(this);
	private       ControllerInput       pause;

	@Override
	public void apply(Mission mission) {
	    final ControllerMapper mapper = Features.get(Features.getSingleton(), ControllerMapper.class);
	    final ControllerInputs inputs = Features.get(mapper, ControllerInputs.class);
	    pause           = inputs.getControllerInput(PAUSE);
	    this.mission = new WeakReference<Mission>(mission);
	    pause.addPropertyChangeListener(controllerListener);
	    getMenuSystem().addMenuItem(PAUSE_MENU_PATH);
	    getMenuSystem().addMenuItemListener(menuSelectionListener, PAUSE_MENU_PATH);
	    getTr().addPropertyChangeListener(TRFactory.RUN_STATE, runStateListener);
	}

	@Override
	public void destruct(Mission target) {
	    new Exception("destruct()").printStackTrace();
	    getTr().removePropertyChangeListener(TRFactory.RUN_STATE, runStateListener);
	    getMenuSystem().removeMenuItemListener(menuSelectionListener, PAUSE_MENU_PATH);
	    getMenuSystem().removeMenuItem(PAUSE_MENU_PATH);
	    pause.removePropertyChangeListener(controllerListener);
	}
	
	private class ControllerListener implements PropertyChangeListener{
	    @Override
	    public void propertyChange(PropertyChangeEvent evt) {
		if((Double)(evt.getNewValue())>.7)
		    proposePause(!paused);
	    }
	}//end ControllerListener
	<commit_msg>❎Debug dumps in GamePauseFactory.<commit_after>/*******************************************************************************
 * This file is part of TERMINAL RECALL
 * Copyright (c) 2015 <NAME>
 * Part of the jTRFP.org project
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     chuck - initial API and implementation
 ******************************************************************************/
package org.jtrfp.trcl.miss;

import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.lang.ref.WeakReference;

import org.jtrfp.trcl.core.Feature;
import org.jtrfp.trcl.core.FeatureFactory;
import org.jtrfp.trcl.core.Features;
import org.jtrfp.trcl.core.TRFactory;
import org.jtrfp.trcl.core.TRFactory.TR;
import org.jtrfp.trcl.ctl.ControllerInput;
import org.jtrfp.trcl.ctl.ControllerInputsFactory.ControllerInputs;
import org.jtrfp.trcl.ctl.ControllerMapperFactory.ControllerMapper;
import org.jtrfp.trcl.game.TVF3Game;
import org.jtrfp.trcl.gui.MenuSystem;
import org.springframework.stereotype.Component;

@Component
public class GamePauseFactory implements FeatureFactory<Mission>  {
    public static final String PAUSE = "Pause";
    public static final String [] PAUSE_MENU_PATH = new String[] {"Game","Pause"}; 
    public interface PauseDisabledState{}
    
    public GamePauseFactory(){
    }//end constructor
    
    public class GamePause implements Feature<Mission>{
	private boolean paused = false;
	private final ControllerListener    controllerListener       = new ControllerListener();
	private final MenuSelectionListener menuSelectionListener    = new MenuSelectionListener();
	private final RunStateListener      runStateListener         = new RunStateListener();
	private WeakReference<Mission>      mission;
	private final PropertyChangeSupport pcs                      = new PropertyChangeSupport(this);
	private       ControllerInput       pause;

	@Override
	public void apply(Mission mission) {
	    final ControllerMapper mapper = Features.get(Features.getSingleton(), ControllerMapper.class);
	    final ControllerInputs inputs = Features.get(mapper, ControllerInputs.class);
	    pause           = inputs.getControllerInput(PAUSE);
	    this.mission = new WeakReference<Mission>(mission);
	    pause.addPropertyChangeListener(controllerListener);
	    getMenuSystem().addMenuItem(PAUSE_MENU_PATH);
	    getMenuSystem().addMenuItemListener(menuSelectionListener, PAUSE_MENU_PATH);
	    getTr().addPropertyChangeListener(TRFactory.RUN_STATE, runStateListener);
	}

	@Override
	public void destruct(Mission target) {
	    getTr().removePropertyChangeListener(TRFactory.RUN_STATE, runStateListener);
	    getMenuSystem().removeMenuItemListener(menuSelectionListener, PAUSE_MENU_PATH);
	    getMenuSystem().removeMenuItem(PAUSE_MENU_PATH);
	    pause.removePropertyChangeListener(controllerListener);
	}
	
	private class ControllerListener implements PropertyChangeListener{
	    @Override
	    public void propertyChange(PropertyChangeEvent evt) {
		if((Double)(evt.getNewValue())>.7)
		    proposePause(!paused);
	    }
	}//end ControllerListener
	
{'fraction_non_alphanumeric': 0.128661688684664, 'fraction_numerical': 0.0022975301550832855, 'mean_word_length': 5.019878997407087, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5827912', 'n_tokens_mistral': 1913, 'n_tokens_neox': 1829, 'n_words': 421}