001/* 002 * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. 003 * Copyright (C) 2000-2010 The Gridarta Developers. 004 * 005 * This program is free software; you can redistribute it and/or modify 006 * it under the terms of the GNU General Public License as published by 007 * the Free Software Foundation; either version 2 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License along 016 * with this program; if not, write to the Free Software Foundation, Inc., 017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 018 */ 019 020package net.sf.gridarta.model.mapcontrol; 021 022import java.io.File; 023import java.util.List; 024import net.sf.gridarta.model.archetype.TestArchetype; 025import net.sf.gridarta.model.gameobject.TestGameObject; 026import net.sf.gridarta.model.io.MapWriter; 027import net.sf.gridarta.model.maparchobject.TestMapArchObject; 028import net.sf.gridarta.model.mapmodel.MapModel; 029import net.sf.gridarta.model.mapmodel.MapModelFactory; 030import net.sf.gridarta.model.settings.ProjectSettings; 031import org.jetbrains.annotations.NotNull; 032import org.jetbrains.annotations.Nullable; 033 034/** 035 * An {@link MapControlFactory} implementation for testing purposes. 036 * @author Andreas Kirschbaum 037 */ 038public class TestMapControlFactory implements MapControlFactory<TestGameObject, TestMapArchObject, TestArchetype> { 039 040 /** 041 * The {@link MapWriter} for saving {@link MapControl} instances. 042 */ 043 @NotNull 044 private final MapWriter<TestGameObject, TestMapArchObject, TestArchetype> mapWriter; 045 046 /** 047 * The {@link ProjectSettings} to use. 048 */ 049 @NotNull 050 private final ProjectSettings projectSettings; 051 052 /** 053 * The {@link MapModelFactory} for creating {@link MapModel} instances. 054 */ 055 @NotNull 056 private final MapModelFactory<TestGameObject, TestMapArchObject, TestArchetype> mapModelFactory; 057 058 /** 059 * Creates a new instance. 060 * @param mapWriter the map writer for saving map control instances 061 * @param projectSettings the project settings to use 062 * @param mapModelFactory the map model factory for creating map model 063 * instances 064 */ 065 public TestMapControlFactory(@NotNull final MapWriter<TestGameObject, TestMapArchObject, TestArchetype> mapWriter, @NotNull final ProjectSettings projectSettings, @NotNull final MapModelFactory<TestGameObject, TestMapArchObject, TestArchetype> mapModelFactory) { 066 this.mapWriter = mapWriter; 067 this.projectSettings = projectSettings; 068 this.mapModelFactory = mapModelFactory; 069 } 070 071 /** 072 * {@inheritDoc} 073 */ 074 @NotNull 075 @Override 076 public MapControl<TestGameObject, TestMapArchObject, TestArchetype> newMapControl(@Nullable final List<TestGameObject> objects, @NotNull final TestMapArchObject mapArchObject, @Nullable final File file) { 077 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelFactory.newMapModel(mapArchObject); 078 if (objects != null) { 079 mapModel.beginTransaction("init"); 080 try { 081 mapModel.addObjectListToMap(objects); 082 } finally { 083 mapModel.endTransaction(); 084 } 085 mapModel.resetModified(); 086 } 087 final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = new DefaultMapControl<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, false, mapWriter, projectSettings); 088 mapControl.getMapModel().setMapFile(file); 089 return mapControl; 090 } 091 092 /** 093 * {@inheritDoc} 094 */ 095 @NotNull 096 @Override 097 public MapControl<TestGameObject, TestMapArchObject, TestArchetype> newPickmapControl(@Nullable final List<TestGameObject> objects, @NotNull final TestMapArchObject mapArchObject, @Nullable final File file) { 098 throw new AssertionError(); 099 } 100 101}