// GET /projects/{project-id}/objects/{class}/{subclass}/{type}/icon/raw
func (resource *WorkspaceResource) getObjectIconAsRaw(request *restful.Request, response *restful.Response) {
	projectID := request.PathParameter("project-id")
	project, err := resource.ws.Project(projectID)

	if err == nil {
		classID, _ := strconv.ParseInt(request.PathParameter("class"), 10, 8)
		subclassID, _ := strconv.ParseInt(request.PathParameter("subclass"), 10, 8)
		typeID, _ := strconv.ParseInt(request.PathParameter("type"), 10, 8)
		objID := res.MakeObjectID(res.ObjectClass(classID), res.ObjectSubclass(subclassID), res.ObjectType(typeID))
		bmp := project.GameObjects().Icon(objID)
		var entity model.RawBitmap

		entity.Width = int(bmp.ImageWidth())
		entity.Height = int(bmp.ImageHeight())
		var pixel []byte

		for row := 0; row < entity.Height; row++ {
			pixel = append(pixel, bmp.Row(row)...)
		}
		entity.Pixels = base64.StdEncoding.EncodeToString(pixel)

		response.WriteEntity(entity)
	} else {
		response.AddHeader("Content-Type", "text/plain")
		response.WriteErrorString(http.StatusBadRequest, err.Error())
		return
	}
}
func (suite *ReleaseStoreLibrarySuite) TestObjpropStoreReturnsEmptyStoreIfNowhereExisting(c *check.C) {
	objID := res.MakeObjectID(1, 2, 2)
	expected := suite.nullObjpropProvider.Provide(objID)
	store, err := suite.library.ObjpropStore("empty.dat")

	c.Assert(err, check.IsNil)
	c.Assert(store, check.NotNil)

	retrieved := store.Get(objID)
	c.Check(retrieved, check.DeepEquals, expected)
}
func (suite *ReleaseStoreLibrarySuite) TestObjpropStoreIsBackedBySourceIfExisting(c *check.C) {
	objID := res.MakeObjectID(1, 2, 2)
	expected := suite.someObjectProperties(objID)
	suite.createObjpropResource(suite.source, "fromSource.dat", func(consumer objprop.Consumer) {
		consumer.Consume(objID, expected)
	})
	store, err := suite.library.ObjpropStore("fromSource.dat")

	c.Assert(err, check.IsNil)
	c.Assert(store, check.NotNil)
	retrieved := store.Get(objID)
	c.Check(retrieved, check.DeepEquals, expected)
}
func (suite *ReleaseStoreLibrarySuite) TestObjpropStoreReturnsSameInstances(c *check.C) {
	suite.createObjpropResource(suite.source, "source.dat", func(consumer objprop.Consumer) {
		objID := res.MakeObjectID(1, 2, 2)
		consumer.Consume(objID, suite.someObjectProperties(objID))
	})
	store1, err1 := suite.library.ObjpropStore("source.dat")
	c.Assert(err1, check.IsNil)
	c.Assert(store1, check.NotNil)

	store2, err2 := suite.library.ObjpropStore("source.dat")
	c.Assert(err2, check.IsNil)

	c.Check(store1, check.Equals, store2)
}
func (suite *DynamicObjPropStoreSuite) TestSwapReplacesWrapped(c *check.C) {
	objId0 := res.MakeObjectID(res.ObjectClass(0), res.ObjectSubclass(0), res.ObjectType(0))
	objId1 := res.MakeObjectID(res.ObjectClass(0), res.ObjectSubclass(0), res.ObjectType(1))
	secondData := suite.testData(6)
	provider0 := suite.createProvider(func(consumer objprop.Consumer) {
		consumer.Consume(objId0, suite.testData(3))
		consumer.Consume(objId1, suite.testData(3))
	})
	provider1 := suite.createProvider(func(consumer objprop.Consumer) {
		consumer.Consume(objId0, suite.testData(5))
		consumer.Consume(objId1, secondData)
	})

	testStore := NewDynamicObjPropStore(store.NewProviderBacked(provider0, func() {}))
	testStore.Swap(func(oldStore objprop.Store) objprop.Store {
		return store.NewProviderBacked(provider1, func() {})
	})

	retrievedData := testStore.Get(objId1)

	c.Check(retrievedData.Common, check.DeepEquals, secondData.Common)
	c.Check(retrievedData.Generic, check.DeepEquals, secondData.Generic)
	c.Check(retrievedData.Specific, check.DeepEquals, secondData.Specific)
}
func (suite *DynamicObjPropStoreSuite) TestGetReturnsBlockFromWrapped(c *check.C) {
	objId := res.MakeObjectID(res.ObjectClass(0), res.ObjectSubclass(0), res.ObjectType(0))
	initData := suite.testData(4)
	provider := suite.createProvider(func(consumer objprop.Consumer) {
		consumer.Consume(objId, initData)
	})

	wrappedStore := store.NewProviderBacked(provider, func() {})
	testStore := NewDynamicObjPropStore(wrappedStore)

	retrievedData := testStore.Get(objId)

	c.Check(retrievedData.Common, check.DeepEquals, initData.Common)
	c.Check(retrievedData.Generic, check.DeepEquals, initData.Generic)
	c.Check(retrievedData.Specific, check.DeepEquals, initData.Specific)
}
func (suite *ReleaseStoreLibrarySuite) TestModifyingObjpropSourceSavesNewSink(c *check.C) {
	objID := res.MakeObjectID(1, 2, 2)
	nullData := suite.nullObjpropProvider.Provide(objID)
	suite.createObjpropResource(suite.source, "source.dat", func(consumer objprop.Consumer) {
		consumer.Consume(objID, suite.someObjectProperties(objID))
	})
	store, err := suite.library.ObjpropStore("source.dat")

	c.Assert(err, check.IsNil)
	c.Assert(store, check.NotNil)

	store.Put(objID, nullData)

	time.Sleep(100 * time.Millisecond)

	c.Check(suite.sink.HasResource("source.dat"), check.Equals, true)
}
func (library *ReleaseStoreLibrary) serializeObjpropStore(store objprop.Store) []byte {
	buffer := serial.NewByteStore()
	consumer := dosObjprop.NewConsumer(buffer, library.descriptors)

	for classIndex, classDesc := range library.descriptors {
		for subclassIndex, subclassDesc := range classDesc.Subclasses {
			for typeIndex := uint32(0); typeIndex < subclassDesc.TypeCount; typeIndex++ {
				objID := res.MakeObjectID(res.ObjectClass(classIndex), res.ObjectSubclass(subclassIndex), res.ObjectType(typeIndex))
				data := store.Get(objID)
				consumer.Consume(objID, data)
			}
		}
	}
	consumer.Finish()

	return buffer.Data()
}
// GET /projects/{project-id}/objects/{class}/{subclass}/{type}
func (resource *WorkspaceResource) getGameObject(request *restful.Request, response *restful.Response) {
	projectID := request.PathParameter("project-id")
	project, err := resource.ws.Project(projectID)

	if err == nil {
		classID, _ := strconv.ParseInt(request.PathParameter("class"), 10, 8)
		subclassID, _ := strconv.ParseInt(request.PathParameter("subclass"), 10, 8)
		typeID, _ := strconv.ParseInt(request.PathParameter("type"), 10, 8)
		objID := res.MakeObjectID(res.ObjectClass(classID), res.ObjectSubclass(subclassID), res.ObjectType(typeID))
		entity := resource.objectEntity(project, objID)

		response.WriteEntity(entity)
	} else {
		response.AddHeader("Content-Type", "text/plain")
		response.WriteErrorString(http.StatusBadRequest, err.Error())
		return
	}
}
func (suite *DynamicObjPropStoreSuite) TestPutInsertsToWrapped(c *check.C) {
	objId := res.MakeObjectID(res.ObjectClass(0), res.ObjectSubclass(0), res.ObjectType(0))
	provider := suite.createProvider(func(consumer objprop.Consumer) {
		consumer.Consume(objId, suite.testData(0))
	})

	wrappedStore := store.NewProviderBacked(provider, func() {})
	testStore := NewDynamicObjPropStore(wrappedStore)
	newData := suite.testData(1)

	testStore.Put(objId, newData)

	wrappedData := wrappedStore.Get(objId)

	c.Check(wrappedData.Common, check.DeepEquals, newData.Common)
	c.Check(wrappedData.Generic, check.DeepEquals, newData.Generic)
	c.Check(wrappedData.Specific, check.DeepEquals, newData.Specific)
}
Example #11
0
// NewGameObjects returns a new instance of GameObjects.
func NewGameObjects(library io.StoreLibrary) (gameObjects *GameObjects, err error) {
	var cybstrng [model.LanguageCount]chunk.Store
	var objart chunk.Store
	var objProperties objprop.Store

	if err == nil {
		objart, err = library.ChunkStore("objart.res")
	}
	if err == nil {
		objProperties, err = library.ObjpropStore("objprop.dat")
	}
	for i := 0; i < model.LanguageCount && err == nil; i++ {
		cybstrng[i], err = library.ChunkStore(localized[i].cybstrng)
	}
	if err == nil {
		gameObjects = &GameObjects{
			cybstrng:       cybstrng,
			cp:             text.DefaultCodepage(),
			desc:           objprop.StandardProperties(),
			objProperties:  objProperties,
			objart:         objart,
			objIconOffsets: make(map[res.ObjectID]int),
			mapIconOffsets: make(map[res.ObjectID]int)}

		offset := 1
		for classIndex, classDesc := range gameObjects.desc {
			for subclassIndex, subclassDesc := range classDesc.Subclasses {
				for typeIndex := uint32(0); typeIndex < subclassDesc.TypeCount; typeIndex++ {
					objID := res.MakeObjectID(res.ObjectClass(classIndex), res.ObjectSubclass(subclassIndex), res.ObjectType(typeIndex))
					commonProperties := gameObjects.commonProperties(objID)
					extraImages := int(commonProperties.Extra >> 4)

					gameObjects.objIconOffsets[objID] = offset
					offset = offset + 3 + extraImages
					gameObjects.mapIconOffsets[objID] = offset - 1
				}
			}
		}
	}

	return
}
Example #12
0
// AddObject adds a new object at given tile.
func (level *Level) AddObject(template *model.LevelObjectTemplate) (createdIndex int, err error) {
	level.mutex.Lock()
	defer level.mutex.Unlock()

	objID := res.MakeObjectID(res.ObjectClass(template.Class),
		res.ObjectSubclass(template.Subclass), res.ObjectType(template.Type))

	classMeta := data.LevelObjectClassMetaEntry(objID.Class)
	classStore := level.store.Get(res.ResourceID(4000 + level.id*100 + 10 + int(objID.Class)))
	classTable := logic.DecodeLevelObjectClassTable(classStore.BlockData(0), classMeta.EntrySize)
	classChain := classTable.AsChain()
	classIndex, classErr := classChain.AcquireLink()

	if classErr != nil {
		err = classErr
		return
	}
	classEntry := classTable.Entry(classIndex)
	classEntryData := classEntry.Data()
	for index := 0; index < len(classEntryData); index++ {
		classEntryData[index] = 0x00
	}

	objectIndex, objectErr := level.objectChain.AcquireLink()
	if objectErr != nil {
		classChain.ReleaseLink(classIndex)
		err = objectErr
		return
	}
	createdIndex = int(objectIndex)

	locations := []logic.TileLocation{logic.AtTile(uint16(template.TileX), uint16(template.TileY))}

	crossrefIndex, crossrefErr := level.crossrefList.AddObjectToMap(uint16(objectIndex), level.tileMap, locations)
	if crossrefErr != nil {
		classChain.ReleaseLink(classIndex)
		level.objectChain.ReleaseLink(objectIndex)
		err = crossrefErr
		return
	}
	crossrefEntry := level.crossrefList.Entry(crossrefIndex)

	objectEntry := &level.objectList[objectIndex]
	objectEntry.InUse = 1
	objectEntry.Class = objID.Class
	objectEntry.Subclass = objID.Subclass
	objectEntry.Type = objID.Type
	objectEntry.X = data.MapCoordinateOf(byte(template.TileX), byte(template.FineX))
	objectEntry.Y = data.MapCoordinateOf(byte(template.TileY), byte(template.FineY))
	objectEntry.Z = byte(template.Z)
	objectEntry.Rot1 = 0
	objectEntry.Rot2 = 0
	objectEntry.Rot3 = 0
	objectEntry.Hitpoints = 1

	objectEntry.CrossReferenceTableIndex = uint16(crossrefIndex)
	crossrefEntry.LevelObjectTableIndex = uint16(objectIndex)

	objectEntry.ClassTableIndex = uint16(classIndex)
	classEntry.LevelObjectTableIndex = uint16(objectIndex)

	classStore.SetBlockData(0, classTable.Encode())

	objWriter := bytes.NewBuffer(nil)
	binary.Write(objWriter, binary.LittleEndian, level.objectList)
	level.objectListStore.SetBlockData(0, objWriter.Bytes())

	level.crossrefListStore.SetBlockData(0, level.crossrefList.Encode())
	level.onTileDataChanged()

	return
}